mxcad_2d API 文档 / 2d / McGeVector3d
Class: McGeVector3d
2d.McGeVector3d
表示三维向量的对象。
Example
//求失量与X轴的夹角
const angle1 = vetT.angleTo2(McGeVector3d.McGeVector3d.kXAxis ,McGeVector3d.kNegateZAxis)
//求出vetFx逆时针到vetT的角度
const angle2 = vetFx.angleTo2(vetT, McGeVector3d.kZAxis)
//判断向量vetT在向量VetFX的左边,还是在右边的调用
const angle3 = vetFx.angleTo2(vetT, McGeVector3d.kZAxis);
if(angle >= 0.0 && angle <= PI ){
//向量vetT在vetFX的左边.
} else {
//向量vetT在vetFX的右边.
}
// 或
if (vetFX.dotProduct(vetT.perpVector()) < 0){
// vetFX在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?
)
构造函数。
Parameters
Name | Type | Description |
---|---|---|
dX? | number | object | X 坐标。 |
dY? | number | Y 坐标。 |
dZ? | number | Z 坐标。 |
Example
import { MdGeVector3d } from "mxcad";
const vec = new MdGeVector3d(20,10,0)
Properties
imp
• imp: any
内部实现对象
kNegateZAxis
▪ Static
kNegateZAxis: McGeVector3d
Z轴单位向量, 指向负 Z 轴方向
Example
import { McGeVector3d } from "mxcad"
const zNegate_vec = McGeVector3d.kNegateZAxis;
kXAxis
▪ Static
kXAxis: McGeVector3d
X轴单位向量, 指向正 X 轴方向
Example
import { McGeVector3d } from "mxcad"
const x_vec = McGeVector3d.kXAxis;
kYAxis
▪ Static
kYAxis: McGeVector3d
Y轴单位向量, 指向正 Y 轴方向
Example
import { McGeVector3d } from "mxcad"
const y_vec = McGeVector3d.kYAxis;
kZAxis
▪ Static
kZAxis: McGeVector3d
Z轴单位向量, 指向正 Z 轴方向
Example
import { McGeVector3d } from "mxcad"
const y_vec = McGeVector3d.kZAxis;
Accessors
x
• get
x(): number
获取或设置向量 X 坐标。
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
获取或设置向量 Y 坐标。
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
获取或设置向量 Z 坐标。
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
计算两向量在[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
计算两向量在[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
刻隆一个向量对象
Returns
三维向量对象
clone
▸ clone(): McGeVector3d
刻隆一个向量对象
Returns
三维向量对象
Example
import { McGeVector3d } from "mxcad"
const vec1 = new McGeVector3d(20,10,0);
const vec2 = vec1.clone();
copy
▸ copy(val
): McGeVector3d
复制对象的值
Parameters
Name | Type | Description |
---|---|---|
val | McGeVector3d | 三维向量对象 |
Returns
复制后的三维向量对象
Example
import { McGeVector3d } from "mxcad"
const vec1 = new McGeVector3d(20,10,0);
const vec2 = new McGeVector3d();
vec2.copy(vec1);
crossProduct
▸ crossProduct(vec
): McGeVector3d
两向量的交叉积
Parameters
Name | Type |
---|---|
vec | McGeVector3d |
Returns
三维向量对象
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
两向量的点积
Parameters
Name | Type | Description |
---|---|---|
vec | McGeVector3d | 三维向量对象 |
Returns
number
点积结果
Example
//判断两个向量方向相同还是相反
const db = vec1.dotProduct(vec2);
if(db < 0 ){
//向量返向.
}
// 两个向量点乘如果等于0,表示向量垂直。
// 两个向量点乘如果等于1,表示向量方向完全向同。
// 两个向量点乘如果等于-1,表示向量方向完全反向。
isEqualTo
▸ isEqualTo(vec
): boolean
判断比较两个向量是否相等
Parameters
Name | Type | Description |
---|---|---|
vec | McGeVector3d | 三维向量对象 |
Returns
boolean
布尔值
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
检查当前向量是否为单位长度
Returns
boolean
布尔值
Example
import { McGeVector3d } from "mxcad";
const vec1 = new McGeVector3d(20,10,0);
const res = vec1.isUnitLength();
console.log(res)//输出false
isZeroLength
▸ isZeroLength(): boolean
是否为零向量
Returns
boolean
布尔值
Example
import { McGeVector3d } from "mxcad";
const vec1 = new McGeVector3d(20,10,0);
const res = vec1.isZeroLength();
console.log(res)//输出false
length
▸ length(): number
获取向量长度
Returns
number
向量长度
Example
import { McGeVector3d } from "mxcad";
const vec1 = new McGeVector3d(20,10,0);
const length = vec1.length();
mult
▸ mult(val
): McGeVector3d
向量与某个值相乘,修改向量长度
Parameters
Name | Type | Description |
---|---|---|
val | number | 数字 |
Returns
三维向量对象
Example
import { McGeVector3d } from "mxcad";
const vec1 = new McGeVector3d(20,10,0);
const vec = vec1.clone().normalize().mult(20)
negate
▸ negate(): McGeVector3d
向量取反
Returns
Example
import { McGeVector3d } from "mxcad";
const vec = new McGeVector3d(20,10,0);
vec_neg = vec.clone().negate()
normalize
▸ normalize(): McGeVector3d
向量归一化操作
Returns
三维向量对象
Example
import { McGeVector3d } from "mxcad";
const vec1 = new McGeVector3d(20,10,0);
vec1.normalize();
perpVector
▸ perpVector(): McGeVector3d
垂直向量
Returns
Example
import { McGeVector3d } from "mxcad";
const vec = new McGeVector3d(20,10,0);
vec_perp = vec.clone().perpVector()
rotateBy
▸ rotateBy(ang
, axis?
): McGeVector3d
旋转
Parameters
Name | Type | Description |
---|---|---|
ang | number | 旋转角度。 |
axis? | McGeVector3d | 旋转轴向量 |
Returns
Example
import { McGeVector3d } from "mxcad";
const vec = new McGeVector3d(20,10,0);
vec.rotateBy(Math.PI * 0.5);
toVector3
▸ toVector3(): Vector3
转换为THREE.Vector3
Returns
Vector3
Example
import { McGeVector3d } from "mxcad";
const vec = new McGeVector3d(20,10,0);
const v = vec.toVector3();