8000 add project point to plane by chuongmep · Pull Request #402 · GSharker/G-Shark · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add project point to plane #402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/GShark.Test.XUnit/Geometry/Point3Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ public void It_Checks_If_A_Point_Lies_On_A_Plane()
// Assert
pt.IsOnPlane(plane, 0.001).Should().BeTrue();
}

[Fact]
public void If_Check_Project_A_Point_On_A_Plane()
{
// Arrange
Point3 point = new Point3(10, 20, -5);
Point3 planeOrigin = new Point3(0, 10, 0);
Vector3 direction = new Vector3(0, 1, 0);
Plane plane = new Plane(planeOrigin, direction);
var expectedPt = new Point3(10, 10, -5);

// Act
var result = point.ProjectToPlan(plane);

// Assert
result.Should().BeEquivalentTo(expectedPt);
result.Equals(expectedPt).Should().Be(true);
}

[Fact]
public void It_Returns_The_Linear_Interpolation_Between_Two_Points()
Expand All @@ -71,6 +89,7 @@ public void It_Returns_The_Linear_Interpolation_Between_Two_Points()
var result = Point3.Interpolate(p1, p2, amount);

// Assert

result.Equals(expectedPoint).Should().Be(true);
}

Expand Down
14 changes: 14 additions & 0 deletions src/GShark/Geometry/Point3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,19 @@ public double DistanceTo(Point3 other)
}
return d;
}

/// <summary>
/// Projects a point onto a plane.
/// </summary>
/// <param name="plane">Plane to project onto</param>
/// <returns name="point3">The point projected to plane</returns>
public Point3 ProjectToPlan(Plane plane)
{
Vector3 v = plane.Origin - this;
Vector3 normal = plane.ZAxis;
double d = Vector3.DotProduct(v, normal);
return this + d * normal;
}

/// <summary>
/// Calculates the distance of a point to a line.
Expand Down Expand Up @@ -665,6 +678,7 @@ public int InPolygon(Polygon polygon)
}
return inside ? 1 : -1;
}

}
}

0