Skip to content
On this page

mxcad_2d API 文档 / 2d / McGeVector3d

Class: McGeVector3d

2d.McGeVector3d

表示三维向量的对象。

Example

ts
//求失量与X轴的夹角 
const angle1 = vetT.angleTo2(McGeVector3d.McGeVector3d.kXAxis ,McGeVector3d.kNegateZAxis)
ts
//求出vetFx逆时针到vetT的角度
const angle2 = vetFx.angleTo2(vetT, McGeVector3d.kZAxis)
ts
//判断向量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

Constructors

constructor

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

构造函数。

Example

ts
import { MdGeVector3d } from "mxcad";

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

Parameters

NameTypeDescription
dX?number | objectX 坐标。
dY?numberY 坐标。
dZ?numberZ 坐标。

Properties

imp

imp: any

内部实现对象


kNegateZAxis

Static kNegateZAxis: McGeVector3d

Z轴单位向量, 指向负 Z 轴方向

Example

ts
import { McGeVector3d } from "mxcad"

const zNegate_vec = McGeVector3d.kNegateZAxis;

kXAxis

Static kXAxis: McGeVector3d

X轴单位向量, 指向正 X 轴方向

Example

ts
import { McGeVector3d } from "mxcad"

const x_vec = McGeVector3d.kXAxis;

kYAxis

Static kYAxis: McGeVector3d

Y轴单位向量, 指向正 Y 轴方向

Example

ts
import { McGeVector3d } from "mxcad"

const y_vec = McGeVector3d.kYAxis;

kZAxis

Static kZAxis: McGeVector3d

Z轴单位向量, 指向正 Z 轴方向

Example

ts
import { McGeVector3d } from "mxcad"

const y_vec = McGeVector3d.kZAxis;

Accessors

x

get x(): number

获取或设置向量 X 坐标。

Example

ts
import { McGeVector3d } from "mxcad";

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

Returns

number

set x(val): void

Parameters

NameType
valnumber

Returns

void


y

get y(): number

获取或设置向量 Y 坐标。

Example

ts
import { McGeVector3d } from "mxcad";

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

Returns

number

set y(val): void

Parameters

NameType
valnumber

Returns

void


z

get z(): number

获取或设置向量 Z 坐标。

Example

ts
import { McGeVector3d } from "mxcad";

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

Returns

number

set z(val): void

Parameters

NameType
valnumber

Returns

void

Methods

angleTo1

angleTo1(vec): number

计算两向量在[0, Pi]范围内所夹的角度

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

Parameters

NameType
vecMcGeVector3d

Returns

number


angleTo2

angleTo2(vec, refVec?): number

计算两向量在[0, 2*Pi]范围内所夹的角度

Example

ts
import { McGeVector3d } from "mxcad";

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

Parameters

NameType
vecMcGeVector3d
refVec?McGeVector3d

Returns

number


c

c(): McGeVector3d

刻隆一个向量对象

Returns

McGeVector3d

三维向量对象


clone

clone(): McGeVector3d

刻隆一个向量对象

Example

ts
import { McGeVector3d } from "mxcad"

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

Returns

McGeVector3d

三维向量对象


copy

copy(val): McGeVector3d

复制对象的值

Example

ts
import { McGeVector3d } from "mxcad"

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

Parameters

NameTypeDescription
valMcGeVector3d三维向量对象

Returns

McGeVector3d

复制后的三维向量对象


crossProduct

crossProduct(vec): McGeVector3d

两向量的交叉积

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)

Parameters

NameType
vecMcGeVector3d

Returns

McGeVector3d

三维向量对象


dotProduct

dotProduct(vec): number

两向量的点积

Example

ts
//判断两个向量方向相同还是相反
 const db = vec1.dotProduct(vec2);
 if(db < 0 ){
     //向量返向.
 }
// 两个向量点乘如果等于0,表示向量垂直。
// 两个向量点乘如果等于1,表示向量方向完全向同。
// 两个向量点乘如果等于-1,表示向量方向完全反向。

Parameters

NameTypeDescription
vecMcGeVector3d三维向量对象

Returns

number

点积结果


isEqualTo

isEqualTo(vec): boolean

判断比较两个向量是否相等

Parameters

NameTypeDescription
vecMcGeVector3d三维向量对象

Returns

boolean

布尔值

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

检查当前向量是否为单位长度

Example

ts
import { McGeVector3d } from "mxcad";

const vec1 = new McGeVector3d(20,10,0);
const res = vec1.isUnitLength();
console.log(res)//输出false

Returns

boolean

布尔值


isZeroLength

isZeroLength(): boolean

是否为零向量

Example

ts
import { McGeVector3d } from "mxcad";

const vec1 = new McGeVector3d(20,10,0);
const res = vec1.isZeroLength();
console.log(res)//输出false

Returns

boolean

布尔值


length

length(): number

获取向量长度

Example

ts
import { McGeVector3d } from "mxcad";

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

Returns

number

向量长度


mult

mult(val): McGeVector3d

向量与某个值相乘,修改向量长度

Example

ts
import { McGeVector3d } from "mxcad";

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

Parameters

NameTypeDescription
valnumber数字

Returns

McGeVector3d

三维向量对象


negate

negate(): McGeVector3d

向量取反

Example

ts
import { McGeVector3d } from "mxcad";

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

Returns

McGeVector3d


normalize

normalize(): McGeVector3d

向量归一化操作

Example

ts
import { McGeVector3d } from "mxcad";

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

Returns

McGeVector3d

三维向量对象


perpVector

perpVector(): McGeVector3d

垂直向量

Example

ts
import { McGeVector3d } from "mxcad";

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

Returns

McGeVector3d


rotateBy

rotateBy(ang, axis?): McGeVector3d

旋转

Example

ts
import { McGeVector3d } from "mxcad";

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

Parameters

NameTypeDescription
angnumber旋转角度。
axis?McGeVector3d旋转轴向量

Returns

McGeVector3d


toVector3

toVector3(): Vector3

转换为THREE.Vector3

Example

ts
import { McGeVector3d } from "mxcad";

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

Returns

Vector3