-
Notifications
You must be signed in to change notification settings - Fork 26
Line, Ray, LineSegment
[[module omega | Python-Reference#module-omega]]
A Line
is a line on plane extending to infinity in both directions.
a Ray
has a finite end-point and extends to infinity in a single direction; a LineSegment
joins two points. All of these classes exist in 2D and 3D variants. Just append a 2
or 3
to the class name to indicate the number of dimensions.
All three classes support the same constructors, operators and methods, but may behave differently when calculating intersections etc.
You may construct a line, ray or line segment using any of:
- another line, ray or line segment
- two points
- a point and a vector
- a point, a vector and a length
For example:
>>> Line3(Point3(1.0, 1.0, 1.0), Point3(1.0, 2.0, 3.0))
Line3(<1.00, 1.00, 1.00> + u<0.00, 1.00, 2.00>)
>>> Line3(Point3(0.0, 1.0, 1.0), Vector3(1.0, 1.0, 2.0))
Line3(<0.00, 1.00, 1.00> + u<1.00, 1.00, 2.00>)
>>> Ray3(Point3(1.0, 1.0, 1.0), Vector3(1.0, 1.0, 2.0), 1.0)
Ray3(<1.00, 1.00, 1.00> + u<0.41, 0.41, 0.82>)
Internally, lines, rays and line segments store a Point p and a Vector v. You can also access (but not set) the two endpoints p1 and p2. These may or may not be meaningful for all types of lines.
The following methods are supported by all three classes:
If other is a Sphere, returns a LineSegment3
which is the intersection of the sphere and line. or None
if there is no intersection.
If other is a Circle, returns a LineSegment2
which is the intersection of the circle and line. or None
if there is no intersection.
If other is a Plane, returns a Point3 of intersection, or None
.
Returns a LineSegment
which is the minimum length line segment that can connect the two shapes. For two parallel lines, this line segment may be in an arbitrary position. other may be a Point, Line
, Ray
, LineSegment
, Sphere, Circle or Plane.
Returns the absolute minimum distance to other. Internally this simply returns the length of the result of connect
.
LineSegment
also has a length property which is read-only.