Offsets
The objective of this section is to cover geometric constructions using points and vectors. In particular this section focuses on shape offsets.
Point
Provided with a point p
and distance d
, determine the shape of all points offset (having the same distance) by d
from the point.
""" Inputs
"""
d = 2.0
p = Point3d( px, py, pz )
Solution
The points equidistant from another point describe a sphere 3D space and a circle in 2D plane.
""" Outputs
"""
s = Sphere( p, d )
Line
Provided with a line ( p, q )
defined by two points p
, and q
, and distance d
, determine the shape of all the points offset (having the same distance) by d
from the line.
""" Inputs
"""
d = 2.0
p = Point3d( px, py, pz )
q = Point3d( qx, qy, qz )
Solution
The points equidistant from a line in 3D describe an infinitely long cylinder. The solution below constructs a finite cylindrical surface, since infinite shapes are generally not supported by computer aided design applications.
""" Outputs
"""
cylinder = Cylinder( Circle(
Plane( p, n ), q - p ),
p.DistanceTo( q ) )
Segment
Provided with a line segment ( p, q )
defined by two points p
, and q
, and distance d
, determine the shape of all the points offset (having the same distance) by d
from the line segment.
""" Inputs
"""
d = 2.0
p = Point3d( px, py, pz )
q = Point3d( qx, qy, qz )
Solution
The points equidistant from a line segment in 3D describe a capsule shape, where projected points situated within the line segment correspond to a cylindrical surface, whereas points outside correspond to semi-spherical surfaces.
""" Outputs
"""
a = Sphere( p, d )
b = Cylinder( Circle(
Plane( p, q - p ), d ),
p.DistanceTo( q ) )
c = Sphere( q, d )
capsule = Brep.CreateBooleanUnion( [
Brep.CreateFromSphere( a ),
Brep.CreateFromCylinder( b, True, True ),
Brep.CreateFromSphere( c )], 1e-5 )
Plane
Provided with a plane ( a, b, c )
defined by three points a
, b
, c
, determine all points offset by distance d
from the plane.
""" Inputs
"""
d = 2.0
a = Point3d( ax, ay, az )
b = Point3d( bx, by, bz )
c = Point3d( cx, cy, cz )
Solution
The points equidistant from a plane are situated on two offset planes, one in front and one at the back at a fixed distance. They are constructed by translating the plane's origin along the normal direction +/-d
. Note that the back plane's normal must be flipped which is equivalent to swapping its basis vectors.
""" Outputs
"""
o = a
u = b - a
v = c - b
n = Vector3d.CrossProduct( u, v )
u.Unitize( )
v.Unitize( )
n.Unitize( )
front = Plane( o + n * d, u, v )
back = Plane( o - n * d, v, u )
Triangle
Provided with a triangle ( a, b, c )
defined by three points a
, b
, c
, determine all points offset by distance d
from the triangle.
""" Inputs
"""
d = 2.0
a = Point3d( ax, ay, az )
b = Point3d( bx, by, bz )
c = Point3d( cx, cy, cz )
Solution
The buffered shape produced by inflating a triangle can be composed using one sphere for each node, one cylinder for each edge and one extrusion for each face. Note that this approach can be used for offsetting a wide range of shapes into solids.
""" Outputs
"""
points = [a, b, c]
shapes = []
""" Offset Direction
"""
n = Vector3d.CrossProduct( b - a, c - b )
n *= d / n.Length
""" One Sphere per Node
"""
for point in points:
sphere = Sphere( point, d )
shapes.append( sphere.ToBrep( ) )
""" One Cylinder per Edge
"""
points.append( points[0] )
for s, t in zip( points[:-1], points[1:] ):
profile = Circle( Plane( s, t - s ), d )
shape = Cylinder( profile, s.DistanceTo( t ) )
shapes.append( shape.ToBrep( True, True ) )
""" One Extrusion per Face
"""
points = [p - n for p in points]
profile = PolylineCurve( points )
shapes.append( Extrusion.Create(
profile, d * 2, True ).ToBrep( ) )
""" Inflated Triangle
"""
inflated = Brep.CreateBooleanUnion( shapes, 1e-5 )