@@ -16,11 +16,11 @@ public sealed class EllipticalArcLineSegment : ILineSegment
1616 private const float MinimumSqrDistance = 1.75f ;
1717 private readonly PointF [ ] linePoints ;
1818 private PointF center ;
19- private float firstRadius ;
20- private float secondRadius ;
21- private float rotation ;
22- private float startAngle ;
23- private float sweepAngle ;
19+ private readonly float firstRadius ;
20+ private readonly float secondRadius ;
21+ private readonly float rotation ;
22+ private readonly float startAngle ;
23+ private readonly float sweepAngle ;
2424
2525 /// <summary>
2626 /// Initializes a new instance of the <see cref="EllipticalArcLineSegment"/> class.
@@ -73,8 +73,15 @@ public EllipticalArcLineSegment Transform(Matrix3x2 matrix)
7373 return this ;
7474 }
7575
76- // TODO
77- return this ;
76+ PointF center = PointF . Transform ( this . center , matrix ) ;
77+ PointF helpFirstRadius = PointF . Transform ( CalculatePoint ( 90 , this . firstRadius , this . secondRadius , this . rotation , this . center ) , matrix ) ;
78+ PointF helpSecondRadius = PointF . Transform ( CalculatePoint ( 0 , this . firstRadius , this . secondRadius , this . rotation , this . center ) , matrix ) ;
79+ float firstRadius = new Vector2 ( center . X - helpFirstRadius . X , center . Y - helpFirstRadius . Y ) . Length ( ) ;
80+ float secondRadius = new Vector2 ( center . X - helpSecondRadius . X , center . Y - helpSecondRadius . Y ) . Length ( ) ;
81+ Vector2 helperRotation1 = new Vector2 ( helpFirstRadius . X - center . X , helpFirstRadius . Y - center . Y ) ;
82+ Vector2 helperRotation2 = new Vector2 ( firstRadius , 0 ) ;
83+ float rotatation = ( float ) Math . Acos ( Vector2 . Dot ( helperRotation1 , helperRotation2 ) / ( helperRotation1 . Length ( ) * helperRotation2 . Length ( ) ) ) ;
84+ return new EllipticalArcLineSegment ( center , firstRadius , secondRadius , rotation , ) ;
7885 }
7986
8087 /// <summary>
@@ -87,7 +94,7 @@ public EllipticalArcLineSegment Transform(Matrix3x2 matrix)
8794 private PointF [ ] GetDrawingPoints ( )
8895 {
8996 var points = new List < PointF > ( ) {
90- this . calculatePoint ( this . startAngle )
97+ CalculatePoint ( this . startAngle , this . firstRadius , this . secondRadius , this . rotation , this . center )
9198 } ;
9299
93100 for ( float i = this . startAngle ; i < this . startAngle + this . sweepAngle ; i ++ )
@@ -98,7 +105,7 @@ private PointF[] GetDrawingPoints()
98105 end = this . startAngle + this . sweepAngle ;
99106 }
100107
101- points . AddRange ( this . GetDrawingPoints ( i , end , 0 ) ) ;
108+ points . AddRange ( this . GetDrawingPoints ( i , end , 0 ) ) ;
102109 }
103110
104111 return points . ToArray ( ) ;
@@ -113,8 +120,8 @@ private List<PointF> GetDrawingPoints(float start, float end, int depth)
113120
114121 var points = new List < PointF > ( ) ;
115122
116- PointF startP = calculatePoint ( start ) ;
117- PointF endP = calculatePoint ( end ) ;
123+ PointF startP = CalculatePoint ( start , this . firstRadius , this . secondRadius , this . rotation , this . center ) ;
124+ PointF endP = CalculatePoint ( end , this . firstRadius , this . secondRadius , this . rotation , this . center ) ;
118125 if ( ( new Vector2 ( endP . X , endP . Y ) - new Vector2 ( startP . X , startP . Y ) ) . LengthSquared ( ) < MinimumSqrDistance )
119126 {
120127 points . Add ( endP ) ;
@@ -129,10 +136,10 @@ private List<PointF> GetDrawingPoints(float start, float end, int depth)
129136 return points ;
130137 }
131138
132- private PointF calculatePoint ( float angle )
139+ private static PointF CalculatePoint ( float angle , float firstRadius , float secondRadius , float rotation , PointF center )
133140 {
134- float x = ( float ) ( ( this . firstRadius * Math . Sin ( Math . PI * angle / 180 ) * Math . Cos ( Math . PI * this . rotation / 180 ) ) - ( this . secondRadius * Math . Cos ( Math . PI * angle / 180 ) * Math . Sin ( Math . PI * this . rotation / 180 ) ) + this . center . X ) ;
135- float y = ( float ) ( ( this . firstRadius * Math . Sin ( Math . PI * angle / 180 ) * Math . Sin ( Math . PI * this . rotation / 180 ) ) + ( this . secondRadius * Math . Cos ( Math . PI * angle / 180 ) * Math . Cos ( Math . PI * this . rotation / 180 ) ) + this . center . Y ) ;
141+ float x = ( float ) ( ( firstRadius * Math . Sin ( Math . PI * angle / 180 ) * Math . Cos ( Math . PI * rotation / 180 ) ) - ( secondRadius * Math . Cos ( Math . PI * angle / 180 ) * Math . Sin ( Math . PI * rotation / 180 ) ) + center . X ) ;
142+ float y = ( float ) ( ( firstRadius * Math . Sin ( Math . PI * angle / 180 ) * Math . Sin ( Math . PI * rotation / 180 ) ) + ( secondRadius * Math . Cos ( Math . PI * angle / 180 ) * Math . Cos ( Math . PI * rotation / 180 ) ) + center . Y ) ;
136143 return new PointF ( x , y ) ;
137144 }
138145
0 commit comments