Skip to content

Commit e2bf656

Browse files
committed
tweaks
1 parent fa1c31e commit e2bf656

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

distance/DistPoint2Circle2.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public double GetSquared()
5555
// Projection of P-C onto plane is Q-C = P-C - Dot(N,P-C)*N.
5656
Vector2d PmC = point - circle.Center;
5757
double lengthPmC = PmC.Length;
58-
if (lengthPmC > 0) {
58+
if (lengthPmC > MathUtil.Epsilon) {
5959
CircleClosest = circle.Center + circle.Radius * PmC / lengthPmC;
6060
AllCirclePointsEquidistant = false;
6161
} else {

distance/DistPoint3Circle3.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ public double GetSquared()
5656
Vector3d PmC = point - circle.Center;
5757
Vector3d QmC = PmC - circle.Normal.Dot(PmC) * circle.Normal;
5858
double lengthQmC = QmC.Length;
59-
if (lengthQmC > 0) {
59+
if (lengthQmC > MathUtil.Epsilon) {
6060
CircleClosest = circle.Center + circle.Radius * QmC / lengthQmC;
6161
AllCirclePointsEquidistant = false;
6262
} else {
6363
// All circle points are equidistant from P. Return one of them.
64-
CircleClosest = circle.Center + circle.Radius * circle.AxisX;
64+
CircleClosest = circle.Center + circle.Radius * circle.PlaneX;
6565
AllCirclePointsEquidistant = true;
6666
}
6767

shapes3/Circle3.cs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,37 @@ public class Circle3d
1212

1313
public Vector3d Center;
1414
public Vector3d Normal;
15-
public Vector3d AxisX, AxisY;
15+
public Vector3d PlaneX, PlaneY;
1616
public double Radius;
1717
public bool IsReversed; // use ccw orientation instead of cw
1818

19-
public Circle3d(Vector3d center, Vector3d axis0, Vector3d axis1, Vector3d normal, double radius)
19+
public Circle3d(Vector3d center, double radius, Vector3d axis0, Vector3d axis1, Vector3d normal)
2020
{
2121
IsReversed = false;
2222
Center = center;
2323
Normal = normal;
24-
AxisX = axis0;
25-
AxisY = axis1;
24+
PlaneX = axis0;
25+
PlaneY = axis1;
26+
Radius = radius;
27+
}
28+
public Circle3d(Vector3d center, double radius, Frame3f f, int nNormalAxis = 1)
29+
{
30+
IsReversed = false;
31+
Center = center;
32+
Normal = f.GetAxis(nNormalAxis);
33+
PlaneX = f.GetAxis((nNormalAxis + 1) % 3);
34+
PlaneY = f.GetAxis((nNormalAxis + 2) % 3);
35+
Radius = radius;
36+
}
37+
public Circle3d(Vector3d center, double radius)
38+
{
39+
IsReversed = false;
40+
Center = center;
41+
Normal = Vector3d.AxisY;
42+
PlaneX = Vector3d.AxisX;
43+
PlaneY = Vector3d.AxisZ;
2644
Radius = radius;
2745
}
28-
2946

3047
public bool IsClosed {
3148
get { return true; }
@@ -41,14 +58,14 @@ public Vector3d SampleDeg(double degrees)
4158
{
4259
double theta = degrees * MathUtil.Deg2Rad;
4360
double c = Math.Cos(theta), s = Math.Sin(theta);
44-
return Center + c * Radius * AxisX + s * Radius * AxisY;
61+
return Center + c * Radius * PlaneX + s * Radius * PlaneY;
4562
}
4663

4764
// angle in range [0,2pi] (but works for any value, obviously)
4865
public Vector3d SampleRad(double radians)
4966
{
5067
double c = Math.Cos(radians), s = Math.Sin(radians);
51-
return Center + c * Radius * AxisX + s * Radius * AxisY;
68+
return Center + c * Radius * PlaneX + s * Radius * PlaneY;
5269
}
5370

5471

@@ -61,7 +78,7 @@ public double ParamLength {
6178
public Vector3d SampleT(double t) {
6279
double theta = (IsReversed) ? -t*MathUtil.TwoPI : t*MathUtil.TwoPI;
6380
double c = Math.Cos(theta), s = Math.Sin(theta);
64-
return Center + c * Radius * AxisX + s * Radius * AxisY;
81+
return Center + c * Radius * PlaneX + s * Radius * PlaneY;
6582
}
6683

6784
public bool HasArcLength { get {return true;} }
@@ -76,7 +93,7 @@ public Vector3d SampleArcLength(double a) {
7693
double t = a / ArcLength;
7794
double theta = (IsReversed) ? -t*MathUtil.TwoPI : t*MathUtil.TwoPI;
7895
double c = Math.Cos(theta), s = Math.Sin(theta);
79-
return Center + c * Radius * AxisX + s * Radius * AxisY;
96+
return Center + c * Radius * PlaneX + s * Radius * PlaneY;
8097
}
8198

8299

0 commit comments

Comments
 (0)