Points and Vectors Subtraction
Point and vector subtraction has the same properties as regular real numbers. It is performed element-wise for each of the X
, Y
and Z
coordinates / components. Specifically, suppose the following two points and vectors are defined:
p = Point3d( px, py, pz )
q = Point3d( qx, qy, qz )
u = Vector3d( ux, uy, uz )
v = Vector3d( vx, vy, vz )
The results of subtracting those respectively are seen below. Note that the standard Rhino library support natively the addition of points and vectors. However, because it is targeting geometric use, the resulting types may be unexpected.
""" Subtraction
"""
o = Vector3d( p.X - q.X,
p.Y - q.Y,
p.Z - q.Z )
w = Vector3d( u.X - v.X,
u.Y - v.Y,
u.Z - v.Z )
""" Shortcut
"""
w = u - v
o = p - q
Algebraic Properties
-
Point and vector subtraction is not commutative
p - q ≠ q - p
andu - v ≠ v - u
. It is in fact anti-commutative becausep - q = -( q - p )
andu - v = -( v - u )
. In other words the direction is flipped. -
Subtraction is associative in that the terms can be grouped in different ways with the same result:
( p + q ) - o = p + ( q - o )
and( u + v ) - w = u + ( v - w )
. -
There exists a special vector, namely
O = [0.0, 0.0, 0.0]
that produces no effect under subtraction, also known as the zero vector. -
Subtracting the zero vector
O
from another vectoru =[ux, uy, uz]
results into a vector with opposite directionO - u = -u = [-ux, -uy, -uz]
.
Geometric Interpretation
The semantics of point and vector subtraction are a bit more nuanced compared to addition. Subtraction encompasses the notions of constructing vectors from points, translating points by vectors, and compounding vectors with one having its direction flipped.
Constructing Vectors
Subtraction between points implies the construction of a vector which contains the relative displacement between the two locations. The vector target - source
is sometimes visually represented with an arrow starting from point source
and ending at point target
. Note that the way we express the displacement source
→ target
is the flipped in the subtraction target - source
.
Translating Points
Subtraction between a point p
and a vector u
is associated with translating the point towards the opposite direction of the vector p - u = p + ( -u )
.
Vector Algebra
Subtracting vectors conveys the notion of computing an aggregate direction. Subtraction between vectors can be expressed in the same sense as addition but with the second operand's direction flipped.
Peculiar Case
Subtracting a point from a vector is geometrically awkward. It may be interpreted as regular vector subtraction, if the point is considered as a vector from the origin.
Type Conversion
Rhino's geometry library supports point and vector subtraction using the same operator as for numbers. However, it throws an exception for the ambiguous case, perhaps to demotivate its use. This can be bypassed by casting the point into a vector before subtracting.
Type A | - | Type B | = | Type A - B | Interpretation |
---|---|---|---|---|---|
Point3d | - | Point3d | = | Vector3d | |
Point3d | - | Vector3d | = | Point3d | |
Vector3d | - | Point3d | = | None | |
Vector3d | - | Vector3d | = | Vector3d |