Table Of Contents

Previous topic

forces Package

Next topic

main Package

This Page

geometry Package

geometry Package

dist Module

pyparticles.geometry.dist.distance(x, y)

return the euclideian distance between x and y

intersection Module

pyparticles.geometry.intersection.box_intersects_sphere(b_min, b_max, c, r)

return True if the box defined by the opposite vertices n_max, b max intersect the sphere centred in c with a radius r

pyparticles.geometry.intersection.sphere_intersect_sphere(c1, r1, c2, r2)

returns the average intersection point if the two spheres centred in c1 and c2 and radius r1, r2 are intersecting, else it returns None

transformations Module

class pyparticles.geometry.transformations.Transformations

Bases: object

Class used for administrate 3D transformations matrix using an OpenGl like method with a push_matrix & pop_matrix model. This method is very confortable if we want to create articulated geometric structures with a lot of subobjects and relative coordinates.

Example:

t = tr.Transformations() # init transfomation

t.set_points_tuple_size(2) # Pairwise points in the queue

t.rotY( np.radians(90) )  # Apply some transoformations matricies
t.rotX( np.radians(90) )  
t.rotZ( np.radians(90) )
# Now the current matrix is: Ry(90) * Rx(90) * Rz(90)

t.append_point( list( [1,0,0] ) )      # Append some poits. It accept every Indexable type 
t.append_point( np.array( [1,1,0] ) )  # The preview transoformations are applied on these points
t.append_point( np.array( [1,1,1] ) )
t.append_point( np.array( [0,1,1] ) )    

t.push_matrix() # push the current matrix

t.translation( 10 , 2 , 2 ) # Apply a translation
# Now the current matrix is: Ry(90) * Rx(90) * Rz(90) * Tr( [ 10 , 2 , 2 ]  )

t.append_point( [1,1,1] )
t.append_point( np.matrix( [0,1,1] ).T ) # Only vertical matrix

t.pop_matrix() # Back to the old matrix
# Now the current matrix is newly: Ry(90) * Rx(90) * Rz(90)

t.append_point( np.array( [1,0,0] ) )
t.append_point( [1,1,0] )
t.append_point( np.array( [1,1,1] ) )
t.append_point( [0,1,1] )

# Print the resulting points (in a paiwise tuple)
# Attention: the points are removed from the queue during the iteration.
for p in t :
    # p is a tuple ( p1 , p2 ) see the function: t.set_points_tuple_size(2)
    print( p[0] )
    print( p[1] )
append_point(pt)

Transforms and append a new point in the points queue

Argument:
pt : point coord: [ x , y , z ]
clear()

Clear the stack, the points in the queue and set to the identity the current matrix

get_matrix()

Returns a copy of the current matrix

identity()

Set the current matrix to the identity

matrix

Returns a copy of the current matrix

next()

iterate over the points in the queue, it pop and returns the transformed points. The popped points in the queue are cancelled during the itarations.

pop_matrix()

Pop and copy in the current matrix the last matrix in the stack

pop_points()

Returns the firsts #nr of points in the point queue, the returned points are organized in a tuple

push_matrix()

Push in the stack a copy of the current matrix

reflection(a, b, c)

Apply the reflection through the plane: ax + by + cz = 0

rotX(angle)

Apply the rotation around the x axis

rotY(angle)

Apply the rotation around the y axis

rotZ(angle)

Apply the rotation around the z axis

rotate(angle, x, y, z)

Apply the rotation matrix around the axis [ x , y , z ] of the angle: angle

scale(x, y, z)

Apply the scale with values x y z

set_matrix(m)

set the current matrix to m

set_points_tuple_size(nr)

The points are organized by tuples of size nr. That’s useful if you want to draw triangles squares or lines, where the size of the tupre are respectively 3, 4 and 2.

shearX(a, b)

Apply the shearing along X axis using the values a b

SH_X(a,b) = [ 1 0 0 0 
              a 1 0 0 
              b 0 1 0 
              0 0 0 1 ]
shearY(a, b)

Apply the shearing along Y axis using the values a b

SH_Y(a,b) = [ 1 a 0 0 
              0 1 0 0 
              0 b 1 0 
              0 0 0 1 ]
shearZ(a, b)

Apply the shearing along Z axis using the values a b

SH_Z(a,b) = [ 1 0 a 0 
              0 1 b 0 
              0 0 1 0 
              0 0 0 1 ]        
transform(x, y, z)

Transform the point ( x , y , z ) according to the current matrix and returns a 3 by 1 matrix containig the resulting point

transformv(pt)

Transform the point pt: [ x , y , z ] according to the current matrix and returns a 3 by 1 matrix containig the resulting point

translation(x, y, z)

apply the translation with the vector [x y z]