I will like to find the distance between an object an a plane using mathematics.
First I have to make a a plane using two Vector3. I know i have to use the Plane constructor, but what I think you get is an infinite plane and I need a constrained one, no bigger than the two vectors (for example constrained in Y and X, and infinite in Z).
After this I will use Plane.GetDistanceToPoint, but Im stuck in first.
Another thing is I don’t know how to draw that plane for debuggin purposes.
As for drawing the plane, it’s really easy to make a plane mesh procedurally, or you could just use GameObject.CreatePrimitive( PrimitiveType.Plane ) and convert your plane equation normal into a rotation for the plane.
Using what you have tell me ( GameObject.CreatePrimitive( PrimitiveType.Plane ) ) y can draw a plane and rotate it to the correct position. But the problem is still there, because I have to draw the Mathematical Plane that I build using Plane.Plane to be able to see what type of plane I’m using (a finite plane between the two vectors or and infinite plane? )
Plane.Plane has 3 ways of creating a plane:
With a vector and a point
With a vector and a distance
Whit 3 vectors
In the reference dosn’t say if they are finite or infinite planes.
If they are infinite planes (I don’t know if they are or not), you could try to create one using a very flat Cube or create a mesh with the two polygons and 4 vertices yourself.
But I don’t think the GetDistanceToPoint method cares about a constrained plane. It simply checks the distance that the point is from the infinite plane (along the plane’s normal). So I’m not sure what exactly you want, but likely your math will be against the infinite plane but visually you’d create a simple square constrained mesh.
This will create a 10x10 bounded plane. The Plane primitive is really nothing more than a 3D rectangle mesh, which starts out with a (1,1,1) scale, so setting the .localScale property is how you would size it to the desired dimensions.
There isn’t a built-in way to easily display an infinite plane, but you could certainly size one to extend past the camera’s far plane to simulate that.
Taking your advice what i have finally did is to instantiate a plane and scale it to fit the requirements,
here is the code:
var angulo = Mathf.Atan2(operationVector.y,operationVector.x)* Mathf.Rad2Deg; //Rotate the plane in the direction of the swipe
plane.transform.localScale.x = operationVector.magnitude *0.00003875; // This transform 1px in screen to the size of the pane
plane.transform.Rotate (0, 0, angulo);
plane.transform.position = camera.ScreenToWorldPoint(Vector3((currentFingerPosition.x+lastFingerPosition.x)/2 ,(currentFingerPosition.y+lastFingerPosition.y)/2,camera.farClipPlane)); //Place the plane in the correct word space