Skip to content

Mapping

The objective of this section is to cover geometric constructions using points and vectors. In particular, this section focuses on transforming or mapping points from local to world coordinates.

Line to World

Provided with a line ( a, b ) defined by points a and b, and a point defined by a normalized parameter t along the line, determine its world position p.

""" Inputs
"""
t = 0.1
a = Point3d( ax, ay, az )
b = Point3d( bx, by, bz )
Solution

Assuming that the parameter is along the a -> b direction, this is just an application of linear interpolation. There are two ways to implement this as seen below.

""" Outputs
"""
p = a * ( 1 - t ) + b * t
''' or '''
p = a + ( b - a ) * t

World to Line

Provided with a line ( a, b ) defined by points a and b, and another point p, express the point in terms of a normalized parameter t along the line.

""" Inputs
"""
a = Point3d( ax, ay, az )
b = Point3d( bx, by, bz )
p = Point3d( px, py, pz )
Solution

The normalized parameter t represents the ratio between the projected distance of v = p - a onto the line and the line's length |b - a|. For example, when t is 0.0, 0.5, 1.0 the points projection coincides with a, the line's mid-point and b, respectively. If t < 0.0 or t > 1.0, then the point's projection is outside the line segment.

The projected distance can be derived from the dot product. The solution below shows first a step-by-step derivation, where the line's direction u = b - a is constructed, then the signed projected distance is computed using the dot product s = v * u / |u| and finally the parameter t = s / |u|.

Note that since the expression involves dividing with the line segment's length twice, this is equivalent to its squared distance, which can be computed from the dot product without using square roots. Also note that this expression can lead to division by zero in case the line has zero length.

""" Outputs
"""
u = b - a
v = p - a

U = u.Length
s = v * u / U
t = s / U

''' or '''

t = ( u * v ) / ( u * u )

Plane to World

Provided with a plane ( o, u, v ) with origin o and two orthonormal vectors, u and v, and a 2D point p on the plane, determine its world position q.

""" Inputs
"""
o =  Point3d( ax, ay, az )
u = Vector3d( ux, uy, uz )
v = Vector3d( vx, vy, vz )
p =  Point2d( px, py )
Solution

Computing the point's world coordinates is a simple application of the linear combinations vector arithmetic concept. Note that if a point is provided in a sense that it is already expressed in relationship with the basis this means that the expression below is a valid even if the basis vectors are not orthonormal.

""" Outputs
"""
q = o + u * p.X + v * p.Y

World to Plane

Provided with a plane ( o, u, v ) with origin o and two orthonormal vectors, u and v, and another point p, determine its local coordinates in the plane.

""" Inputs
"""
o =  Point3d( ax, ay, az )
u = Vector3d( ux, uy, uz )
v = Vector3d( vx, vy, vz )
p =  Point3d( px, py, pz )
Solution

Expressing a world point in relationship with the plane requires first constructing a vector for the plane's origin to the points w = p - o, followed by projecting the vector on each basis vector. Note that this works only if the basis vectors are orthogonal to one another.

""" Outputs
"""
w = p - o
q = Point2d( u * w, v * w )

Basis to World

Provided with a basis ( o, u, v, n ) with origin o and three orthonormal vectors u, v and n, and another point p expressed in reference to basis, determine its world position q.

""" Inputs
"""
o =  Point3d( ax, ay, az )
u = Vector3d( ux, uy, uz )
v = Vector3d( vx, vy, vz )
n = Vector3d( nx, ny, nz )
p =  Point3d( px, py, pz )
Solution

Computing the point's world coordinates is a simple application of the linear combinations vector arithmetic concept. Note that if a point is provided in a sense that it is already expressed in relationship with the basis this means that the expression below is a valid even if the basis vectors are not orthonormal.

""" Outputs
"""
q = o + u * p.X + v * p.Y + n * p.Z

World to Basis

Provided with a basis ( o, u, v, n ) with origin o and three orthogonal vectors, u, v and n, and another point p, expressed in reference to the world, determine its local position in reference to basis.

""" Inputs
"""
o =  Point3d( ax, ay, az )
u = Vector3d( ux, uy, uz )
v = Vector3d( vx, vy, vz )
n = Vector3d( nx, ny, nz )
p =  Point3d( px, py, pz )
Solution

Expressing a world point in relationship with the basis requires first constructing a vector for the basis' origin to the points w = p - o, followed by projecting the vector on each basis vector. Note that this works only if the basis vectors are orthogonal to one another.

""" Outputs
"""
w = p - o
q = Point3d( u * w, v * w, n * w )