Skip to content
On this page

[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/McGeVector3d

Class: McGeVector3d

2d.McGeVector3d

An object that represents a three-dimensional vector.

Example

ts
//Find the angle between the loss and the X-axis
const angle1 = vetT.angleTo2(McGeVector3d.McGeVector3d.kXAxis ,McGeVector3d.kNegateZAxis)
ts
//Find the angle from vetPx counterclockwise to vetT
const angle2 = vetFx.angleTo2(vetT, McGeVector3d.kZAxis)
ts
//Determine whether vector vetT is on the left or right side of vector VetFX in the call
const angle3 = vetFx.angleTo2(vetT, McGeVector3d.kZAxis);
  if(angle >= 0.0 && angle <= PI ){
//The vector vetT is to the left of vetFX
   } else {
//The vector vetT is to the right of vetFX
   }
//Or
  if (vetFX.dotProduct(vetT.perpVector()) < 0){
//VetFX is on the left side of vetT.
  }

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new McGeVector3d(dX?, dY?, dZ?)

Constructor.

Parameters

NameTypeDescription
dX?Number \object
dY?NumberY coordinate
dZ?NumberZ coordinate

Example

ts
import { MdGeVector3d } from "mxcad";

const vec = new MdGeVector3d(20,10,0)

Properties

imp

imp: any

Internal implementation object


kIdentity

Static kIdentity: McGeVector3d

0 length vector

Example

ts

kNegateZAxis

Static kNegateZAxis: McGeVector3d

Z-axis unit vector, pointing towards the negative Z-axis direction

Example

ts
import { McGeVector3d } from "mxcad"

const zNegate_vec = McGeVector3d.kNegateZAxis;

kXAxis

Static kXAxis: McGeVector3d

X-axis unit vector, pointing towards the positive X-axis direction

Example

ts
import { McGeVector3d } from "mxcad"

const x_vec = McGeVector3d.kXAxis;

kYAxis

Static kYAxis: McGeVector3d

Y-axis unit vector, pointing towards the positive Y-axis direction

Example

ts
import { McGeVector3d } from "mxcad"

const y_vec = McGeVector3d.kYAxis;

kZAxis

Static kZAxis: McGeVector3d

Z-axis unit vector, pointing towards the positive Z-axis direction

Example

ts
import { McGeVector3d } from "mxcad"

const y_vec = McGeVector3d.kZAxis;

Accessors

x

get x(): number

Get or set the X coordinate of the vector.

Returns

number

Example

ts
import { McGeVector3d } from "mxcad";

const vec1 = new McGeVector3d();
vec1.x = 10;

set x(val): void

Parameters

NameType
valnumber

Returns

void


y

get y(): number

Get or set the Y coordinate of the vector.

Returns

number

Example

ts
import { McGeVector3d } from "mxcad";

const vec1 = new McGeVector3d();
vec1.y = 10;

set y(val): void

Parameters

NameType
valnumber

Returns

void


z

get z(): number

Get or set the Z-coordinate of the vector.

Returns

number

Example

ts
import { McGeVector3d } from "mxcad";

const vec1 = new McGeVector3d();
vec1.z = 0;

set z(val): void

Parameters

NameType
valnumber

Returns

void

Methods

angleTo1

angleTo1(vec): number

Calculate the angle between two vectors within the range of [0, Pi]

Parameters

NameType
vecMcGeVector3d

Returns

number

Example

ts
import { McGeVector3d } from "mxcad";

const vec1 = new McGeVector3d(20,10,0);
const vec2 = new McGeVector3d(50,0,0);
const angle = vec1.angleTo1(vec2);

angleTo2

angleTo2(vec, refVec?): number

Calculate the angle between two vectors within the range of [0,2 * Pi]

Parameters

NameType
vecMcGeVector3d
refVec?McGeVector3d

Returns

number

Example

ts
import { McGeVector3d } from "mxcad";

const vec1 = new McGeVector3d(20,10,0);
const angle = vec1.angleTo2(McGeVector3d.kXAxis, McGeVector3d.kNegateZAxis);

c

c(): McGeVector3d

Kelon, a vector object

Returns

McGeVector3d

3D vector object


clone

clone(): McGeVector3d

Kelon, a vector object

Returns

McGeVector3d

3D vector object

Example

ts
import { McGeVector3d } from "mxcad"

const vec1 = new McGeVector3d(20,10,0);
const vec2 = vec1.clone();

copy

copy(val): McGeVector3d

Copy the value of the object

Parameters

NameTypeDescription
Val[McGeVector3d] (2d. McGeVector3d. md)3D Vector Object

Returns

McGeVector3d

Copy the 3D vector object

Example

ts
import { McGeVector3d } from "mxcad"

const vec1 = new McGeVector3d(20,10,0);
const vec2 = new McGeVector3d();
vec2.copy(vec1);

crossProduct

crossProduct(vec): McGeVector3d

The cross product of two vectors

Parameters

NameType
vecMcGeVector3d

Returns

McGeVector3d

3D vector object

Example

ts
import { McGeVector3d } from "mxcad";

const vec1 = new McGeVector3d(20,10,0);
const vec2 = new McGeVector3d(10,10,0);
const vec = vec2.crossProduct(vec1)

dotProduct

dotProduct(vec): number

Dot product of two vectors

Parameters

NameTypeDescription
Vec[McGeVector3d] (2d. McGeVector3d. md)3D vector object

Returns

number

Dot product result

Example

ts
//Determine whether two vectors have the same or opposite direction
 const db = vec1.dotProduct(vec2);
 if(db < 0 ){
//Vector reversal
 }
//If the dot product of two vectors is equal to 0, it means that the vectors are perpendicular.
//If the dot product of two vectors is equal to 1, it means that the vector directions are completely in the same direction.
//If the dot product of two vectors is equal to -1, it means that the direction of the vectors is completely opposite.

isEqualTo

isEqualTo(vec): boolean

Determine whether comparing two vectors is equal

Parameters

NameTypeDescription
Vec[McGeVector3d] (2d. McGeVector3d. md)3D vector object

Returns

boolean

Boolean value

ts
import { McGeVector3d } from "mxcad";

const vec1 = new McGeVector3d(20,10,0);
const vec2 = new McGeVector3d(10,10,0);
const res = vec1.isEqualTo(vec2)

isUnitLength

isUnitLength(): boolean

Check if the current vector is of unit length

Returns

boolean

Boolean value

Example

ts
import { McGeVector3d } from "mxcad";

const vec1 = new McGeVector3d(20,10,0);
const res = vec1.isUnitLength();
Console. log (res)//Output false

isZeroLength

isZeroLength(): boolean

Is it a zero vector

Returns

boolean

Boolean value

Example

ts
import { McGeVector3d } from "mxcad";

const vec1 = new McGeVector3d(20,10,0);
const res = vec1.isZeroLength();
Console. log (res)//Output false

length

length(): number

Obtain vector length

Returns

number

Vector length

Example

ts
import { McGeVector3d } from "mxcad";

const vec1 = new McGeVector3d(20,10,0);
const length = vec1.length();

mult

mult(val): McGeVector3d

Multiply a vector with a certain value, modify the length of the vector

Parameters

NameTypeDescription
ValnumberNumber

Returns

McGeVector3d

3D vector object

Example

ts
import { McGeVector3d } from "mxcad";

const vec1 = new McGeVector3d(20,10,0);
const vec = vec1.clone().normalize().mult(20)

negate

negate(): McGeVector3d

Vector inversion

Returns

McGeVector3d

Example

ts
import { McGeVector3d } from "mxcad";

const vec = new McGeVector3d(20,10,0);
vec_neg = vec.clone().negate()

normalize

normalize(): McGeVector3d

Vector normalization operation

Returns

McGeVector3d

3D vector object

Example

ts
import { McGeVector3d } from "mxcad";

const vec1 = new McGeVector3d(20,10,0);
vec1.normalize();

perpVector

perpVector(): McGeVector3d

Vertical vector

Returns

McGeVector3d

Example

ts
import { McGeVector3d } from "mxcad";

const vec = new McGeVector3d(20,10,0);
vec_perp = vec.clone().perpVector()

rotateBy

rotateBy(ang, axis?): McGeVector3d

rotate

Parameters

NameTypeDescription
'ang''number'Rotation angle
axis?[McGeVector3d] (2d. McGeVector3d. md)Rotation axis vector

Returns

McGeVector3d

Example

ts
import { McGeVector3d } from "mxcad";

const vec = new McGeVector3d(20,10,0);
vec.rotateBy(Math.PI * 0.5);

toVector3

toVector3(): Vector3

Convert to THREE Vector3

Returns

Vector3

Example

ts
import { McGeVector3d } from "mxcad";

const vec = new McGeVector3d(20,10,0);
const v = vec.toVector3();