1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import { GeometricObject } from "../../../core/models/objects/geometric-object";
- import { IntersectionModel } from "../../intersection-component/models/intersection-model";
- export class LineSegmentModel extends GeometricObject {
- constructor(pointA, pointB, label) {
- super();
- this.pointA = pointA;
- this.pointB = pointB;
- this.setLabel(label);
- }
- getStraight() {
- const aX = this.pointA.posX;
- const aY = this.pointA.posY;
- const bX = this.pointB.posX;
- const bY = this.pointB.posY;
- const a = bY - aY;
- const b = aX - bX;
- const c = a * aX + b * aY;
- return [a, b, c];
- }
- getIntersection(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) {
- return new IntersectionModel(
- Number.MAX_SAFE_INTEGER,
- Number.MAX_SAFE_INTEGER,
- undefined,
- this,
- lineSegment
- );
- } else {
- const x = (b2 * c1 - b1 * c2) / determinant;
- const y = (a1 * c2 - a2 * c1) / determinant;
- return new IntersectionModel(x, y, undefined, this, lineSegment);
- }
- }
- }
|