Skip to content

Polygons

The objective of this section is to cover geometric constructions using points and vectors. In particular, this section focuses on polygons.

Equilateral Triangle

Determine the points a, b, c of an equilateral triangle in basis ( o, u, v, n ), where o is the origin, u, v and n are its orthonormal basis vectors.

""" Inputs
"""
o =  Point3d( ox, oy, oz )
u = Vector3d( ux, uy, uz )
v = Vector3d( vx, vy, vz )
n = Vector3d( nx, ny, nz )
Solution

One way to construct an equilateral triangle is to establish its coordinates in the world's XY-plane and then transform it to the arbitrary basis. Therefore, for convenience point a can be set at [0.0, 0.0], point b at [1.0, 0.0] and point c at [0.5, √3/2].

""" Output
"""
a = o + u * 0.0 + v * 0.0
b = o + u * 1.0 + v * 0.0
c = o + u * 0.5 + v * 0.5 * math.sqrt( 3 )

Inscribed Hexagon

Determine the points a, b, c, d, e, f of a hexagon inscribed in circle ( o, u, v, r ), where o is the center, u and v are orthonormal basis vectors and r is the radius of the circle.

""" Inputs
"""
o =  Point3d( ox, oy, oz )
u = Vector3d( ux, uy, uz )
v = Vector3d( vx, vy, vz )
r = 2.0
Solution

One way to construct the hexagon is by noticing that if it is conveniently registered in the world's XY-plane it is easy to transform it in any arbitrary basis. By setting the center of the circle to [0, 0] and the first point at [r, 0], we only need to compute one more point [r/2, r√3/2] and then use reflections about the X and Y axes to determine the locations of the remaining points.

""" Output
"""
x = r / 2
y = x * math.sqrt( 3 )

a = o + u * r + v * 0
b = o + u * x + v * y
c = o - u * x + v * y
d = o - u * r + v * 0
e = o - u * x - v * y
f = o + u * x - v * y

Regular Polygon

Generate the points for a regular polygon of n sides, provided with its side's length s in the plane ( o, u, v ), where o is the origin, u and v are its orthonormal basis vectors.

""" Inputs
"""
o =  Point3d( ox, oy, oz )
u = Vector3d( ux, uy, uz )
v = Vector3d( vx, vy, vz )
s = 2.0
n = 12
Solution

The simplest approach involves dividing a circle by the number of sides of the inscribed regular polygon. Thus the angle between consecutive radial line from the circle's center to the points of the polygon is a = 2Ï€ / n. With a bit of trigonometry, the radius r and side s of the polygon are associated by r = 0.5 * s / sin( a / 2 ).

""" Output
"""
def RegularPolygon( o, u, v, s, n ):
    a = 2.0 * math.pi / n
    r = 0.5 * s / math.sin( a / 2 )
    return [( o + u * r * math.cos( a * i )
                + v * r * math.sin( a * i ) )
        for i in range( n )]