Skip to content

Commit

Permalink
Fix check if two normal vectors are withing same plane
Browse files Browse the repository at this point in the history
  • Loading branch information
DmytroMuravskyi committed Aug 29, 2023
1 parent fa0b8d1 commit 0b688a8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Elements/src/Geometry/Circle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public bool Intersects(Circle other, out List<Vector3> results)
Plane planeB = new Plane(other.Center, other.Normal);

// Check if two circles are on the same plane.
if (Normal.IsAlmostEqualTo(other.Normal) &&
if (Normal.IsParallelTo(other.Normal, Vector3.EPSILON * Vector3.EPSILON) &&
other.Center.DistanceTo(planeA).ApproximatelyEquals(0))
{
var delta = other.Center - Center;
Expand Down
4 changes: 2 additions & 2 deletions Elements/src/Geometry/Ellipse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public bool Intersects(Circle circle, out List<Vector3> results)
Plane planeB = new Plane(circle.Center, circle.Normal);

// Check if circle and ellipse are on the same plane.
if (Normal.IsAlmostEqualTo(circle.Normal) &&
if (Normal.IsParallelTo(circle.Normal, Vector3.EPSILON * Vector3.EPSILON) &&
circle.Center.DistanceTo(planeA).ApproximatelyEquals(0))
{
// Circle and Ellipse are the same.
Expand Down Expand Up @@ -381,7 +381,7 @@ public bool Intersects(Ellipse other, out List<Vector3> results)
Plane planeB = new Plane(other.Center, other.Normal);

// Check if circle and ellipse are on the same plane.
if (Normal.IsAlmostEqualTo(other.Normal) &&
if (Normal.IsParallelTo(other.Normal, Vector3.EPSILON * Vector3.EPSILON) &&
other.Center.DistanceTo(planeA).ApproximatelyEquals(0))
{
// Ellipses are the same.
Expand Down
7 changes: 7 additions & 0 deletions Elements/test/CircleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public void CirceIntersectsCircle()
Assert.Contains(new Vector3(1.5, 4.769696, 0), results);
Assert.Contains(new Vector3(1.5, -4.769696, 0), results);

// Planar intersecting circles with opposite normals
c1 = new Circle(new Transform(new Vector3(8, 0, 0), Vector3.ZAxis.Negate()), 5);
Assert.True(c0.Intersects(c1, out results));
Assert.Equal(2, results.Count());
Assert.Contains(new Vector3(4, 3, 0), results);
Assert.Contains(new Vector3(4, -3, 0), results);

// Planar touching circles
c1 = new Circle(new Vector3(8, 0, 0), 3);
Assert.True(c0.Intersects(c1, out results));
Expand Down
8 changes: 4 additions & 4 deletions Elements/test/EllipseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public void EllipseIntersectsCircle()
Assert.True(ellipse.Intersects(circle, out var results));
Assert.Equal(4, results.Count());

// Planar intersection 3 intersections.
// Planar intersection 3 intersections and negative normals.
ellipse = new Ellipse(new Vector3(1, 1), 2, 6);
circle = new Circle(new Vector3(-2, 1, 0), 5);
circle = new Circle(new Transform(new Vector3(-2, 1, 0), Vector3.ZAxis.Negate()), 5);
Assert.True(ellipse.Intersects(circle, out results));
Assert.Equal(3, results.Count());

Expand Down Expand Up @@ -130,9 +130,9 @@ public void EllipseIntersectsEllipse()
Assert.True(ellipse.Intersects(other, out var results));
Assert.Equal(4, results.Count());

// Planar intersection 3 intersections.
// Planar intersection 3 intersections and negative normals.
ellipse = new Ellipse(new Vector3(1, 1), 2, 6);
other = new Ellipse(new Vector3(-2, 1, 0), 5, 2);
other = new Ellipse(new Transform(new Vector3(-2, 1, 0), Vector3.ZAxis.Negate()), 5, 2);
Assert.True(ellipse.Intersects(other, out results));
Assert.Equal(3, results.Count());

Expand Down

0 comments on commit 0b688a8

Please sign in to comment.