You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Point3d struct represents a point in 3D space with X, Y, and Z coordinates. It is one of the most fundamental geometry classes in the AutoCAD .NET API, used extensively for positioning entities, defining vertices, and performing geometric calculations.
Namespace
Autodesk.AutoCAD.Geometry
Key Properties
Property
Type
Description
X
double
Gets the X coordinate
Y
double
Gets the Y coordinate
Z
double
Gets the Z coordinate
Origin
Point3d (static)
Gets the origin point (0, 0, 0)
Key Methods
Method
Return Type
Description
Add(Vector3d)
Point3d
Adds a vector to the point
Subtract(Vector3d)
Point3d
Subtracts a vector from the point
GetVectorTo(Point3d)
Vector3d
Gets the vector from this point to another
DistanceTo(Point3d)
double
Calculates distance to another point
TransformBy(Matrix3d)
Point3d
Transforms the point by a matrix
RotateBy(double, Vector3d, Point3d)
Point3d
Rotates the point around an axis
Mirror(Plane)
Point3d
Mirrors the point across a plane
ToArray()
double[]
Converts to array [X, Y, Z]
Code Examples
Example 1: Creating Points
// Create point at originPoint3dorigin=Point3d.Origin;// (0, 0, 0)// Create point with coordinatesPoint3dpt1=newPoint3d(10,20,0);Point3dpt2=newPoint3d(5.5,7.3,12.8);// Create from arraydouble[]coords={15,25,35};Point3dpt3=newPoint3d(coords);ed.WriteMessage($"\nPoint 1: ({pt1.X}, {pt1.Y}, {pt1.Z})");ed.WriteMessage($"\nPoint 2: ({pt2.X}, {pt2.Y}, {pt2.Z})");ed.WriteMessage($"\nPoint 3: ({pt3.X}, {pt3.Y}, {pt3.Z})");
Example 2: Point Arithmetic
Point3dpt=newPoint3d(10,10,0);Vector3dvec=newVector3d(5,3,0);// Add vector to pointPoint3dnewPt=pt.Add(vec);// (15, 13, 0)// Subtract vector from pointPoint3dmovedPt=pt.Subtract(vec);// (5, 7, 0)// Get vector between two pointsPoint3dpt1=newPoint3d(0,0,0);Point3dpt2=newPoint3d(10,10,0);Vector3ddirection=pt1.GetVectorTo(pt2);ed.WriteMessage($"\nOriginal: {pt}");ed.WriteMessage($"\nAfter add: {newPt}");ed.WriteMessage($"\nAfter subtract: {movedPt}");ed.WriteMessage($"\nDirection vector: {direction}");
Example 3: Distance Calculations
Point3dpt1=newPoint3d(0,0,0);Point3dpt2=newPoint3d(10,0,0);Point3dpt3=newPoint3d(0,10,0);Point3dpt4=newPoint3d(10,10,10);// Calculate distancesdoubledist12=pt1.DistanceTo(pt2);// 10.0doubledist13=pt1.DistanceTo(pt3);// 10.0doubledist14=pt1.DistanceTo(pt4);// 17.32 (3D distance)ed.WriteMessage($"\nDistance pt1 to pt2: {dist12:F2}");ed.WriteMessage($"\nDistance pt1 to pt3: {dist13:F2}");ed.WriteMessage($"\nDistance pt1 to pt4: {dist14:F2}");
Example 4: Midpoint Calculation
Point3dpt1=newPoint3d(0,0,0);Point3dpt2=newPoint3d(20,10,5);// Calculate midpointPoint3dmidpoint=newPoint3d((pt1.X+pt2.X)/2,(pt1.Y+pt2.Y)/2,(pt1.Z+pt2.Z)/2);// Alternative using vector mathVector3dhalfVector=pt1.GetVectorTo(pt2)*0.5;Point3dmidpoint2=pt1.Add(halfVector);ed.WriteMessage($"\nMidpoint: ({midpoint.X}, {midpoint.Y}, {midpoint.Z})");
Example 5: Transforming Points
Point3dpt=newPoint3d(10,0,0);// Create translation matrix (move 5 units in X, 10 in Y)Matrix3dtranslation=Matrix3d.Displacement(newVector3d(5,10,0));Point3dtranslatedPt=pt.TransformBy(translation);// Create rotation matrix (rotate 90° around Z axis)Matrix3drotation=Matrix3d.Rotation(Math.PI/2,Vector3d.ZAxis,Point3d.Origin);Point3drotatedPt=pt.TransformBy(rotation);// Create scaling matrix (scale by 2)Matrix3dscaling=Matrix3d.Scaling(2.0,Point3d.Origin);Point3dscaledPt=pt.TransformBy(scaling);ed.WriteMessage($"\nOriginal: {pt}");ed.WriteMessage($"\nTranslated: {translatedPt}");ed.WriteMessage($"\nRotated: {rotatedPt}");ed.WriteMessage($"\nScaled: {scaledPt}");
Example 6: Rotating Points
Point3dpt=newPoint3d(10,0,0);Point3dcenter=Point3d.Origin;// Rotate 45° around Z axisdoubleangle=Math.PI/4;// 45 degrees in radiansPoint3drotated=pt.RotateBy(angle,Vector3d.ZAxis,center);ed.WriteMessage($"\nOriginal: ({pt.X:F2}, {pt.Y:F2}, {pt.Z:F2})");ed.WriteMessage($"\nRotated 45°: ({rotated.X:F2}, {rotated.Y:F2}, {rotated.Z:F2})");// Rotate multiple times to create circular patternfor(inti=0;i<8;i++){doubleang=(i*2*Math.PI)/8;Point3dcircPt=pt.RotateBy(ang,Vector3d.ZAxis,center);ed.WriteMessage($"\nPoint {i}: ({circPt.X:F2}, {circPt.Y:F2})");}
Example 7: Creating Entities with Points
using(Transactiontr=db.TransactionManager.StartTransaction()){BlockTableRecordbtr=tr.GetObject(db.CurrentSpaceId,OpenMode.ForWrite)asBlockTableRecord;// Create line using two pointsPoint3dstartPt=newPoint3d(0,0,0);Point3dendPt=newPoint3d(10,10,0);Lineline=newLine(startPt,endPt);line.SetDatabaseDefaults();btr.AppendEntity(line);tr.AddNewlyCreatedDBObject(line,true);// Create circle using center pointPoint3dcenter=newPoint3d(5,5,0);Circlecircle=newCircle(center,Vector3d.ZAxis,3.0);circle.SetDatabaseDefaults();btr.AppendEntity(circle);tr.AddNewlyCreatedDBObject(circle,true);// Create arc using center, start, and end pointsPoint3darcCenter=newPoint3d(0,0,0);doubleradius=5.0;doublestartAngle=0;doubleendAngle=Math.PI/2;Arcarc=newArc(arcCenter,Vector3d.ZAxis,radius,startAngle,endAngle);arc.SetDatabaseDefaults();btr.AppendEntity(arc);tr.AddNewlyCreatedDBObject(arc,true);tr.Commit();}
Example 8: Point Array Conversion
Point3dpt=newPoint3d(10,20,30);// Convert to arraydouble[]coords=pt.ToArray();ed.WriteMessage("\nPoint coordinates:");ed.WriteMessage($"\n X: {coords[0]}");ed.WriteMessage($"\n Y: {coords[1]}");ed.WriteMessage($"\n Z: {coords[2]}");// Create point from arrayPoint3dnewPt=newPoint3d(coords);ed.WriteMessage($"\nRecreated point: ({newPt.X}, {newPt.Y}, {newPt.Z})");
// Define a linePoint3dlineStart=newPoint3d(0,0,0);Point3dlineEnd=newPoint3d(10,0,0);// Point to projectPoint3dtestPoint=newPoint3d(5,5,0);// Calculate closest point on lineVector3dlineVector=lineStart.GetVectorTo(lineEnd);Vector3dpointVector=lineStart.GetVectorTo(testPoint);doubledotProduct=lineVector.DotProduct(pointVector);doublelineLength=lineVector.Length;doublet=dotProduct/(lineLength*lineLength);// Clamp t to [0, 1] to stay on line segmentt=Math.Max(0,Math.Min(1,t));Point3dclosestPoint=lineStart.Add(lineVector*t);ed.WriteMessage($"\nTest point: {testPoint}");ed.WriteMessage($"\nClosest point on line: {closestPoint}");ed.WriteMessage($"\nDistance: {testPoint.DistanceTo(closestPoint):F2}");
Point3dstart=newPoint3d(0,0,0);Point3dend=newPoint3d(10,10,0);// Get 10 points along the linefor(inti=0;i<=10;i++){doublet=i/10.0;Vector3dvec=start.GetVectorTo(end)*t;Point3dinterpolated=start.Add(vec);}
Point3d vs Point2d
Feature
Point3d
Point2d
Dimensions
X, Y, Z
X, Y
Namespace
Geometry
Geometry
Use Case
3D coordinates
2D coordinates
Conversion
Can convert to Point2d
Can convert to Point3d (Z=0)
Best Practices
Use Origin: Use Point3d.Origin instead of new Point3d(0, 0, 0)
Immutability: Point3d is a struct; operations return new points
Tolerance: Use tolerance-based equality for floating-point comparisons
Vector Math: Use GetVectorTo() for direction and distance calculations
Transformations: Use TransformBy() for complex geometric operations
2D Operations: Set Z=0 for 2D operations in XY plane
Performance: Point3d is a value type (struct), passed by value
Null Checks: Point3d cannot be null (it's a struct)