- Home /
The question is answered, right answer was accepted
What exactly is the Vector3.ProjectOnPlane documentation saying?
Hello all,
Please forgive the noob question, but could someone please explain to me what exactly the documentation on Vector3.ProjectOnPlane (Vector3.ProjectOnPlane) is saying. Again, please forgive the noobishness of this question.
Thank you for reading.
Godfrey
Answer by Stratosome · Jul 23, 2018 at 08:37 AM
Yay, I know this one!
Alright, so, a normal of a plane is just the vector pointing outwards from its surface. We could even just represent that plane (of infinite length and width) with that one normal vector. So, a projection is if you were to take a vector and lay it down onto the plane kind of. Here is an image showing it better:
Looking at the function Vector3.ProjectOnPlane, it takes in vector and plane normal. Using the picture as a reference, the dotted line is the plane normal that is being used to represent that WHOLE plane. the vector parameter is the x vector in the image. The return of calling this function is the nice little blue vector. It has been placed onto the plane, but note that it doesn't fall onto it like a pencil. It falls straight down on it, so it may get squished a bit.
So, to reword what it the documentation is saying, it is projecting the given vector (laying it down) on the plane that is being defined by the plane normal. Normal orthogonal just means it is a right angle vector from the plane's surface.
And no need for forgiveness. It is using a bunch of fancy math terms to make the description of the function short and sweet. ;)
I may should add that just a normal vector can only describe a plane that is located / goes through the origin. So the vector you're projecting is a direction vector. Note that "origin" does not necessarily mean the world origin. Like every vector it's all a matter of interpretation. The vector (0,1,0) is the up vector in worldspace. However when interpreted in local space it may point in a different worldspace direction based on the rotation of the object. This of course requires some understanding of coordinate systems and spaces.
Please note that Unity Answers is for Unity related questions (this question here is one, so don't worry). Though if the source of your problems is lacking some basic concepts not directly related to Unity you should first study those. We can't $$anonymous$$ch every aspect about program$$anonymous$$g, math, geometry and computer science from ground up. We also have the help room which is meant for borderline questions. The help rooms is meant for more general questions which are only partially Unity related. It's a place to get assistance for example with a debugging problem.
Hello @Stratosome,
So I studied your answer for a while, and would like some correction to my understanding whenever you can manage. Say we have a scene with a flat plane called "plank", such that the plank's z-axis is parallel with the world (horizontal) XZ plane. Then placed a character called "spider" upright on that plank. Then got a direction vector from user input (Input.GetAxis), and wanted that direction to be relative to the current surface (plank) on which the spider crawls. Now based off my understanding of your explanation, if i converted the direction to the spider's space (local axes), and assu$$anonymous$$g the spider is perfectly upright on the plank, then a) The (new) direction's normal would define/create a plane that's the same as the plane created by the normal of the plank? Secondly, if i were to create a sphere called "skull" on top of the plank, and wanted the spider to move about on the surface of the skull, then b) Passing the input direction vector and the skull normal to Vector3.ProjectOnPlane() would return the corrected direction for movement on the skull? Is this what is meant by projecting the (direction) vector onto a plane (i.e. skull surface)? $$anonymous$$g. directionOnSkull = Vector3.ProjectOnPlane(inputDirection, skullNormal).
I know my example is a bit convoluted, but without a proper grasp, i was unable to come up with a simpler one. Anyway, i'd like to thank you for your answer, it is great.
Cheers
Godfrey
Oh and if you were to rewrite that 'Description' phrase in the documentation. Would it be correct to rephrase it from "Projects a vector onto a plane defined by a normal orthogonal to the plane", to "Projects a vector onto a plane defined by a normal that is orthogonal to the plane"?
Godfrey
Yes, your two sentences say 100% the same thing. The term "normal" does already imply that it's orthogonal to something otherwise it wouldn't be a normal. This is more a matter of english grammer than about anything technical. Both sentences express exactly the same thing. The "that is" is already implied.
Hola again (sorry, I got in an hour of sleep for my night hah),
I think I followed that. Yeah, actually, I believe that would be true and possible using Vector3.ProjectOnPlane. This isn't something I had actually done or thought about really, but I think you've got the right idea. If you get the player input and make it relative to the spider, you could use the Vector3.ProjectOnPlane function to then find the proper direction of movement? This is the kind of thing that I would test myself before attempting to help someone else with that, but it sounds reasonable. To get that normal on the surface, you could shoot out a raycast from the bottom of the spider to see what the ray hits. After getting the projection (the new vector) you could then normalize it to make it actually a simple direction vector. Eh, hopefully I said a few useful words in there hah. Like I said, this is the kind of thing I'd want to do myself first but I've got a lot going on, so I'm not sure if I'd have the time to get around to it.
Short answer though is yes, I believe that kind of thing would work.
I was scratching my head on this one. Thank you for clarifying!