- Home /
Point on a Plane between two points
I have a Plane (the class not the gameobject) and two Vector 3 positions.
I am trying to find the point on the line between the two positions that also intersects the plane.
My best idea at the moment is creating a custom plane class that stores the equation of the plane and working it out using algebra however I feel like there is likely a simpler way.
Thanks
Assu$$anonymous$$g you have a collider on the plane, you can get the middle between both points and use Collider.ClosestPoint like so
Vector3 pointOnPlane = myPlaneObject.GetComponent<Collider>().ClosestPoint(centerPointOfTwoPoints);
Rereading your question now, I think it may actually be easiest to Raycast between the two points, and if the ray hits the plane, then you found your intersecting point. Something to note though, if your plane is 1-sided you would need to set your physics to query backfaces.
To clarify the plane is the built -in class Plane not a physical one
Answer by MomentsStudio · Feb 17, 2019 at 07:33 PM
It turns out getting the equation from the plane was not too hard.
Vector3 PointOnPlaneBetweenTwoPoints(Plane p, Vector3 a, Vector3 b){
Vector3 q = (b-a);
q.Normalize();
Vector3 planeEqation;
Vector3 pointOnPlane = p.ClosestPointOnPlane(Vector3.zero);
Vector3 normal = p.normal;
planeEqation = normal;
float offset = Vector3.Dot(pointOnPlane,normal);
Debug.Log(planeEqation);
float t = (offset-Vector3.Dot(a,planeEqation))/Vector3.Dot(q,planeEqation);
return a+(q*t);
}
If anyone else ever needs this feel free to use it.
Your answer
Follow this Question
Related Questions
Projecting a point on plane 1 Answer
Finding the intersection of vertical plane and scene mesh geometry 0 Answers
Get point in plane where the normal crosses a GameObject in local space 2 Answers
Using the Horizontal Slider to Control a Plane's Y transform Variable 1 Answer
Detecting object inside an area. 1 Answer