[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/McGePoint3d
Class: McGePoint3d
2d.McGePoint3d
McGePoint3d represents a point object in three-dimensional space.
Description
This class is used to describe and manipulate coordinate points in CAD/3D scenes, with common uses including: Calculate the distance between two points, perform point vector operations, perform coordinate transformations, and interconvert vector objects with Three.js. It is the fundamental type for many geometric operations and graphic drawing logic.
Example
import { McGePoint3d, McGeVector3d, McGeMatrix3d } from "mxcad";
const pt1 = new McGePoint3d(10, 20, 0);
const pt2 = new McGePoint3d(30, 40, 0);
const distance = pt1.distanceTo(pt2);
Console.log ("distance:", distance);
const vec = pt2.sub(pt1);
const matrix = new McGeMatrix3d();
matrix.setToTranslation(vec); //Translation matrix
pt1.transformBy(matrix); //Apply translation matrixTable of contents
Constructors
Properties
Accessors
Methods
Constructors
constructor
• new McGePoint3d(dX?, dY?, dZ?)
Constructor.
Parameters
| Name | Type | Description |
|---|---|---|
dX? | Number \ | object |
dY? | Number | Y coordinate |
dZ? | Number | Z coordinate |
Properties
imp
• imp: any
Internal implementation object
kOrigin
▪ Static kOrigin: McGePoint3d
Origin of coordinate system
Accessors
vector3
• get vector3(): Vector3
Returns
Vector3
• set vector3(val): void
Parameters
| Name | Type |
|---|---|
val | Vector3 |
Returns
void
x
• get x(): number
Get or set the X coordinate.
Returns
number
• set x(val): void
Parameters
| Name | Type |
|---|---|
val | number |
Returns
void
y
• get y(): number
Get or set the Y coordinate.
Returns
number
• set y(val): void
Parameters
| Name | Type |
|---|---|
val | number |
Returns
void
z
• get z(): number
Get or set the Z coordinate.
Returns
number
• set z(val): void
Parameters
| Name | Type |
|---|---|
val | number |
Returns
void
Methods
addvec
▸ addvec(vec): McGePoint3d
Calculate the new position of the point after adding the vector
Parameters
| Name | Type | Description |
|---|---|---|
| Vec | [McGeVector3d] (2d. McGeVector3d. md) | Vector |
Returns
Calculated point object
Example
import { McGePoint3d, McGeVector3d } from "mxcad";
const pt1 = new McGePoint3d(20,10,0);
const pt = pt1.clone().addvec(new McGeVector3d(10,10,0))av
▸ av(vec): McGePoint3d
Calculate the new position of the point after adding the vector
Parameters
| Name | Type | Description |
|---|---|---|
| Vec | [McGeVector3d] (2d. McGeVector3d. md) | Vector |
Returns
Calculated point object
c
▸ c(): McGePoint3d
Kerong, a point object
Returns
3D point object
clone
▸ clone(): McGePoint3d
Kerong, a point object
Returns
3D point object
Example
import { McGePoint3d } from "mxcad"
const pt1 = new McGePoint3d(10,10,0);
const pt2 = pt1.clone();copy
▸ copy(val): McGePoint3d
Copy the value of a point object
Parameters
| Name | Type | Description |
|---|---|---|
| Val | [McGePoint3d] (2d. McGePoint3d. md) | Point Object |
Returns
Copy the point object
Example
import { McGePoint3d } from "mxcad"
const point1 = new McGePoint3d(20,10,0);
const point2 = new McGePoint3d();
point2.copy(point1);distanceTo
▸ distanceTo(pnt): number
Calculate the distance between two points
Parameters
| Name | Type | Description |
|---|---|---|
| Pnt | McGePoint3d (2d. McGePoint3d. md) | 3D point object |
Returns
number
Distance between two points
Example
import { McGePoint3d } from "mxcad";
const pt1 = new McGePoint3d(20,10,0);
const pt2 = new McGePoint3d(50,20,0);
const dist = pt1.distanceTo(pt2);isEqualTo
▸ isEqualTo(pnt): boolean
Determine whether two points are equal
Parameters
| Name | Type | Description |
|---|---|---|
| Pnt | McGePoint3d (2d. McGePoint3d. md) | 3D point object |
Returns
boolean
Boolean value
Example
import { McGePoint3d } from "mxcad"
const pt1 = new McGePoint3d(10,20,0);
const pt2 = new McGePoint3d(10,10,0);
const res = pt1.isEqualTo(pt2);
Console. log (res)//Output falsesetFromVector3
▸ setFromVector3(val): McGePoint3d
Set the vector of Three.js to points
Parameters
| Name | Type |
|---|---|
val | Vector3 |
Returns
sub
▸ sub(pt): McGeVector3d
Return a new vector obtained by subtracting two points
Parameters
| Name | Type | Description |
|---|---|---|
| Pt | McGePoint3d (2d. McGePoint3d. md) | 3D point object |
Returns
3D point vector
Example
import { McGePoint3d } from "mxcad";
const pt1 = new McGePoint3d(20,10,0);
const pt2 = new McGePoint3d(50,20,0);
const vec = pt1.sub(pt2);subvec
▸ subvec(vec): McGePoint3d
Calculate the new position of the point after subtracting the vector
Parameters
| Name | Type | Description |
|---|---|---|
| Vec | [McGeVector3d] (2d. McGeVector3d. md) | Vector |
Returns
Calculated point object
Example
import { McGePoint3d, McGeVector3d } from "mxcad";
const pt1 = new McGePoint3d(20,10,0);
const pt = pt1.clone().subvec(new McGeVector3d(10,10,0));sv
▸ sv(vec): McGePoint3d
Calculate the new position of the point after subtracting the vector
Parameters
| Name | Type | Description |
|---|---|---|
| Vec | [McGeVector3d] (2d. McGeVector3d. md) | Vector |
Returns
Calculated point object
toVector3
▸ toVector3(): Vector3
Convert the coordinate information of the current object to THREE Instances of Vector3 class
Returns
Vector3
THREE. Vector3 instance object
transformBy
▸ transformBy(leftSide): McGePoint3d
Transform the point using a matrix
Parameters
| Name | Type | Description |
|---|---|---|
| LeftSide | McGeMatrix3d (2d. McGeMatrix3d. md) | Transformation Matrix |
Returns
The transformed point object
Example
import { McGePoint3d, McGeVector3d, McGeMatrix3d } from "mxcad"
const point = new McGePoint3d(20,10,0);
let matrix = new McGeMatrix3d();
matrix.setToTranslation(new McGeVector3d(10,10,0));// translation
point.transformBy(matrix);