Skip to content

Commit

Permalink
fixed eq to get points on ellipse curve
Browse files Browse the repository at this point in the history
  • Loading branch information
AnushaTiwari5 committed Oct 8, 2023
1 parent 7034723 commit af4c04c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 31 deletions.
1 change: 1 addition & 0 deletions src/AEG/AEGTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class AEGTree {
* @returns True, if the node can be inserted. Else, false
*/
public canInsert(incomingNode: AtomNode | CutNode): boolean {
console.log("checking can insert");
const currentCut: CutNode = this.sheet.getCurrentCut(incomingNode);
for (let i = 0; i < currentCut.children.length; i++) {
if (this.overlaps(incomingNode, currentCut.children[i])) {
Expand Down
1 change: 1 addition & 0 deletions src/AEG/CutNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class CutNode {
public getCurrentCut(newNode: CutNode | AtomNode): CutNode {
for (let i = 0; i < this.children.length; i++) {
if (this.children[i] instanceof CutNode && this.children[i].containsNode(newNode)) {
console.log("current cut: " + this.children[i]);
//newNode can be placed at least one layer deeper
return this.getCurrentCut(this.children[i]);
}
Expand Down
70 changes: 39 additions & 31 deletions src/AEG/Ellipse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export class Ellipse {
this.radiusX +
", \n" +
"Vertical Radius of: " +
this.radiusY
this.radiusY +
", \n" +
"Bounding box: " +
this.boundingBox.toString()
);
}

Expand All @@ -74,9 +77,10 @@ export class Ellipse {
//(x, y) = new point
//(h, k) = center

const p: number =
const p: number = Math.round(
Math.pow(otherPoint.x - this.center.x, 2) / Math.pow(this.radiusX, 2) +
Math.pow(otherPoint.y - this.center.y, 2) / Math.pow(this.radiusY, 2);
Math.pow(otherPoint.y - this.center.y, 2) / Math.pow(this.radiusY, 2)
);

return p <= 1;

Expand Down Expand Up @@ -106,6 +110,7 @@ export class Ellipse {
} else {
//check if the rectangular bounding boxes of the ellipse overlap
if (this.boundingBox.overlaps((otherShape as Ellipse).boundingBox)) {
console.log("ellipse boxes overlap");
//if there is an overlap, check if points along the ellipse curve overlap
//this can be done by checking if points along the curve of the other ellipse
//are within this ellipse
Expand Down Expand Up @@ -142,25 +147,6 @@ export class Ellipse {
}
}

/**
* An array containing the widest coordinates of the ellipse, i.e. the coordinates along the
* x-axis and y-axis of the ellipse.
* The coordinates are in clockwise order such that:
* 0 - Top most coordinate (Top along y-axis).
* 1 - Right most coordinate (Right along x-axis).
* 2 - Bottom most coordinate (Bottom along y-axis).
* 3 - Left most coordinate (Left along x-axis).
* @returns
*/
public getWidestCoordinates(): Point[] {
return [
new Point(this.center.x, this.center.y - this.radiusY),
new Point(this.center.x + this.radiusX, this.center.y),
new Point(this.center.x, this.center.y + this.radiusY),
new Point(this.center.x - this.radiusX, this.center.y),
];
}

/**
* Method that checks if any quadrant of another ellipse overlaps with this ellipse.
* This can be done by checking if a point on the curve of the ellipse is within this ellipse.
Expand All @@ -171,7 +157,6 @@ export class Ellipse {
//Get the quadrant which might be overlapping with this ellipse.
//To do so, check which corner of the rectangular bounding box of the other ellipse
//is within this ellipse.

for (let i = 0; i < 4; i++) {
if (this.containsPoint(otherEllipse.boundingBox.getCorners()[i])) {
//Get the points on the curve of the ellipse in that quadrant
Expand All @@ -191,50 +176,73 @@ export class Ellipse {
return false;
}

/**
* An array containing the widest coordinates of the ellipse, i.e. the coordinates along the
* x-axis and y-axis of the ellipse.
* The coordinates are in clockwise order such that:
* 0 - Top most coordinate (Top along y-axis).
* 1 - Right most coordinate (Right along x-axis).
* 2 - Bottom most coordinate (Bottom along y-axis).
* 3 - Left most coordinate (Left along x-axis).
* @returns
*/
public getWidestCoordinates(): Point[] {
return [
new Point(this.center.x, this.center.y - this.radiusY),
new Point(this.center.x + this.radiusX, this.center.y),
new Point(this.center.x, this.center.y + this.radiusY),
new Point(this.center.x - this.radiusX, this.center.y),
];
}

/**
* Method that returns the points on the curve of the ellipse in a specific quadrant
* @param quadrant The quadrant which we want the points in
* @returns An array of points along the curve of the ellipse
*/
private getQuadrantPoints(quadrant: number): Point[] {
//==========DEBUGGG=========
console.log("Getting points for: " + this + "\n" + "In quad: " + quadrant);

const points: Point[] = [];
let quadDistance = 0;
const quadDistance = this.radiusX;
let curve = 1;

if (quadrant === 0) {
//top left quadrant
points[0] = this.getWidestCoordinates()[3];
points[1] = this.getWidestCoordinates()[0];

quadDistance = Math.abs(points[0].x - points[1].x);
} else if (quadrant === 1) {
//top right quadrant
points[0] = this.getWidestCoordinates()[0];
points[1] = this.getWidestCoordinates()[1];

quadDistance = Math.abs(points[0].x - points[1].x);
} else if (quadrant === 2) {
//bottom right quadrant
points[0] = this.getWidestCoordinates()[1];
points[1] = this.getWidestCoordinates()[2];

quadDistance = Math.abs(points[0].x - points[1].x);
curve = -1;
} else if (quadrant === 3) {
//bottom left quadrant
points[0] = this.getWidestCoordinates()[2];
points[1] = this.getWidestCoordinates()[3];

quadDistance = Math.abs(points[0].x - points[1].x);
curve = -1;
}

for (let i = 2; i < 6; i++) {
const x = points[0].x + (i - 1) * (quadDistance / 5);
let x = points[0].x;
if (curve === 1) {
x = x + (i - 1) * (quadDistance / 5);
} else {
x = x - (i - 1) * (quadDistance / 5);
}
const y = this.getCurvePoint(x, curve);
points[i] = new Point(x, y);
}

//========DEBUGGGG========
console.log(points);
return points;
}

Expand Down

0 comments on commit af4c04c

Please sign in to comment.