Skip to content

[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

ts
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 matrix

Table of contents ​

Constructors ​

Properties ​

Accessors ​

Methods ​

Constructors ​

constructor ​

• new McGePoint3d(dX?, dY?, dZ?)

Constructor.

Parameters ​

NameTypeDescription
dX?Number \object
dY?NumberY coordinate
dZ?NumberZ 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 ​

NameType
valVector3

Returns ​

void


x ​

• get x(): number

Get or set the X coordinate.

Returns ​

number

• set x(val): void

Parameters ​

NameType
valnumber

Returns ​

void


y ​

• get y(): number

Get or set the Y coordinate.

Returns ​

number

• set y(val): void

Parameters ​

NameType
valnumber

Returns ​

void


z ​

• get z(): number

Get or set the Z coordinate.

Returns ​

number

• set z(val): void

Parameters ​

NameType
valnumber

Returns ​

void

Methods ​

addvec ​

▸ addvec(vec): McGePoint3d

Calculate the new position of the point after adding the vector

Parameters ​

NameTypeDescription
Vec[McGeVector3d] (2d. McGeVector3d. md)Vector

Returns ​

McGePoint3d

Calculated point object

Example

ts
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 ​

NameTypeDescription
Vec[McGeVector3d] (2d. McGeVector3d. md)Vector

Returns ​

McGePoint3d

Calculated point object


c ​

▸ c(): McGePoint3d

Kerong, a point object

Returns ​

McGePoint3d

3D point object


clone ​

▸ clone(): McGePoint3d

Kerong, a point object

Returns ​

McGePoint3d

3D point object

Example

ts
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 ​

NameTypeDescription
Val[McGePoint3d] (2d. McGePoint3d. md)Point Object

Returns ​

McGePoint3d

Copy the point object

Example

ts
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 ​

NameTypeDescription
PntMcGePoint3d (2d. McGePoint3d. md)3D point object

Returns ​

number

Distance between two points

Example

ts
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 ​

NameTypeDescription
PntMcGePoint3d (2d. McGePoint3d. md)3D point object

Returns ​

boolean

Boolean value

Example

ts
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 false

setFromVector3 ​

▸ setFromVector3(val): McGePoint3d

Set the vector of Three.js to points

Parameters ​

NameType
valVector3

Returns ​

McGePoint3d


sub ​

▸ sub(pt): McGeVector3d

Return a new vector obtained by subtracting two points

Parameters ​

NameTypeDescription
PtMcGePoint3d (2d. McGePoint3d. md)3D point object

Returns ​

McGeVector3d

3D point vector

Example

ts
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 ​

NameTypeDescription
Vec[McGeVector3d] (2d. McGeVector3d. md)Vector

Returns ​

McGePoint3d

Calculated point object

Example

ts
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 ​

NameTypeDescription
Vec[McGeVector3d] (2d. McGeVector3d. md)Vector

Returns ​

McGePoint3d

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 ​

NameTypeDescription
LeftSideMcGeMatrix3d (2d. McGeMatrix3d. md)Transformation Matrix

Returns ​

McGePoint3d

The transformed point object

Example

ts
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);