8000 GitHub - odevauchelle/pycavalier: Draw oblique projection of 3D objects
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

odevauchelle/pycavalier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pycavalier

Pycavalier is a Python library to draw 3D objects using an oblique projection with Matplotlib.

The orientation of the projection is with respect to the observer, and the vertical direction is kept track of.

Quick example

from pycavalier import projection_tools as pt
from pylab import *

# create a view point

viewpoint = pt.viewpoint( latitude = 0.9*pi/2., longitude = pi/10. )

# show refrence frame

viewpoint.show_reference_frame()

# create disk

radius = 2
theta = linspace(0,2*pi,100)
center = array( [ 3, 2.5, 0 ] )
circle = center + array( [ radius*cos(theta), radius*sin(theta), 0.*theta ] ).T

# show disk

viewpoint.plot_points( circle, '--', lw = 3 )

axis('equal')
show()

Blue circle

Patches

from pycavalier import projection_tools as pt
from pylab import *

# create a view point

viewpoint = pt.viewpoint( latitude = 0.9*pi/2., longitude = pi/10. )

# create box

sides = [ [ [0,0,1], [0,1,1], [1,1,1], [1,0,1] ] ]
sides += [ [ [1,0,0], [1,0,1], [1,1,1], [1,1,0] ] ]
sides += [ [ [0,1,0], [0,1,1], [1,1,1], [1,1,0] ] ]

# show box

for side in sides :
    viewpoint.plot_patch( side, color = 'tab:brown', edgecolor = 'black' )

axis('equal')

show()

Brown box

Tilt the reference frame

from pycavalier import projection_tools as pt
from pylab import *

# define the vertical direction

tilt_angles = [ 0, -pi/8, -pi/4 ]

for tilt_angle in tilt_angles :

    # create viewpoint with tilt

    viewpoint = pt.viewpoint( latitude = 0.9*pi/2., longitude = pi/10., plummet = [ 0,-sin(tilt_angle), -cos(tilt_angle) ] )

    # translate reference frame

    viewpoint.reference_frame['center'] = viewpoint.reference_frame['center'] + array( [-6, 0, 0] )

    # show refrence frame and plummet

    viewpoint.show_reference_frame()
    viewpoint.show_plummet()


axis('equal')
show()

Tilted frame

Add decoration on patches

from pycavalier import projection_tools as pt
from pylab import *

# create a view point

viewpoint = pt.viewpoint( latitude = 0.7*pi/2., longitude =-.4*pi/2. )
viewpoint.show_reference_frame()

# create sandy wavy bed

x = linspace( 0, 6*pi, 100 )
z = -.5*cos(x)
points = array( [ x, 0*x, z ] ).T
width = array([0, 3, 0])
patches = [ [ points[i], points[i+1], points[i+1] + width,  points[i] + width] for i in range( len(points) - 1 ) ]

# show bed patches

for patch in patches :
    viewpoint.plot_patch( patch, color = 'tab:brown', alpha = .3, edgecolor = 'none' )
    dots = pt.dotify( patch, 30 )
    viewpoint.plot_points( dots, '.', ms = 2, color = 'tab:brown', alpha = .3 )

axis('equal')
show()

Sandy bed

About

Draw oblique projection of 3D objects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0