@xort/cga 0.0.90 → 0.0.92

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.
@@ -131,7 +131,19 @@ export declare class Vec3 implements IVec3 {
131
131
  */
132
132
  projectDirectionOnPlane(plane: Plane, dir: Vec3): this;
133
133
  reflect(normal: any): this;
134
+ /**
135
+ * 两个向量的夹角
136
+ * @param v
137
+ * @param normal
138
+ * @returns
139
+ */
134
140
  angleTo(v: Vec3, normal?: Vec3 | any): number;
141
+ /**
142
+ * 一个向量到另一个向量的角度
143
+ * @param v
144
+ * @param normal
145
+ * @returns
146
+ */
135
147
  angleToEx(v: Vec3, normal: Vec3): number;
136
148
  distanceTo(v: any): number;
137
149
  distanceToSquared(v: Vec3): number;
package/dist/math/Vec3.js CHANGED
@@ -527,12 +527,24 @@ var Vec3 = /** @class */ (function () {
527
527
  // normal is assumed to have unit length
528
528
  return this.sub(_vec.copy(normal).multiplyScalar(2 * this.dot(normal)));
529
529
  };
530
+ /**
531
+ * 两个向量的夹角
532
+ * @param v
533
+ * @param normal
534
+ * @returns
535
+ */
530
536
  Vec3.prototype.angleTo = function (v, normal) {
531
537
  if (normal)
532
538
  return this.angleToEx(v, normal);
533
539
  var theta = this.dot(v) / Math.sqrt(this.lengthSq() * v.lengthSq());
534
540
  return Math.acos((0, Math_1.clamp)(theta, -1, 1));
535
541
  };
542
+ /**
543
+ * 一个向量到另一个向量的角度
544
+ * @param v
545
+ * @param normal
546
+ * @returns
547
+ */
536
548
  Vec3.prototype.angleToEx = function (v, normal) {
537
549
  var theta = this.dot(v) / Math.sqrt(this.lengthSq() * v.lengthSq());
538
550
  if (this.clone().cross(v).dot(normal) > 0)
package/dist/math/vecs.js CHANGED
@@ -336,44 +336,52 @@ var vecs = /** @class */ (function () {
336
336
  * @returns {Array<Number>} 数字数组
337
337
  */
338
338
  vecs.verctorToNumbers = function (vectors, comSort) {
339
- if (comSort === void 0) { comSort = "xyz"; }
340
339
  if (!(vectors instanceof Array)) {
341
340
  console.error("传入参数必须是数组");
342
341
  return [];
343
342
  }
344
343
  var numbers = [];
345
- if (vectors[0].x !== undefined && vectors[0].y !== undefined && vectors[0].z !== undefined && vectors[0].w !== undefined) {
346
- comSort = comSort.length !== 4 ? 'xyzw' : comSort;
347
- for (var i = 0; i < vectors.length; i++) {
348
- for (var j = 0; j < comSort.length; j++) {
349
- numbers.push(vectors[i][comSort[j]]);
344
+ if (!comSort) {
345
+ if (vectors[0].x !== undefined && vectors[0].y !== undefined && vectors[0].z !== undefined && vectors[0].w !== undefined) {
346
+ comSort = !comSort ? 'xyzw' : comSort;
347
+ for (var i = 0; i < vectors.length; i++) {
348
+ for (var j = 0; j < comSort.length; j++) {
349
+ numbers.push(vectors[i][comSort[j]]);
350
+ }
350
351
  }
351
352
  }
352
- }
353
- if (vectors[0].x !== undefined && vectors[0].y !== undefined && vectors[0].z !== undefined) {
354
- comSort = comSort.length !== 3 ? 'xyz' : comSort;
355
- for (var i = 0; i < vectors.length; i++) {
356
- for (var j = 0; j < comSort.length; j++) {
357
- numbers.push(vectors[i][comSort[j]]);
353
+ if (vectors[0].x !== undefined && vectors[0].y !== undefined && vectors[0].z !== undefined) {
354
+ comSort = !comSort ? 'xyz' : comSort;
355
+ for (var i = 0; i < vectors.length; i++) {
356
+ for (var j = 0; j < comSort.length; j++) {
357
+ numbers.push(vectors[i][comSort[j]]);
358
+ }
359
+ }
360
+ }
361
+ else if (vectors[0].x !== undefined && vectors[0].y !== undefined) {
362
+ comSort = !comSort ? 'xy' : comSort;
363
+ for (var i = 0; i < vectors.length; i++) {
364
+ for (var j = 0; j < comSort.length; j++) {
365
+ numbers.push(vectors[i][comSort[j]]);
366
+ }
358
367
  }
359
368
  }
369
+ else if (vectors[0] instanceof Array) {
370
+ for (var i = 0; i < vectors.length; i++) {
371
+ numbers = numbers.concat(vecs.verctorToNumbers(vectors[i]));
372
+ }
373
+ }
374
+ else {
375
+ console.error("数组内部的元素不是向量");
376
+ }
360
377
  }
361
- else if (vectors[0].x !== undefined && vectors[0].y !== undefined) {
362
- comSort = comSort.length !== 2 ? 'xy' : comSort;
378
+ else {
363
379
  for (var i = 0; i < vectors.length; i++) {
364
380
  for (var j = 0; j < comSort.length; j++) {
365
381
  numbers.push(vectors[i][comSort[j]]);
366
382
  }
367
383
  }
368
384
  }
369
- else if (vectors[0] instanceof Array) {
370
- for (var i = 0; i < vectors.length; i++) {
371
- numbers = numbers.concat(vecs.verctorToNumbers(vectors[i]));
372
- }
373
- }
374
- else {
375
- console.error("数组内部的元素不是向量");
376
- }
377
385
  return numbers;
378
386
  };
379
387
  vecs.vec = function (component) {
@@ -38,6 +38,15 @@ export declare class Circle {
38
38
  * @param lengthAngle 弧度长度 单位弧度
39
39
  * @param segment 分段
40
40
  */
41
- static toVertices(center: Vec3, radius: number, startAngle?: number, lengthAngle?: number, segment?: number): Vec3[];
41
+ static toVecs(center: Vec3, radius: number, startAngle?: number, lengthAngle?: number, up?: Vec3, segment?: number): Vec3[];
42
+ /**
43
+ * 在p点延伸a,b两个方向,生成半径为r的圆弧,圆弧所在位置在a,b向量的内夹角
44
+ * @param p 位置
45
+ * @param a a方向
46
+ * @param b b方向
47
+ * @param r 圆弧半径
48
+ */
49
+ static PAdBdtoVecs(p: Vec3, a: Vec3, b: Vec3, r: number, segment?: number): Vec3[];
50
+ static PApBptoVecs(p: Vec3, a: Vec3, b: Vec3, r: number, segment?: number): Vec3[];
42
51
  }
43
52
  export declare function circle(center?: Vec3, radius?: number): Circle;
@@ -4,6 +4,7 @@ exports.circle = exports.Circle = void 0;
4
4
  var Vec3_1 = require("../../math/Vec3");
5
5
  var common_1 = require("../../alg/common");
6
6
  var Line_1 = require("./Line");
7
+ var Quat_1 = require("src/math/Quat");
7
8
  var Circle = /** @class */ (function () {
8
9
  /**
9
10
  * 圆圈
@@ -83,14 +84,14 @@ var Circle = /** @class */ (function () {
83
84
  * @param lengthAngle 弧度长度 单位弧度
84
85
  * @param segment 分段
85
86
  */
86
- Circle.toVertices = function (center, radius, startAngle, lengthAngle, segment) {
87
+ Circle.toVecs = function (center, radius, startAngle, lengthAngle, up, segment) {
87
88
  if (startAngle === void 0) { startAngle = 0; }
88
89
  if (lengthAngle === void 0) { lengthAngle = Math.PI * 2; }
90
+ if (up === void 0) { up = Vec3_1.Vec3.UnitY; }
89
91
  if (segment === void 0) { segment = 16; }
90
92
  var Xvec = Vec3_1.Vec3.UnitX;
91
93
  Xvec.multiplyScalar(radius);
92
94
  var result = [];
93
- var up = Vec3_1.Vec3.UnitY;
94
95
  var perAngle = lengthAngle / segment;
95
96
  for (var i = 0; i <= segment; i++) {
96
97
  var langlei = perAngle * i + startAngle;
@@ -99,6 +100,35 @@ var Circle = /** @class */ (function () {
99
100
  }
100
101
  return result;
101
102
  };
103
+ /**
104
+ * 在p点延伸a,b两个方向,生成半径为r的圆弧,圆弧所在位置在a,b向量的内夹角
105
+ * @param p 位置
106
+ * @param a a方向
107
+ * @param b b方向
108
+ * @param r 圆弧半径
109
+ */
110
+ Circle.PAdBdtoVecs = function (p, a, b, r, segment) {
111
+ if (segment === void 0) { segment = 3; }
112
+ var angle = a.angleTo(b);
113
+ var d = r / Math.tan(angle / 2);
114
+ var cr = r / Math.sin(angle / 2);
115
+ var c = a.clone().add(b).normalize().multiplyScalar(cr).add(p);
116
+ var cd1 = a.clone().multiplyScalar(d).add(p).sub(c).normalize();
117
+ var cd2 = a.clone().multiplyScalar(d).add(p).sub(c).normalize();
118
+ var up = cd1.clone().cross(cd2).normalize();
119
+ var q = (0, Quat_1.quat)().setFromUnitVecs(up, Vec3_1.Vec3.UnitY); //两个向量形成一个旋转4元数
120
+ cd1.applyQuat(q);
121
+ cd2.applyQuat(q);
122
+ var startAngle = Vec3_1.Vec3.UnitX.angleToEx(cd1, Vec3_1.Vec3.UnitY);
123
+ var lengthAngle = Vec3_1.Vec3.UnitX.angleToEx(cd2, Vec3_1.Vec3.UnitY) - startAngle;
124
+ return this.toVecs(c, r, startAngle, lengthAngle, up, segment);
125
+ };
126
+ Circle.PApBptoVecs = function (p, a, b, r, segment) {
127
+ if (segment === void 0) { segment = 3; }
128
+ var pa = a.clone().sub(p).normalize();
129
+ var pb = b.clone().sub(p).normalize();
130
+ return Circle.PAdBdtoVecs(p, pa, pb, r, segment);
131
+ };
102
132
  return Circle;
103
133
  }());
104
134
  exports.Circle = Circle;
@@ -0,0 +1,9 @@
1
+ import { Tree } from "./tree";
2
+ /**
3
+ *
4
+ */
5
+ export declare class BSP extends Tree {
6
+ constructor();
7
+ get pos(): this;
8
+ get neg(): this;
9
+ }
@@ -1 +1,44 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.BSP = void 0;
19
+ var tree_1 = require("./tree");
20
+ /**
21
+ *
22
+ */
23
+ var BSP = /** @class */ (function (_super) {
24
+ __extends(BSP, _super);
25
+ function BSP() {
26
+ return _super.call(this, 2) || this;
27
+ }
28
+ Object.defineProperty(BSP.prototype, "pos", {
29
+ get: function () {
30
+ return this.children[0];
31
+ },
32
+ enumerable: false,
33
+ configurable: true
34
+ });
35
+ Object.defineProperty(BSP.prototype, "neg", {
36
+ get: function () {
37
+ return this.children[1];
38
+ },
39
+ enumerable: false,
40
+ configurable: true
41
+ });
42
+ return BSP;
43
+ }(tree_1.Tree));
44
+ exports.BSP = BSP;
package/gitproxy.sh ADDED
@@ -0,0 +1,6 @@
1
+ git config --global http.proxy 'socks5://127.0.0.1:5006'
2
+ git config --global https.proxy 'socks5://127.0.0.1:5006'
3
+
4
+
5
+ # git config --global --unset http.proxy
6
+ # git config --global --unset https.proxy
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xort/cga",
3
- "version": "0.0.90",
3
+ "version": "0.0.92",
4
4
  "description": "Xtor Compute Geometry Algorithm Libary 计算几何算法库",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -243,7 +243,7 @@ export function linkSides(options: ILinkSideOptions): IGeometry {
243
243
  index.index += endShape.length
244
244
  if (holess && holess[0])
245
245
  endHoles.forEach((h: any) => {
246
- index.index += h.length
246
+ index.index += h.length;
247
247
  })
248
248
  }
249
249
  triangles.push(...endTris);
package/src/math/Vec3.ts CHANGED
@@ -7,7 +7,7 @@ import { DistanceResult } from '../alg/result';
7
7
  import { Line, line } from '../struct/3d/Line';
8
8
  import { Ray } from '../struct/3d/Ray';
9
9
  import { Segment } from '../struct/3d/Segment';
10
- import { Plane } from '../struct/3d/Plane';
10
+ import { Plane } from '../struct/3d/Plane';
11
11
  import { Triangle } from '../struct/3d/Triangle';
12
12
  import { Capsule } from '../struct/3d/Capsule';
13
13
  import { Rectangle } from '../struct/3d/Rectangle';
@@ -27,10 +27,10 @@ export interface IVec4 extends IVec3 {
27
27
  w: number;
28
28
  }
29
29
 
30
- export class Vec3 implements IVec3 {
30
+ export class Vec3 implements IVec3 {
31
31
 
32
32
  constructor(private _x: number = 0, private _y: number = 0, private _z: number = 0) {
33
-
33
+
34
34
  }
35
35
 
36
36
  get x() {
@@ -98,7 +98,7 @@ export class Vec3 implements IVec3 {
98
98
  this._x = x;
99
99
  this._y = y;
100
100
  this._z = z;
101
- //// this.fire('change');
101
+ //// this.fire('change');
102
102
  return this;
103
103
  }
104
104
 
@@ -107,7 +107,7 @@ export class Vec3 implements IVec3 {
107
107
  this._y = scalar;
108
108
  this._z = scalar;
109
109
 
110
- // this.fire('change');
110
+ // this.fire('change');
111
111
  return this;
112
112
  }
113
113
 
@@ -151,7 +151,7 @@ export class Vec3 implements IVec3 {
151
151
  this._y = v.y;
152
152
  this._z = v.z;
153
153
 
154
- // this.fire('change');
154
+ // this.fire('change');
155
155
  return this;
156
156
  }
157
157
 
@@ -167,7 +167,7 @@ export class Vec3 implements IVec3 {
167
167
  this._y += v.y;
168
168
  this._z += v.z;
169
169
 
170
- // this.fire('change');
170
+ // this.fire('change');
171
171
  return this;
172
172
  }
173
173
 
@@ -176,7 +176,7 @@ export class Vec3 implements IVec3 {
176
176
  this._y += s;
177
177
  this._z += s;
178
178
 
179
- // this.fire('change');
179
+ // this.fire('change');
180
180
  return this;
181
181
  }
182
182
 
@@ -185,7 +185,7 @@ export class Vec3 implements IVec3 {
185
185
  this._y = a.y + b.y;
186
186
  this._z = a.z + b.z;
187
187
 
188
- // this.fire('change');
188
+ // this.fire('change');
189
189
  return this;
190
190
  }
191
191
 
@@ -194,7 +194,7 @@ export class Vec3 implements IVec3 {
194
194
  this._y += v.y * s;
195
195
  this._z += v.z * s;
196
196
 
197
- // this.fire('change');
197
+ // this.fire('change');
198
198
  return this;
199
199
  }
200
200
 
@@ -210,7 +210,7 @@ export class Vec3 implements IVec3 {
210
210
  this._y -= v.y;
211
211
  this._z -= v.z;
212
212
 
213
- // this.fire('change');
213
+ // this.fire('change');
214
214
  return this;
215
215
  }
216
216
 
@@ -219,7 +219,7 @@ export class Vec3 implements IVec3 {
219
219
  this._y -= s;
220
220
  this._z -= s;
221
221
 
222
- // this.fire('change');
222
+ // this.fire('change');
223
223
  return this;
224
224
  }
225
225
 
@@ -228,7 +228,7 @@ export class Vec3 implements IVec3 {
228
228
  this._y = a.y - b.y;
229
229
  this._z = a.z - b.z;
230
230
 
231
- // this.fire('change');
231
+ // this.fire('change');
232
232
  return this;
233
233
  }
234
234
 
@@ -241,7 +241,7 @@ export class Vec3 implements IVec3 {
241
241
  this._y *= v.y;
242
242
  this._z *= v.z;
243
243
 
244
- // this.fire('change');
244
+ // this.fire('change');
245
245
  return this;
246
246
  }
247
247
 
@@ -250,7 +250,7 @@ export class Vec3 implements IVec3 {
250
250
  this._y *= scalar;
251
251
  this._z *= scalar;
252
252
 
253
- // this.fire('change');
253
+ // this.fire('change');
254
254
  return this;
255
255
  }
256
256
 
@@ -259,7 +259,7 @@ export class Vec3 implements IVec3 {
259
259
  this._y = a.y * b.y;
260
260
  this._z = a.z * b.z;
261
261
 
262
- // this.fire('change');
262
+ // this.fire('change');
263
263
  return this;
264
264
  }
265
265
 
@@ -291,7 +291,7 @@ export class Vec3 implements IVec3 {
291
291
  this._y = e[1] * x + e[4] * y + e[7] * z;
292
292
  this._z = e[2] * x + e[5] * y + e[8] * z;
293
293
 
294
- // this.fire('change');
294
+ // this.fire('change');
295
295
  return this;
296
296
  }
297
297
 
@@ -307,7 +307,7 @@ export class Vec3 implements IVec3 {
307
307
  this._y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
308
308
  this._z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
309
309
 
310
- // this.fire('change');
310
+ // this.fire('change');
311
311
  return this;
312
312
  }
313
313
 
@@ -333,7 +333,7 @@ export class Vec3 implements IVec3 {
333
333
  this._y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
334
334
  this._z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
335
335
 
336
- // this.fire('change');
336
+ // this.fire('change');
337
337
  return this;
338
338
  }
339
339
 
@@ -362,7 +362,7 @@ export class Vec3 implements IVec3 {
362
362
  this._y = e[1] * x + e[5] * y + e[9] * z;
363
363
  this._z = e[2] * x + e[6] * y + e[10] * z;
364
364
 
365
- // this.fire('change');
365
+ // this.fire('change');
366
366
  return this.normalize();
367
367
  }
368
368
 
@@ -371,7 +371,7 @@ export class Vec3 implements IVec3 {
371
371
  this._y /= v.y;
372
372
  this._z /= v.z;
373
373
 
374
- // this.fire('change');
374
+ // this.fire('change');
375
375
  return this;
376
376
  }
377
377
 
@@ -384,7 +384,7 @@ export class Vec3 implements IVec3 {
384
384
  this._y = Math.min(this._y, v.y);
385
385
  this._z = Math.min(this._z, v.z);
386
386
 
387
- // this.fire('change');
387
+ // this.fire('change');
388
388
  return this;
389
389
  }
390
390
 
@@ -393,7 +393,7 @@ export class Vec3 implements IVec3 {
393
393
  this._y = Math.max(this._y, v.y);
394
394
  this._z = Math.max(this._z, v.z);
395
395
 
396
- // this.fire('change');
396
+ // this.fire('change');
397
397
  return this;
398
398
  }
399
399
 
@@ -404,7 +404,7 @@ export class Vec3 implements IVec3 {
404
404
  this._y = Math.max(min.y, Math.min(max.y, this._y));
405
405
  this._z = Math.max(min.z, Math.min(max.z, this._z));
406
406
 
407
- // this.fire('change');
407
+ // this.fire('change');
408
408
  return this;
409
409
  }
410
410
 
@@ -413,7 +413,7 @@ export class Vec3 implements IVec3 {
413
413
  this._y = Math.max(minVal, Math.min(maxVal, this._y));
414
414
  this._z = Math.max(minVal, Math.min(maxVal, this._z));
415
415
 
416
- // this.fire('change');
416
+ // this.fire('change');
417
417
  return this;
418
418
  }
419
419
 
@@ -430,7 +430,7 @@ export class Vec3 implements IVec3 {
430
430
  this._y = Math.floor(this._y);
431
431
  this._z = Math.floor(this._z);
432
432
 
433
- // this.fire('change');
433
+ // this.fire('change');
434
434
  return this;
435
435
  }
436
436
 
@@ -439,7 +439,7 @@ export class Vec3 implements IVec3 {
439
439
  this._y = Math.ceil(this._y);
440
440
  this._z = Math.ceil(this._z);
441
441
 
442
- // this.fire('change');
442
+ // this.fire('change');
443
443
  return this;
444
444
  }
445
445
 
@@ -448,7 +448,7 @@ export class Vec3 implements IVec3 {
448
448
  this._y = Math.round(this._y);
449
449
  this._z = Math.round(this._z);
450
450
 
451
- // this.fire('change');
451
+ // this.fire('change');
452
452
  return this;
453
453
  }
454
454
 
@@ -457,7 +457,7 @@ export class Vec3 implements IVec3 {
457
457
  this._y = this._y < 0 ? Math.ceil(this._y) : Math.floor(this._y);
458
458
  this._z = this._z < 0 ? Math.ceil(this._z) : Math.floor(this._z);
459
459
 
460
- // this.fire('change');
460
+ // this.fire('change');
461
461
  return this;
462
462
  }
463
463
 
@@ -466,7 +466,7 @@ export class Vec3 implements IVec3 {
466
466
  this._y = -this._y;
467
467
  this._z = -this._z;
468
468
 
469
- // this.fire('change');
469
+ // this.fire('change');
470
470
  return this;
471
471
  }
472
472
 
@@ -671,14 +671,26 @@ export class Vec3 implements IVec3 {
671
671
  return this.sub(_vec.copy(normal).multiplyScalar(2 * this.dot(normal)));
672
672
  }
673
673
 
674
+ /**
675
+ * 两个向量的夹角
676
+ * @param v
677
+ * @param normal
678
+ * @returns
679
+ */
674
680
  angleTo(v: Vec3, normal?: Vec3 | any) {
675
681
  if (normal)
676
- return this.angleToEx(v, normal)
682
+ return this.angleToEx(v, normal);
677
683
 
678
684
  var theta = this.dot(v) / Math.sqrt(this.lengthSq() * v.lengthSq());
679
685
  return Math.acos(clamp(theta, -1, 1));
680
686
  }
681
687
 
688
+ /**
689
+ * 一个向量到另一个向量的角度
690
+ * @param v
691
+ * @param normal
692
+ * @returns
693
+ */
682
694
  angleToEx(v: Vec3, normal: Vec3) {
683
695
  var theta = this.dot(v) / Math.sqrt(this.lengthSq() * v.lengthSq());
684
696
 
package/src/math/vecs.ts CHANGED
@@ -353,43 +353,51 @@ export class vecs {
353
353
  * @param {String} comSort 'x','y','z','w' 按顺序选取后自由组合
354
354
  * @returns {Array<Number>} 数字数组
355
355
  */
356
- static verctorToNumbers(vectors: Array<Vec4 | Vec3 | Vec2 | any> | any, comSort = "xyz"): number[] {
356
+ static verctorToNumbers(vectors: Array<Vec4 | Vec3 | Vec2 | any> | any, comSort?: string): number[] {
357
357
  if (!(vectors instanceof Array)) {
358
358
  console.error("传入参数必须是数组");
359
359
  return [];
360
360
  }
361
361
 
362
362
  var numbers: number[] = [];
363
- if (vectors[0].x !== undefined && vectors[0].y !== undefined && vectors[0].z !== undefined && vectors[0].w !== undefined) {
364
- comSort = comSort.length !== 4 ? 'xyzw' : comSort;
365
- for (var i = 0; i < vectors.length; i++) {
366
- for (let j = 0; j < comSort.length; j++) {
367
- numbers.push(vectors[i][comSort[j]]);
363
+ if (!comSort) {
364
+ if (vectors[0].x !== undefined && vectors[0].y !== undefined && vectors[0].z !== undefined && vectors[0].w !== undefined) {
365
+ comSort = !comSort ? 'xyzw' : comSort;
366
+ for (var i = 0; i < vectors.length; i++) {
367
+ for (let j = 0; j < comSort.length; j++) {
368
+ numbers.push(vectors[i][comSort[j]]);
369
+ }
368
370
  }
369
371
  }
370
- }
371
- if (vectors[0].x !== undefined && vectors[0].y !== undefined && vectors[0].z !== undefined) {
372
- comSort = comSort.length !== 3 ? 'xyz' : comSort;
373
- for (var i = 0; i < vectors.length; i++) {
374
- for (let j = 0; j < comSort.length; j++) {
375
- numbers.push(vectors[i][comSort[j]]);
372
+ if (vectors[0].x !== undefined && vectors[0].y !== undefined && vectors[0].z !== undefined) {
373
+ comSort = !comSort ? 'xyz' : comSort;
374
+ for (var i = 0; i < vectors.length; i++) {
375
+ for (let j = 0; j < comSort.length; j++) {
376
+ numbers.push(vectors[i][comSort[j]]);
377
+ }
378
+ }
379
+ } else if (vectors[0].x !== undefined && vectors[0].y !== undefined) {
380
+ comSort = !comSort ? 'xy' : comSort;
381
+ for (var i = 0; i < vectors.length; i++) {
382
+ for (let j = 0; j < comSort.length; j++) {
383
+ numbers.push(vectors[i][comSort[j]]);
384
+ }
376
385
  }
377
386
  }
378
- } else if (vectors[0].x !== undefined && vectors[0].y !== undefined) {
379
- comSort = comSort.length !== 2 ? 'xy' : comSort;
387
+ else if (vectors[0] instanceof Array) {
388
+ for (var i = 0; i < vectors.length; i++) {
389
+ numbers = numbers.concat(vecs.verctorToNumbers(vectors[i]));
390
+ }
391
+ } else {
392
+ console.error("数组内部的元素不是向量");
393
+ }
394
+ } else {
380
395
  for (var i = 0; i < vectors.length; i++) {
381
396
  for (let j = 0; j < comSort.length; j++) {
382
397
  numbers.push(vectors[i][comSort[j]]);
383
398
  }
384
399
  }
385
400
  }
386
- else if (vectors[0] instanceof Array) {
387
- for (var i = 0; i < vectors.length; i++) {
388
- numbers = numbers.concat(vecs.verctorToNumbers(vectors[i]));
389
- }
390
- } else {
391
- console.error("数组内部的元素不是向量");
392
- }
393
401
 
394
402
  return numbers;
395
403
  }
@@ -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 toVertices(center: Vec3, radius: number, startAngle: number = 0, lengthAngle: number = Math.PI * 2, segment: number = 16) {
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 up: Vec3 = Vec3.UnitY;
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 = a.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
@@ -0,0 +1,18 @@
1
+ import { Tree } from "./tree";
2
+
3
+ /**
4
+ *
5
+ */
6
+ export class BSP extends Tree {
7
+ constructor() {
8
+ super(2);
9
+ }
10
+
11
+ get pos() {
12
+ return this.children[0];
13
+ }
14
+
15
+ get neg() {
16
+ return this.children[1];
17
+ }
18
+ }