Skip to content

Commit f19149e

Browse files
author
hackermd
committed
Add check to ensure ellipse axes have right angle
1 parent b17d396 commit f19149e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/scoord3d.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,26 @@ class Ellipse extends Scoord3D {
229229
if(options.coordinates.find(c => c.some((item => item < 0)))) {
230230
throw new Error('coordinates of Ellipse must be positive numbers')
231231
}
232-
// TODO: assert major and minor axes are in right angle
232+
const majorAxis = [
233+
options.coordinates[0][0] - options.coordinates[1][0],
234+
options.coordinates[0][1] - options.coordinates[1][1]
235+
];
236+
const minorAxis = [
237+
options.coordinates[2][0] - options.coordinates[3][0],
238+
options.coordinates[2][1] - options.coordinates[3][1]
239+
];
240+
const majorAxisNorm = Math.sqrt(
241+
Math.pow(majorAxis[0], 2) + Math.pow(majorAxis[1], 2)
242+
);
243+
const minorAxisNorm = Math.sqrt(
244+
Math.pow(minorAxis[0], 2) + Math.pow(minorAxis[1], 2)
245+
);
246+
const dotProduct = majorAxis[0] * minorAxis[0] + majorAxis[1] * minorAxis[1];
247+
const angle = Math.acos(dotProduct / (majorAxisNorm * minorAxisNorm));
248+
const degree = angle * 180 / Math.PI;
249+
if(degree !== 90) {
250+
throw new Error('major and minor axis of Ellipse must have right angle')
251+
}
233252
super({
234253
coordinates: options.coordinates,
235254
frameOfReferenceUID: options.frameOfReferenceUID,

0 commit comments

Comments
 (0)