Containment
The objective of this section is to cover geometric constructions using points and vectors. In particular, this section focuses on detecting a geometric object is situated inside another.
Point in Interval
Provided with a real value v
and an interval ( a, b )
, determine the condition such that the value t
is inside the interval.
""" Inputs
"""
v = 0.5
a, b = 0.0, 1.0
Solution
Containment is trivially computed using arithmetic and boolean operations as seen below. Note however, that checking for inclusion requires two arithmetic operations because of the use of and
, whereas exclusion potentially requires only one when v < a
because or
short-circuits the rest of the expression.
""" Outputs
"""
inside = ( v >= a ) and ( v <= b )
outside = ( v < a ) or ( v > b )
inside = not outside
Point in Domain
Provided with a point ( u, v )
and a surface domain ( umin, umax )
and ( vmin, vmax )
, determine the condition such that the point is inside the domain.
""" Inputs
"""
u, v = 0.5, 0.5
umin, umax = 0.0, 1.0
vmin, vmax = 0.0, 1.0
Solution
Containment is computed using arithmetic and boolean operations in the same sense it is performed for a value in an interval. Note that this approach applies to the scenario of testing whether a 2D point in contained within an axis aligned bounding rectangle.
""" Outputs
"""
inside = ( ( u >= umin ) and ( u <= umax ) and
( v >= vmin ) and ( v <= vmax ) )
outside = ( ( u < umin ) or ( u > umax ) or
( v < vmin ) or ( v > vmax ) )
inside = not outside
Point in Bounding Box
Provided with an axis aligned bounding box ( min, max )
where min
and max
are its extreme points, and a point p
, determine the condition such that the point is inside the bounding box.
""" Inputs
"""
p = Point3d( px, py, pz )
min = Point3d( xmin, ymin, zmin )
max = Point3d( xmax, ymax, zmax )
Solution
Containment is computed using arithmetic and boolean operations in the same sense it is performed for a value in an interval and a point in a domain. Note that this approach can be used for checking whether a 3D parameter is within a volume domain.
""" Outputs
"""
inside = ( ( p.X >= min.X ) and ( p.X <= max.X ) and
( p.Y >= min.Y ) and ( p.Y <= max.Y ) and
( p.Z >= min.Z ) and ( p.Z <= max.Z ) )
outside = ( ( p.X < min.X ) or ( p.X > max.X ) or
( p.Y < min.Y ) or ( p.Y > max.Y ) or
( p.Z < min.Z ) or ( p.Z > max.Z ) )
inside = not outside
Point in Circle
Provided with a circle ( o, r )
with origin o
and radius r
in the XY-Plane, and a point p
determine the condition such that the point p
is inside the circle.
""" Inputs
"""
o, r = Point3d( ox, oy, oz ), 1.0
p = Point3d( px, py, pz )
Solution
Containment is computed using the Euclidean distance between the point and the circle's origin. Additionally, for overlap testing it is common to use a tolerance value to overcome potential numerical accuracy issues.
""" Without Tolerance
"""
distance = p.DistanceTo( o )
inside = distance < r
outside = distance > r
""" With Tolerance
"""
epsilon = 1e-5 #-- Tolerance
overlap = abs( distance - r ) <= epsilon
Point in Plane
Provided with a plane ( o, n )
with origin o
and unit normal n
and a point p
, determine the condition such that the point is inside the plane.
""" Inputs
"""
o, n = Point3d( ox, oy, oz ), Vector3d( nx, ny, nz )
p = Point3d( px, py, pz )
Solution
Containment in this scenario is associated with overlap, as such the projected distance from the point to the plane is computed using the dot product and its value is checked against a tolerance value.
""" Outputs
"""
distance = n * ( p - o )
epsilon = 1e-5 #-- Tolerance
overlap = abs( distance ) <= epsilon
Point in Half-Space
Provided with a plane ( o, n )
with origin o
and unit normal n
and a point p
, determine the condition such that the point is inside the positive half-space defined by the plane.
""" Inputs
"""
o, n = Point3d( ox, oy, oz ), Vector3d( nx, ny, nz )
p = Point3d( px, py, pz )
Solution
Considering that a plane splits space into two parts, one in the positive direction of its normal and the opposite, this is a matter of computing the signed distance of projection using the dot product and checking its sign.
""" Without Tolerance
"""
distance = n * ( p - o )
inside = distance > 0
outside = distance < 0
""" With Tolerance
"""
epsilon = 1e-5 #-- Tolerance
inside = distance > -epsilon
outside = distance < epsilon
Point in Line Segment
Provided with line segment ( a, b )
defined by two points a
and b
and a point p
on the line, determine the condition such that the point is within the line segment.
""" Inputs
"""
a, b = Point3d( ax, ay, az ), Point3d( bx, by, bz )
p = Point3d( px, py, pz )
Solution
There are several ways to check this condition. One way is to measure the distance between the point and line's start and end points and check if their sum equals the line's length. This is reasonable because if the point is outside the line then the sum of distances will be larger than the line's length.
Alternatively, the normalized parameter along the line t
of point p
can be computed. The point is within the line segment if the parameter is inside the unit-range. Note that this approach, on the positive side, does not compute square roots, but on the negative side, it will fail if the line segment's length is zero.
""" Using Distances
"""
L = a.DistanceTo( b )
A = a.DistanceTo( p )
B = b.DistanceTo( p )
inside = A + B <= L #- sketchy
outside = A + B > L
""" Using Parameter
"""
u, v = b - a, p - a
t = ( u * v ) / ( u * u )
inside = ( t >= 0.0 ) and ( t <= 1.0 )
outside = ( t < 0.0 ) or ( t > 1.0 )