Visual shapes

In the following, we demonstrate how to use VisualShapes to create geometries, such as point, line and polygon.

Point

import Shape4D.VisualShapes as vs
P = vs.Point(1,2,3)
print(P)
>>> 1,2,3
P.coordinates
>>> array([1, 2, 3])
import Shape4D.VisualShapes as vs
P = vs.Point(4,5,6)
ax = P.plot(style={'color':'r','marker':'o','alpha':0.5})
P = vs.Point(0.5,0.7,0.5)
P.plot(ax=ax)
P.show()
_images/Points.png

Line

import Shape4D.VisualShapes as vs
P1 = vs.Point(0.2,0.1,0.1)
P2 = vs.Point(0.8,0.5,0.8)
L  = vs.Line(P1,P2)
L.plot()
L.show()
_images/line1.png
L  = vs.Line((1,2,3),(4,5,6))
L.plot(style={'color':'r','node':'visible'})
L.show(azim=30,elev=3)
_images/line2.png

Polyline

pl = vs.Polyline((0.5,0.3,0.6),(0.1,0.9,0.3),(0.7,0.3,0.9))
pl.broken_by((0.1,0.9,0.6))
pl.insert_at(1,(0.3,0.6,0.9))
pl.plot()
pl.show()
_images/polyline1.png
pl.plot(style = {'colors':['darkorange','orange','gold','wheat'],'node':'visible'})
pl.show(azim=110, elev=19)
_images/polyline2.png

Polygon

x = [0.5,0.3,0.6,0.9,0.1]
y = [0.1,0.9,0.3,0.4,0.8]
z = [0.7,0.3,0.1,0.9,0.6]
points = list(zip(x,y,z))
poly = vs.Polygon(points)
poly.plot()
poly.show()
_images/testPolyon1.PNG
poly.plot(style = {'facecolor':'orange','edgecolor':'darkgreen'})
poly.show(azim=110,elev=20)
_images/testPolyon2.PNG

Shape

import Shape4D.VisualShapes as vs
W,H,A,B,C,D = 2.0,1.5, 1.0, 0.6, 0.2, 0.3
shape1 = vs.Shape('rectangle',W,H,A,B,C,D)
shape2 = vs.Shape('triangle' ,W,H,A,B,C,D)
shape3 = vs.Shape('fourSided',W,H,A,B,C,D)
shape4 = vs.Shape('fiveSided',W,H,A,B,C,D)
shape5 = vs.Shape('rectangleWithHole',W,H,A,B,C,D)

shape1.plot(hideAxes=True)

shape2 = shape2.move(to = (0,2,0))
shape3 = shape3.move(to = (0,4,0))
shape4 = shape4.move(to = (0,6,0))
shape5 = shape5.move(to = (0,8,0))

shape1.add_plot(shape2)
shape1.add_plot(shape3)
shape1.add_plot(shape4)
shape1.add_plot(shape5)
shape1.show(azim=0, elev=12)
_images/shapes_test.PNG

Note

move() can transform the 2D Shapes created in yz plane to.desired 3D positions.

Transformation

In general, a transformation is accomplished by rotation together with translation.
Here, the rotation of a polygon is designed to control with two parameters, α and β, as shown below. In the rotating process, its origin is always fixed at the origin (0,0,0).
_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 means that its origin moves to a new position.

In Shape4D, the rotation and translation are combined into one function move().

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