Skip to content

Commit

Permalink
Update BuildingShapeUtils.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Beakerboy authored May 15, 2024
1 parent b87b26c commit 56ddaff
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/extras/BuildingShapeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,25 +243,30 @@ class BuildingShapeUtils extends ShapeUtils {
}

/**
* Calculate the angle of each of a shape's edge
* Calculate the angle of each of a shape's edge.
* the angle will be PI > x >= -PI
*
* @param {THREE.Shape} shape - the shape
*
* @return {[number, ...]} the angles in radians.
*/
static edgeDirection(shape) {
const points = shape.extractPoints().shape;
points.push(points[0]);
const angles = [];
var p1;
var p2;
for (let i = 0; i < points.length - 1; i++) {
for (let i = 0; i < points.length; i++) {
p1 = points[i];
p2 = points[i + 1];
angles.push(Math.atan((p2.y - p1.y) / (p2.x - p1.x)));
let angle = Math.atan2((p2.y - p1.y), (p2.x - p1.x));
if (angle >= Math.PI / 2) {
angle -= Math.PI;
} else if (angle < -Math.PI / 2) {
angle += Math.PI;
}
angles.push(angle);
}
p1 = points[points.length - 1];
p2 = points[0];
angles.push(Math.atan((p2.y - p1.y) / (p2.x - p1.x)));
return angles;
}

Expand Down

0 comments on commit 56ddaff

Please sign in to comment.