File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments