@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.
@@ -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 = 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
@@ -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
+ }