Creating point, line and polygon

Point

For a single point, Point = (x,y) or np.array((x,y)) at best.
For multiple points, Points =[(a,b,c),(d,e,f),(g,h,i)] or np.array([(a,b,c),(d,e,f),(g,h,i)]) at best.
For instance, P1 refers to (1,2), P2 to (2, 2), both Points1 and Points2 are defined by a set of vertices of (0.0,0.0),(0.5,0.0),(1.0,0.0),(1.5,0.0) and (2.0,0.0). The Python coding follows,

>>> P1 = (1,1)           #  Creating point (1,1)
>>> P2 = np.array ((2,2))
>>> Points1 = [(0.0,0.0),(0.5,0.0),(1.0,0.0),(1.5,0.0),(2.0,0.0)]
>>> Points2 = np.array([(0.0,0.0),(0.5,0.0),(1.0,0.0),(1.5,0.0),(2.0,0.0)])

Besides, they can be represented by a matrix for convenience.

>>> Points1 = [[(0.0,0.0),(0.5,0.0)],[(1.0,0.0),(1.5,0.0)],[(2.0,0.0),(2.5,0.0)]]
>>> Points2 = np.array([[(0.0,0.0),(0.5,0.0)],[(1.0,0.0),(1.5,0.0)],[(2.0,0.0),(2.5,0.0)]])

Line and plane

A line is represented by both a point and a slope.

>>> P,L = (0,0), (1,2)

It means a line across (0,0) with slope of (1,2).

A plane is represented by a point and its normal vector.

>>> P,n = (0,0,0),(1,2,3)

It means a plane across (0,0,0) with a normal vector of (1,2,3).

Segment

set by its starting end ending points.

>>> P1,P2 = (0,0), (1,1)

It defines a segment from (0,0) to (1,1).

Polygon

Here, the polygon is close, meaning that its starting point is its ending point. Its vertices run counter-clockwise as viewed to its facet. With the aid of the package, one can define a polygon first in the yz plane, and then move and/or rotate it to the designated position in the following way.

1. Creating a 3D polygon directly.

>>> vertices = [(0,0,0),(1,0,0),(1,1,1),(0,1,1)]
>>> polygon = np.array(vertices)
_images/polygon1.png

2. Creating a 2D polygon first in yz plane and then transform it to its real 3D position as desired.

>>> vertices2D = Vertices([(0,0),(0,2**0.5),(1,2**0.5),(1,0)])    # verices are defined by (y,z). 
_images/polygon2-1.png

Rotation of a polygon is done with α and β, and in the process, its origin is fixed at (0,0,0).

The transformation is illustrated as follows,

_images/shapes_rotation.png
α is made from y axis to its first edge moving counter-clockwise in the xy plane around z axis, as viewed against the direction of z;
β is made from z axis to its projection on the facet of polygon after it turns clockwise around its first edge, as viewed against the direction of the edge.

Translation of a polygon is done with new position of its origin.

Moving a polygon to its real position is achieved with the above rotation and translation, and it is done with the function of move().

>>> x0,y0,z0 = 0.3,0.4,0.5    
>>> alpha, beta = -90,45
>>> vertices = move(shape = vertices2D, to = (x0,y0,z0), by = (alpha,beta))   
_images/polygon1.png