Areas
The objective of this section is to cover geometric constructions using points and vectors. In particular, this section focuses on computing areas.
Parallelogram
Provided with two vectors u
and v
, determine the area of the parallelogram spanned by them.
""" Inputs
"""
u = Vector3d( ux, uy, uz )
v = Vector3d( vx, vy, vz )
Solution
The magnitude of the cross product between two vectors measures the area of the parallelogram spanned.
- Compute the cross product of the
u
andv
vectors. - Measure the length of the normal vector.
""" Outputs
"""
a = Vector3d.CrossProduct( u, v ).Length
Triangle
Provided three points a
, b
, and c
, determine the area of triangle ( a, b, c )
.
""" Inputs
"""
a = Point3d( ax, ay, az )
b = Point3d( bx, by, bz )
c = Point3d( cx, cy, cz )
Solution
The solution requires noticing that we can compute the area of a triangle if we half the area of the parallelogram spanned by two vectors encoded in their cross product.
- Construct two vectors
u = b - a
andv = c - a
along the triangle's sides. - Compute the cross product of the
u
andv
vectors. - Measure half of the length of the normal vector.
""" Outputs
"""
u = b - a
v = c - a
a = Vector3d.CrossProduct( u, v ).Length * 0.5
Polygon
Provided with a plane ( o, n )
defined by its origin o
and unit normal n
, and a list of n
points [p1, p2, ..., pn]
compute the area of the polygon.
""" Inputs
"""
origin = Point3d( ox, oy, oz )
normal = Vector3d( nx, ny, nz )
points = [Point3d( x1, y1, z1 ),
Point3d( x2, y2, z2 ),
#...
Point3d( xn, yn, zn )]
Solution
Computing the area of an arbitrary spatial polygon requires first to project its points to a plane. To compute its area we can either use the shoelace algorithm or Rhino's area and mass properties.
- Project the points on the plane
- Compute the area of the 2D polygon
Note that we need to create a polyline curve in order to use the area and mass properties compute method.
""" Outputs
"""
projected = []
for point in points:
projected.append( point - normal * ( point - origin ) * normal )
props = AreaMassProperties.Compute(
PolylineCurve( projected )
area = props.Area
The shoelace algorithm is presented below. Note that we need to ensure that the polygon is closed. Therefore, the first point in appended at the end of the list. Then we iterate all points pair-wise and accumulate the discriminants. The area computed using this method is also known as the signed area of the polygon because it is positive or negative depending on whether the points are ordered clockwise or anticlockwise.
""" Outputs
"""
projected = [point - normal * ( point - origin ) * normal
for point in points]
projected.append( projected[0] )
area = 0.0
for p, q in zip( points[:-1], points[1:] ):
area += ( p.X + q.X ) * ( p.Y - q.Y )
area = abs( area / 2 )