diff --git a/src/ApplicationServices/mesh/createBoard.ts b/src/ApplicationServices/mesh/createBoard.ts index 676670cd6..a678f92ce 100644 --- a/src/ApplicationServices/mesh/createBoard.ts +++ b/src/ApplicationServices/mesh/createBoard.ts @@ -1,6 +1,6 @@ import { ExtrudeGeometry, Matrix4, Mesh, Shape, Vector2 } from 'three'; import { Shape2 } from '../../DatabaseServices/Shape2'; -import { AsVector3, equaln, equalv2, polar } from '../../Geometry/GeUtils'; +import { angle, AsVector3, equaln, equalv2, polar } from '../../Geometry/GeUtils'; import { RotateUVs } from '../../Geometry/RotateUV'; export namespace CreateBoardUtil @@ -10,37 +10,26 @@ export namespace CreateBoardUtil { _StartAn: number; _EndAn: number; - _StartPoint: Vector2; - _EndPoint: Vector2; _Center: Vector2; _Radius: number; constructor(p1: Vector2, p2: Vector2, bul: number) { - this._StartPoint = p1.clone(); - this._EndPoint = p2.clone(); - - let vec: Vector2 = p2.clone().sub(p1); - let len = vec.length(); - let an = vec.angle(); - this._Radius = len / Math.sin(2 * Math.atan(bul)) / 2; - let allAngle = Math.atan(bul) * 4; - let delDis = bul * len / 2; - let toDis = this._Radius - delDis; - an += Math.PI * 0.5; - - this._Center = p1.clone().add(p2); - this._Center.multiplyScalar(0.5); - - polar(this._Center, an, toDis); - - this._StartAn = p1.clone().sub(this._Center).angle(); - this._EndAn = p2.clone().sub(this._Center).angle(); - if (bul < 0) - { - //一个神奇的特性 它需要这么做 - this._StartAn -= Math.PI; - this._EndAn -= Math.PI; - } + p1 = p1.clone(); + p2 = p2.clone(); + + //a (* 2 (atan b)) + let a = Math.atan(bul) * 2; + //r (/ (distance p1 p2) 2 (sin a)) + let r = p1.distanceTo(p2) / 2 / Math.sin(a); + //c (polar p1 (+ (- (/ pi 2) a) (angle p1 p2)) r) + let c = polar(p1.clone(), Math.PI / 2 - a + angle(p2.clone().sub(p1)), r); + + this._Radius = Math.abs(r); + + this._StartAn = angle(p1.sub(c)); + this._EndAn = angle(p2.sub(c)); + + this._Center = c; } }