[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/McGeVector3d
Class: McGeVector3d
2d.McGeVector3d
An object that represents a three-dimensional vector.
Example
//Find the angle between the loss and the X-axis
const angle1 = vetT.angleTo2(McGeVector3d.McGeVector3d.kXAxis ,McGeVector3d.kNegateZAxis)//Find the angle from vetPx counterclockwise to vetT
const angle2 = vetFx.angleTo2(vetT, McGeVector3d.kZAxis)//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
- angleTo1
- angleTo2
- c
- clone
- copy
- crossProduct
- dotProduct
- isEqualTo
- isUnitLength
- isZeroLength
- length
- mult
- negate
- normalize
- perpVector
- rotateBy
- toVector3
Constructors
constructor
• new McGeVector3d(dX?, dY?, dZ?)
Constructor.
Parameters
| Name | Type | Description |
|---|---|---|
| DX? | number \ | object |
| DY? | number | Y coordinate. |
| DZ? | number | Z coordinate. |
Example
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
kNegateZAxis
▪ Static kNegateZAxis: McGeVector3d
Z-axis unit vector, pointing towards the negative Z-axis direction
Example
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
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
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
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
import { McGeVector3d } from "mxcad";
const vec1 = new McGeVector3d();
vec1.x = 10;• set x(val): void
Parameters
| Name | Type |
|---|---|
val | number |
Returns
void
y
• get y(): number
Get or set the Y coordinate of the vector.
Returns
number
Example
import { McGeVector3d } from "mxcad";
const vec1 = new McGeVector3d();
vec1.y = 10;• set y(val): void
Parameters
| Name | Type |
|---|---|
val | number |
Returns
void
z
• get z(): number
Get or set the Z-coordinate of the vector.
Returns
number
Example
import { McGeVector3d } from "mxcad";
const vec1 = new McGeVector3d();
vec1.z = 0;• set z(val): void
Parameters
| Name | Type |
|---|---|
val | number |
Returns
void
Methods
angleTo1
▸ angleTo1(vec): number
Calculate the angle between two vectors within the range of [0, Pi]
Parameters
| Name | Type |
|---|---|
vec | McGeVector3d |
Returns
number
Example
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
| Name | Type |
|---|---|
vec | McGeVector3d |
refVec? | McGeVector3d |
Returns
number
Example
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
3D vector object
clone
▸ clone(): McGeVector3d
Kelon, a vector object
Returns
3D vector object
Example
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
| Name | Type | Description |
|---|---|---|
| Val | [McGeVector3d] (2d. McGeVector3d. md) | 3D Vector Object |
Returns
Copy the 3D vector object
Example
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
| Name | Type |
|---|---|
vec | McGeVector3d |
Returns
3D vector object
Example
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
| Name | Type | Description |
|---|---|---|
| Vec | [McGeVector3d] (2d. McGeVector3d. md) | 3D vector object |
Returns
number
Dot product result
Example
//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
| Name | Type | Description |
|---|---|---|
| Vec | [McGeVector3d] (2d. McGeVector3d. md) | 3D vector object |
Returns
boolean
Boolean value
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
import { McGeVector3d } from "mxcad";
const vec1 = new McGeVector3d(20,10,0);
const res = vec1.isUnitLength();
Console. log (res)//Output falseisZeroLength
▸ isZeroLength(): boolean
Is it a zero vector
Returns
boolean
Boolean value
Example
import { McGeVector3d } from "mxcad";
const vec1 = new McGeVector3d(20,10,0);
const res = vec1.isZeroLength();
Console. log (res)//Output falselength
▸ length(): number
Obtain vector length
Returns
number
vector length
Example
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
| Name | Type | Description |
|---|---|---|
| Val | number | Number |
Returns
3D vector object
Example
import { McGeVector3d } from "mxcad";
const vec1 = new McGeVector3d(20,10,0);
const vec = vec1.clone().normalize().mult(20)negate
▸ negate(): McGeVector3d
Vector inversion
Returns
Example
import { McGeVector3d } from "mxcad";
const vec = new McGeVector3d(20,10,0);
vec_neg = vec.clone().negate()normalize
▸ normalize(): McGeVector3d
Vector normalization operation
Returns
3D vector object
Example
import { McGeVector3d } from "mxcad";
const vec1 = new McGeVector3d(20,10,0);
vec1.normalize();perpVector
▸ perpVector(): McGeVector3d
Vertical vector
Returns
Example
import { McGeVector3d } from "mxcad";
const vec = new McGeVector3d(20,10,0);
vec_perp = vec.clone().perpVector()rotateBy
▸ rotateBy(ang, axis?): McGeVector3d
rotate
Parameters
| Name | Type | Description |
|---|---|---|
| 'ang' | 'number' | Rotation angle. |
axis? | [McGeVector3d] (2d. McGeVector3d. md) | Rotation axis vector |
Returns
Example
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
import { McGeVector3d } from "mxcad";
const vec = new McGeVector3d(20,10,0);
const v = vec.toVector3();