@xort/cga 0.0.91 → 0.0.93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/@xort_cga.js +1281 -3480
- package/build/cga.d.ts +33 -8
- package/dist/math/Vec3.d.ts +12 -0
- package/dist/math/Vec3.js +12 -0
- package/dist/struct/3d/Circle.d.ts +10 -1
- package/dist/struct/3d/Circle.js +32 -2
- package/dist/struct/bsp.d.ts +9 -0
- package/dist/struct/bsp.js +43 -0
- package/gitproxy.sh +6 -0
- package/package.json +1 -1
- package/rollup.config.js +24 -21
- package/src/alg/extrude.ts +1 -1
- package/src/math/Vec3.ts +43 -31
- package/src/struct/3d/Circle.ts +46 -4
- package/src/struct/bsp.ts +18 -0
package/src/struct/3d/Circle.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Vec3, v3 } from '../../math/Vec3';
|
|
2
2
|
import { angle, pointsCollinear, rotate } from '../../alg/common';
|
|
3
3
|
import { Line } from './Line';
|
|
4
|
+
import { quat } from 'src/math/Quat';
|
|
4
5
|
|
|
5
6
|
export class Circle {
|
|
6
7
|
startAngle: number = 0;
|
|
@@ -81,13 +82,12 @@ export class Circle {
|
|
|
81
82
|
* @param lengthAngle 弧度长度 单位弧度
|
|
82
83
|
* @param segment 分段
|
|
83
84
|
*/
|
|
84
|
-
static
|
|
85
|
+
static toVecs(center: Vec3, radius: number, startAngle: number = 0, lengthAngle: number = Math.PI * 2, up: Vec3 = Vec3.UnitY, segment: number = 16) {
|
|
85
86
|
const Xvec: Vec3 = Vec3.UnitX;
|
|
86
87
|
Xvec.multiplyScalar(radius);
|
|
87
|
-
|
|
88
|
-
const result:Vec3[]=[]
|
|
89
88
|
|
|
90
|
-
const
|
|
89
|
+
const result: Vec3[] = []
|
|
90
|
+
|
|
91
91
|
const perAngle = lengthAngle / segment;
|
|
92
92
|
for (let i = 0; i <= segment; i++) {
|
|
93
93
|
const langlei = perAngle * i + startAngle;
|
|
@@ -100,6 +100,48 @@ export class Circle {
|
|
|
100
100
|
return result;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 在p点延伸a,b两个方向,生成半径为r的圆弧,圆弧所在位置在a,b向量的内夹角
|
|
106
|
+
* @param p 位置
|
|
107
|
+
* @param a a方向
|
|
108
|
+
* @param b b方向
|
|
109
|
+
* @param r 圆弧半径
|
|
110
|
+
*/
|
|
111
|
+
static PAdBdtoVecs(p: Vec3, a: Vec3, b: Vec3, r: number, segment: number = 3) {
|
|
112
|
+
|
|
113
|
+
const angle = a.angleTo(b)
|
|
114
|
+
const d = r / Math.tan(angle / 2);
|
|
115
|
+
|
|
116
|
+
const cr = r / Math.sin(angle / 2);
|
|
117
|
+
const c = a.clone().add(b).normalize().multiplyScalar(cr).add(p)
|
|
118
|
+
|
|
119
|
+
const cd1 = a.clone().multiplyScalar(d).add(p).sub(c).normalize();
|
|
120
|
+
const cd2 = b.clone().multiplyScalar(d).add(p).sub(c).normalize();
|
|
121
|
+
|
|
122
|
+
const up = cd1.clone().cross(cd2).normalize();
|
|
123
|
+
|
|
124
|
+
const q = quat().setFromUnitVecs(up, Vec3.UnitY); //两个向量形成一个旋转4元数
|
|
125
|
+
|
|
126
|
+
cd1.applyQuat(q);
|
|
127
|
+
cd2.applyQuat(q);
|
|
128
|
+
|
|
129
|
+
const startAngle = Vec3.UnitX.angleToEx(cd1, Vec3.UnitY);
|
|
130
|
+
const lengthAngle = Vec3.UnitX.angleToEx(cd2, Vec3.UnitY) - startAngle;
|
|
131
|
+
|
|
132
|
+
return this.toVecs(c, r, startAngle, lengthAngle, up, segment);
|
|
133
|
+
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
static PApBptoVecs(p: Vec3, a: Vec3, b: Vec3, r: number, segment: number = 3) {
|
|
137
|
+
|
|
138
|
+
const pa = a.clone().sub(p).normalize();
|
|
139
|
+
const pb = b.clone().sub(p).normalize();
|
|
140
|
+
|
|
141
|
+
return Circle.PAdBdtoVecs(p, pa, pb, r, segment);
|
|
142
|
+
|
|
143
|
+
}
|
|
144
|
+
|
|
103
145
|
}
|
|
104
146
|
|
|
105
147
|
export function circle(center?: Vec3, radius?: number) {
|
package/src/struct/bsp.ts
CHANGED