Skip to content

[API Proposal]: Plane.Project #107407

Description

@PavielKraskouski

Background and motivation

Projecting a point onto a plane is a basic operation that can be used in a variety of problems.

API Proposal

namespace System.Numerics;

public struct Plane
{
    public static Vector3 Project(Plane plane, Vector3 point)
    {
        return point - (Vector3.Dot(plane.Normal, point) + plane.D) * plane.Normal;
    }
}

API Usage

Vector3 point = new(1, 2, 3);
Plane plane = new(Vector3.UnitY, -5);
Vector3 projectedPoint = Plane.Project(plane, point);

Alternative Designs

Two alternative placements were raised in the discussion below. The naming and placement question was left open for API review.

1. Extension method on Vector3 — proposed by @julealgon (comment) as more intuitive and more discoverable at the call site:

public static class VectorProjectionExtensions
{
    public static Vector3 ProjectOnto(this Vector3 point, Plane plane);
}
Vector3 projectedPoint = point.ProjectOnto(plane);

2. Static method on Vector3 — proposed by @PavielKraskouski (comment), mirroring the existing Vector3.Transform methods:

namespace System.Numerics;

public struct Vector3
{
    public static Vector3 Project(Vector3 point, Plane plane);
}

Considerations raised for each:

  • Vector3.Project reads better than Plane.Project, because Plane.Project gives the impression that the plane is the thing being projected (julealgon).
  • .NET has no existing extension-method class for vectors, so introducing one to hold a single method may be impractical (PavielKraskouski).

Risks

No response

Activity

  1. added
    api-suggestion
    on Sep 5, 2024
  2. added
    untriaged
    on Sep 5, 2024
  3. dotnet-policy-service commented on Sep 5, 2024

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-numerics
    See info in area-owners.md if you want to be subscribed.

  4. julealgon commented on Sep 5, 2024

    @julealgon

    Wouldn't this be more intuitive if it was an extension on Vector instead of a pure static method?

    public static class VectorProjectionExtensions
    {
        public static Vector3 ProjectOnto(this Vector3 point, Plane plane)
    Vector3 point = new(1, 2, 3);
    Plane plane = new(Vector3.UnitY, -5);
    Vector3 projectedPoint = point.ProjectOnto(plane);
  5. PavielKraskouski commented on Sep 5, 2024

    @PavielKraskouski
    Author

    In this case, it is better to make this method static for Vector3, similar to Vector3.Transform methods.

    namespace System.Numerics;
    
    public struct Vector3
    {
        public static Vector3 Project(Vector3 point, Plane plane);
    }
  6. julealgon commented on Sep 5, 2024

    @julealgon

    In this case, it is better to make this method static for Vector3, similar to Vector3.Transform methods.

    @PavielKraskouski can you elaborate why it is better? Are you arguing just for consistency with Vector3.Transform, or is there more to it?

    I think the extension method approach not only makes this more intuitive to use, but also more discoverable.

    I do agree that Vector3.Project seems more intuitive than Plane.Project though as the latter gives the impression you are "projecting the plane", which is not really what is happening.

  7. PavielKraskouski commented on Sep 5, 2024

    @PavielKraskouski
    Author

    @julealgon My main argument is that .Net doesn't have a separate extension method class for vectors, so I think creating a class with one method is impractical. However, if .Net developers approve this method, they'll decide where to add it.

  8. added this to the Future milestone on Sep 17, 2024
  9. added
    needs-further-triage
    and removed
    untriaged
    on Sep 17, 2024
  10. added
    api-ready-for-review
    and removed
    api-suggestion
    needs-further-triage
    on Aug 17, 2026
  11. bartonjs commented on Oct 13, 2026

    @bartonjs
    Member

    Video

    Looks good as proposed.

    namespace System.Numerics;
    
    public partial struct Plane
    {
        public static Vector3 Project(Plane plane, Vector3 point);
    }
  12. added
    api-approved
    and removed
    api-ready-for-review
    on Oct 13, 2026
  13. Manish-1kumar commented on Nov 5, 2026

    @Manish-1kumar
    Contributor

    I'd like to take this one and will open a PR implementing the approved Plane.Project(Plane, Vector3) with tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedarea-System.Numerics

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions