|
@@ -97,31 +97,58 @@ export class CircumferenceModel extends GeometricObject {
|
|
];
|
|
];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Get Intersection Poin By Circumference and Line Segment
|
|
|
|
+ * @param {LineSegmentModel} lineSegment
|
|
|
|
+ */
|
|
getIntersectionByLine(lineSegment) {
|
|
getIntersectionByLine(lineSegment) {
|
|
- const r = this.getStraight();
|
|
|
|
- const s = lineSegment.getStraight();
|
|
|
|
- const a1 = r[0];
|
|
|
|
- const b1 = r[1];
|
|
|
|
- const c1 = r[2];
|
|
|
|
- const a2 = s[0];
|
|
|
|
- const b2 = s[1];
|
|
|
|
- const c2 = s[2];
|
|
|
|
- const determinant = a1 * b2 - a2 * b1;
|
|
|
|
- if (determinant == 0) {
|
|
|
|
|
|
+
|
|
|
|
+ const pointA = lineSegment.pointA;
|
|
|
|
+ const pointB = lineSegment.pointB;
|
|
|
|
+ const center = this.center;
|
|
|
|
+ const radius = this.getRadius();
|
|
|
|
+
|
|
|
|
+ const dx = pointB.posX - pointA.posX;
|
|
|
|
+ const dy = pointB.posY - pointA.posY;
|
|
|
|
+
|
|
|
|
+ const cx = center.posX - pointA.posX;
|
|
|
|
+ const cy = center.posY - pointA.posY;
|
|
|
|
+
|
|
|
|
+ const a = dx * dx + dy * dy;
|
|
|
|
+ const b = dx * cx + dy * cy;
|
|
|
|
+ const c = cx * cx + cy * cy - radius * radius;
|
|
|
|
+
|
|
|
|
+ const D = b / a;
|
|
|
|
+ const q = c / a;
|
|
|
|
+
|
|
|
|
+ const delta = D * D - q;
|
|
|
|
+ if (delta < 0) {
|
|
return [
|
|
return [
|
|
- new IntersectionModel(
|
|
|
|
- Number.MAX_SAFE_INTEGER,
|
|
|
|
- Number.MAX_SAFE_INTEGER,
|
|
|
|
- undefined,
|
|
|
|
- this,
|
|
|
|
- lineSegment
|
|
|
|
- )
|
|
|
|
|
|
+ new IntersectionModel(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, lineSegment, false, 0),
|
|
|
|
+ new IntersectionModel(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, lineSegment, false, 1)
|
|
];
|
|
];
|
|
- } else {
|
|
|
|
- const x = (b2 * c1 - b1 * c2) / determinant;
|
|
|
|
- const y = (a1 * c2 - a2 * c1) / determinant;
|
|
|
|
- return [new IntersectionModel(x, y, undefined, this, lineSegment)];
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ const deltaSqrt = Math.sqrt(delta);
|
|
|
|
+ const root1 = -D + deltaSqrt;
|
|
|
|
+ const root2 = -D - deltaSqrt;
|
|
|
|
+ const x1 = pointA.posX - dx * root1
|
|
|
|
+ const y1 = pointA.posY - dy * root1;
|
|
|
|
+
|
|
|
|
+ if (delta == 0) {
|
|
|
|
+ return [
|
|
|
|
+ new IntersectionModel(x1, y1, undefined, this, lineSegment, true, 0),
|
|
|
|
+ new IntersectionModel(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, lineSegment, false, 1)
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ const x2 = pointA.posX - dx * root2;
|
|
|
|
+ const y2 = pointA.posY - dy * root2;
|
|
|
|
+
|
|
|
|
+ return [
|
|
|
|
+ new IntersectionModel(x1, y1, undefined, this, lineSegment, true, 0),
|
|
|
|
+ new IntersectionModel(x2, y2, undefined, this, lineSegment, true, 1)
|
|
|
|
+ ];
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
insideSegment(intersecX, intersecY) {
|
|
insideSegment(intersecX, intersecY) {
|