11using System ;
22using System . Collections . Generic ;
3+ using System . Runtime . CompilerServices ;
34
45namespace CSMath . Geometry
56{
67 public static class CurveExtensions
78 {
8- public static XYZ PolarCoordinateRelativeToCenter ( double angle , XYZ center , XYZ normal , XYZ startPoint , double ratio = 1 )
9+ public static XYZ PolarCoordinateRelativeToCenter ( double angle , XYZ center , XYZ normal , XYZ startPoint , double ratio = 1 )
910 {
1011 XYZ prep = XYZ . Cross ( normal , startPoint ) ;
1112 double radius = startPoint . Normalize ( ) . GetLength ( ) ;
@@ -20,7 +21,7 @@ public static XYZ PolarCoordinateRelativeToCenter(double angle, XYZ center, XYZ
2021 /// <param name="startAngle"></param>
2122 /// <param name="endAngle"></param>
2223 /// <param name="normal"></param>
23- /// <param name="startPoint">Start point of the curve relative to center .</param>
24+ /// <param name="startPoint">Start point in the curve.</param>
2425 /// <param name="ratio"></param>
2526 /// <returns></returns>
2627 /// <exception cref="ArgumentOutOfRangeException"></exception>
@@ -33,23 +34,22 @@ public static List<XYZ> PolygonalVertexes(int precision, XYZ center, double star
3334
3435 List < XYZ > points = new ( ) ;
3536
36- double start = startAngle ;
3737 double end = endAngle ;
38- if ( end <= start )
38+ if ( end <= startAngle )
3939 {
4040 end += MathHelper . TwoPI ;
4141 }
4242
43- XYZ prep = XYZ . Cross ( normal , startPoint ) ;
44-
45- double portion = startPoint . Normalize ( ) . GetLength ( ) ;
46- double radius = ratio * portion ;
43+ XYZ xdir = ( startPoint - center ) . Normalize ( ) ;
44+ XYZ ydir = XYZ . Cross ( normal , xdir ) ;
4745
48- double delta = ( end - start ) / ( precision - 1 ) ;
46+ double delta = ( end - startAngle ) / ( precision - 1 ) ;
47+ double radius = center . DistanceFrom ( startPoint ) ;
4948
49+ double start = 0 ;
5050 for ( int i = 0 ; i < precision ; i ++ , start += delta )
5151 {
52- points . Add ( portion * MathHelper . Cos ( start ) * startPoint + radius * MathHelper . Sin ( start ) * prep + center ) ;
52+ points . Add ( MathHelper . Cos ( start ) * xdir * radius + ( double ) ratio * MathHelper . Sin ( start ) * ydir * radius + center ) ;
5353 }
5454
5555 return points ;
0 commit comments