Clash Detection
The objective of this section is to cover geometric constructions using points and vectors. In particular, this section focuses on detecting whether two geometric objects are clashing with one another.
Sphere and Sphere
Provided with two spheres ( p, s )
and ( q, t )
with centers p
and q
, and radii s
and t
, determine the condition such that the two spheres have clearance d
(are spaced apart by at least d
).
""" Inputs
"""
p, s = Point3d( px, py, pz ), 1.0
q, t = Point3d( qx, qy, qz ), 2.0
d = 1e-5
Solution
Two spheres overlap, if the distance between their centers is smaller than the sum of their radii. By adding the clearance term the concept is extended to clash detection.
""" Outputs
"""
distance = p.DistanceTo( q )
overlap = distance < s + t
clashing = distance < s + t + d
Sphere and Plane
Provided with a sphere ( p, r )
with center p
and radius r
, and a plane ( o, n )
with origin o
and unit normal n
, determine the condition such that the two objects have clearance d
(are spaced apart by at least d
).
""" Inputs
"""
p, r = Point3d( px, py, pz ), 1.0
o, n = Point3d( ox, oy, oz ), Vector3d( nx, ny, nz )
d = 1e-5
Solution
A plane and a sphere overlap if the distance between the sphere's center and the plane is smaller than the sphere's radius. The distance is computed from the absolute value of the dot product, assuming we don't care about the side of the plane. By adding the clearance term the concept is extended to clash detection.
""" Outputs
"""
distance = abs( n * ( p - o ) )
overlap = distance < r
clashing = distance < r + d
Sphere and Line
Provided with a sphere ( c, r )
with center c
and radius r
, and a line ( p, u )
with origin point p
and unit direction u
, determine the condition such that the two objects have clearance d
(are spaced apart by at least d
).
""" Inputs
"""
c, r = Point3d( cx, cy, cz ), 1.0
p, u = Point3d( px, py, pz ), Vector3d( ux, uy, uz )
d = 1e-5
Solution
A line and a sphere overlap if the distance between the sphere's center and the line is smaller than the sphere's radius. The distance is computed using the dot product. By adding the clearance term the concept is extended to clash detection.
""" Outputs
"""
v = c - p
w = v - u * v * u
distance = w.Length
overlap = distance < r
clashing = distance < r + d