The following examples show some of the most commonly used functions in the line and plane classes. These examples show how to use the line and plane classes for basic linear algebra operations. Although the examples use the 3D classes, most of the functions that do not involve the plane class are also present in the 2D classes. These examples also use the infinite line and plane classes, but they are equally valid for line segments, rays, and bounded planes.
The default line constructor constructs a line along the X axis. The default plane constructor constructs the XY plane:
AcGePoint3d p1(2.0,5.0,-7.5), p2; AcGeLine3d line1(p1,v1), line2; AcGePlane plane1(p1,v1), plane2;
The above constructor for line1 constructs a line through p1 in the direction of v1. The constructor for plane1 constructs a plane through p1 and normal to v1. Thus, line1 is perpendicular to plane1.
The following functions return the line or plane definition:
p1 = line1.pointOnLine(); // Arbitrary point on line. v1 = line1.direction(); // Direction vector of line. p1 = plane1.pointOnPlane(); // Arbitrary point on plane. v1 = plane1.normal(); // Normal vector of plane.
The direction() and normal() functions always return unit vectors.
The following functions return the closest point on the line or plane to the point p1:
p2 = line1.closestPointTo(p1); p2 = plane1.closestPointTo(p1);
The following functions return the distance between a point and line or plane (these distances will be the same as the distances between p1 and p2 above):
double len = line1.distanceTo(p1); len = plane1.distanceTo(p1);
The following functions return a Boolean value (true or false) and may be used inside an if statement. The first two test if the point p1 lies on line1orplane1, and the third tests if line1 lies on plane1:
if (line1.isOn(p1)) if (plane1.isOn(p1)) if (line1.isOn(plane1))
The following functions test if lines or planes are parallel, perpendicular, or coincident:
if (line1.isParallelTo(line2)) if (line1.isParallelTo(plane1)) if (line1.isPerpendicularTo(line2)) if (line1.isPerpendicularTo(plane1)) if (line1.isColinearTo(line2)) if (plane1.isParallelTo(plane2)) if (plane1.isPerpendicularTo(plane2)) if (plane1.isCoplanarTo(plane2))
The following functions return the intersections of lines and planes:
if (line1.intersectWith(line2,p1)) if (line1.intersectWith(plane1,p1)) if (plane1.intersectWith(plane2,line1))