Skip to content

Commit dfd1e80

Browse files
committed
PolygonalVertexes
1 parent 7b6930b commit dfd1e80

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

CSMath/Geometry/CurveExtensions.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Runtime.CompilerServices;
34

45
namespace 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

Comments
 (0)