|
@@ -1,5 +1,10 @@
|
|
-export class CircumferenceModel {
|
|
|
|
|
|
+import { LineSegmentModel } from "../../line-segment-component/models/line-segment-model";
|
|
|
|
+import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
|
|
|
|
+import { GeometricObject } from "../../../core/models/objects/geometric-object";
|
|
|
|
+import { IntersectionModel } from "../../intersection-component/models/intersection-model";
|
|
|
|
+export class CircumferenceModel extends GeometricObject {
|
|
constructor(center, radius) {
|
|
constructor(center, radius) {
|
|
|
|
+ super();
|
|
this.center = center;
|
|
this.center = center;
|
|
this.radius = radius;
|
|
this.radius = radius;
|
|
this._coordinates = [];
|
|
this._coordinates = [];
|
|
@@ -7,6 +12,8 @@ export class CircumferenceModel {
|
|
this._coordinates[1] = this.center.posY;
|
|
this._coordinates[1] = this.center.posY;
|
|
this._coordinates[2] = this.radius.posX;
|
|
this._coordinates[2] = this.radius.posX;
|
|
this._coordinates[3] = this.radius.posY;
|
|
this._coordinates[3] = this.radius.posY;
|
|
|
|
+ super.setClass(ELEMENTS_CLASS.CIRCUMFERENCE);
|
|
|
|
+
|
|
}
|
|
}
|
|
getRadius() {
|
|
getRadius() {
|
|
this._coordinates[0] = this.center.posX;
|
|
this._coordinates[0] = this.center.posX;
|
|
@@ -18,4 +25,115 @@ export class CircumferenceModel {
|
|
const radius = Math.sqrt(Math.pow(legA, 2) + Math.pow(legB, 2));
|
|
const radius = Math.sqrt(Math.pow(legA, 2) + Math.pow(legB, 2));
|
|
return radius;
|
|
return radius;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ getStraight() {
|
|
|
|
+ const aX = this.center.posX;
|
|
|
|
+ const aY = this.center.posY;
|
|
|
|
+ const bX = this.radius.posX;
|
|
|
|
+ const bY = this.radius.posY;
|
|
|
|
+ const a = bY - aY;
|
|
|
|
+ const b = aX - bX;
|
|
|
|
+ const c = a * aX + b * aY;
|
|
|
|
+ return [a, b, c];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ getDirection() {
|
|
|
|
+ const aX = this.center.posX;
|
|
|
|
+ const aY = this.center.posY;
|
|
|
|
+ const bX = this.radius.posX;
|
|
|
|
+ const bY = this.radius.posY;
|
|
|
|
+ const a = bX - aX;
|
|
|
|
+ const b = bY - aY;
|
|
|
|
+ return [a, b];
|
|
|
|
+ }
|
|
|
|
+ getIntersection(geometricObject) {
|
|
|
|
+ switch (geometricObject.elementClass) {
|
|
|
|
+ case ELEMENTS_CLASS.LINE_SEGMENT:
|
|
|
|
+ return this.getIntersectionByLine(geometricObject);
|
|
|
|
+ case ELEMENTS_CLASS.CIRCUMFERENCE:
|
|
|
|
+ return this.getIntersectionByCircumference(geometricObject);
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ getIntersectionByCircumference(circumference) {
|
|
|
|
+ const rM = new LineSegmentModel(this.center, this.radius);
|
|
|
|
+ const sM = new LineSegmentModel(circumference.center, circumference.radius);
|
|
|
|
+ const r = rM.getStraight();
|
|
|
|
+ const s = sM.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,
|
|
|
|
+ circumference
|
|
|
|
+ );
|
|
|
|
+ } else {
|
|
|
|
+ const x = (b2 * c1 - b1 * c2) / determinant;
|
|
|
|
+ const y = (a1 * c2 - a2 * c1) / determinant;
|
|
|
|
+ return new IntersectionModel(x, y, undefined, this, circumference);
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ 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) {
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ insideSegment(intersecX, intersecY) {
|
|
|
|
+ const valuesR = this.getDirection();
|
|
|
|
+ const dirX = valuesR[0];
|
|
|
|
+ const dirY = valuesR[1];
|
|
|
|
+ const cInterA = dirX * intersecX + dirY * intersecY;
|
|
|
|
+
|
|
|
|
+ // comparaca cv do ponto A > cv da intersec => vazio
|
|
|
|
+ const cRA = dirX * this.center.posX + dirY * this.center.posY;
|
|
|
|
+
|
|
|
|
+ if (cInterA < cRA) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // comparaca cv do ponto B < cv da intersec => vazio
|
|
|
|
+ const cRB = dirX * this.radius.posX + dirY * this.radius.posY;
|
|
|
|
+
|
|
|
|
+ if (cInterA > cRB) {
|
|
|
|
+ this.posX = Number.MAX_SAFE_INTEGER;
|
|
|
|
+ this.posY = Number.MAX_SAFE_INTEGER;
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|