Angles
The objective of this section is to cover geometric constructions using points and vectors. In particular, this section focuses on computing angles.
Between Vectors
Provided with two vectors u
and v
, determine the angle a
spanned between them.
""" Inputs
"""
u = Vector3d( ux, uy, uz )
v = Vector3d( vx, vy, vz )
Solution
Computing the angle between vectors is based on the trigonometric definition of the dot product u · v = |u| * |v| * cos( t )
. Note that the angle computed is in radians.
- Normalize both
u
andv
vectors. - Use the arc-cosine of the dot product.
""" Outputs
"""
u.Unitize( )
v.Unitize( )
a = math.acos( u * v )
Using Rhino's geometry library requires invoking the Vector3d
static method VectorAngle( )
. See the relevant documentation.
""" Outputs
"""
a = Vector3d.VectorAngle( u, v )
Angle Bisector
Provided three points a
, b
, and c
, determine the location of a point p
on the bisector of the angle of the triangle ( a, b, c )
from point a
.
""" Inputs
"""
a = Point3d( ax, ay, az )
b = Point3d( bx, by, bz )
c = Point3d( cx, cy, cz )
Solution
A simple solution for this construction requires noticing that the problem is trivial for isosceles triangles, where two sides ab
and ac
are equal. For these triangles the line from a
to the mid-point of the opposite side, namely ( b + c ) / 2
, is bisecting the angle.
We create two vectors from a
to the other points b
and c
, namely u = b - a
and v = c - a
and then normalize them U = u / |u|
and V = v / |v|
. This is equivalent to making them the same size |U| = |V|
, as if they were produced from a unit-length isosceles triangle.
Adding w = U + V
forms a vector pointing to the opposite corner of the parallelogram spanned form a
. This direction is bisecting the angle as required. The last step is to translate point a
by adding the bisecting vector p = a + w
.
- Create the vectors from
a
tob
andc
. - Normalize and add the two vectors.
- Translate
a
by the bisecting direction.
""" Outputs
"""
u = b - a; u.Unitize( )
v = c - a; v.Unitize( )
p = a + u + v
Point in Plane
Provided with a plane ( o, u, v )
with origin o
and orthonormal directions u
and v
, and another point p
in space, determine its angle a
in [0, 2π]
with respect to the plane.
""" Inputs
"""
o = Point3d( ox, oy, oz )
u = Vector3d( ux, uy, uz )
v = Vector3d( vx, vy, vz )
p = Point3d( px, py, pz )
Solution
This question has conceptually two different parts. First the point provided is in space so we need to associate it with the plane. This can be done by projecting it onto the plane as seen in projections.
Alternatively, we can construct a vector w = p - o
from the origin to the point and compute the dot products x = u · w
and y = v · w
. Notice that the point q = [x, y]
represents the local coordinates version of the original point. In a sense we performed the projection for each of the plane's axes individually.
To compute the angle in a 360deg sense we need use the two-parameter arctangent method which provides an angle in the [-π, π]
range. Finally, we need to check if the angle is negative and adjust it such that it is within the desired [0, 2π]
angle range.
- Create a vector
w = p - o
from the plane's origino
to the spatial pointp
. - Compute the local coordinates
[u · w, v · w]
by dot product projections. - Compute the angle
a = tan-1( y, x )
and adjust its range if it is negative.
#-- Outputs
#--
w = p - o
x = u * w
y = v * W
a = math.atan2( y, x )
if( a < 0 ): a += 2 * math.pi