Points and Vectors Multiplication
Multiplication of points and vectors is more complicated than regular real numbers. There are three distinct definitions. This section start with the simplest kind, namely point or vector times number. It is performed element-wise for each of the X
, Y
and Z
coordinates / components. Specifically, suppose the following point, vector and real number are defined:
p = Point3d( px, py, pz )
u = Vector3d( ux, uy, uz )
s = float( num )
The result of multiplying those respectively are seen below for different values of s
. Note that Rhino supports point and vector multiplication with real numbers using the *
operator.
""" Multiplication
"""
q = Point3d( px * s, py * s, pz * s )
v = Vector3d( ux * s, uy * s, uz * s )
""" Shortcut
"""
q = p * s
v = u * s
Algebraic Properties
-
Point and vector multiplication with scalars is commutative in the sense that it doesn't matter in which order vectors are multiplied
p * s = s * p
andu * s = s * u
. -
Multiplication is associative, as the terms can be grouped in different ways with the same result:
( p * s ) * s = p * ( s * s )
and( u * s ) * s = u * ( s * s )
. -
There exists a special multiplicative identity value, namely
1.0
that produces no effect under multiplication.
Geometric Interpretation
The semantics of point and vector multiplication with numbers are associated with the geometric transformation of uniform scaling.
Scaling Points
In CAD systems, scaling geometry is performed about a user-selected origin and a scaling factor. Multiplying points with scalars has the same effects as CAD scaling using the origin [0.0, 0.0, 0.0]
as the selected reference point. To emulate CAD's scaling behavior for a point p
about an origin o
with a scaling factor s
, we first compute the intermediate point q = p - o
. This is equivalent to moving the geometry, represented by the point p
, to the standard CAD origin [0.0, 0.0, 0.0]
. Now can apply the scaling operation q * s
, and finally move back the result q * s + o
. We thus in total performed the following operation: ( p - o ) * s + o
.
""" Inputs
"""
point = Point3d( 1, 2, 3 )
origin = Point3d( 0, 1, 0 )
factor = 2.0
""" Outputs
"""
scaled = ( point - origin ) * factor + origin
Scaling Vectors
The concept of vector times scalar multiplication u * s
is associated changing the vector's length. Conceptually we are stretching or shrinking the vector but we do not change its direction.
""" Inputs
"""
u = Vector3d( 1, 2, 3 )
""" Outputs
"""
v = u * 0.5 ''' Half size '''
v = u * 2.0 ''' Double size '''
Flipping Vectors
Multiplying a vector with -1
results into a new vector with the same magnitude but exactly the opposite direction. Therefore, negating vectors is equivalent to flipping their direction.
""" Inputs
"""
O = Vector3d( 0, 0, 0 )
u = Vector3d( 1, 2, 3 )
""" Operators
"""
v = u * -1 ''' Multiplication '''
v = O - u ''' Subtraction '''
v = -u ''' Negation '''
Vectors can be flipped using the Reverse( )
method provided by Rhino's geometry implementation as seen below. Note that the operation is performed in-place, that is the vector object is modified internally.
""" Rhino
"""
u.Reverse( )
Type Conversion
The rhino / grasshopper library supports point and vector by scalar multiplication using the standard notation. Note that the implementation support this symmetrically.
Type A | * | Type B | = | Type A - B | Interpretation |
---|---|---|---|---|---|
Point3d | * | float | = | Point3d | |
float | * | Point3d | = | Point3d | |
Vector3d | * | float | = | Vector3d | |
float | * | Vector3d | = | Vector3d |
Division with Scalars
Division of points and vectors by real numbers is also defined as an extension to multiplication. It is equivalent of taking the reciprocal of the scalar and performing the multiplication as seen above p / s = p * ( 1 / s )
and u / s = u * ( 1 / s )
.
However, the scalar can only appear in the right-hand side of the expression. This is a limitation of the library implementation.
Type A | / | Type B | = | Type A - B | Interpretation |
---|---|---|---|---|---|
Point3d | / | float | = | Point3d | |
float | / | Point3d | = | None | |
Vector3d | / | float | = | Vector3d | |
float | / | Vector3d | = | None |