How to work out the height of a point on a tilted surface?

I have a plane which gets tilted on the X and Z axis (y+ is the normal).

Given an X and Z coordinate and the X and Z rotation of the plane, how do I find out the height (Y) at that point?

I assume this is a trigonometry question... I could use simple sin & cos to work it out if it was moving on just the X or Z axis, but what if it's at 3,8 (x,z)? Maybe an average of the sin/cos heights?!

Assuming your plane passes through the origin, then it can be defined in terms of its normal vector as the set of all points perpendicular to the normal, ie.

dot(position, normal) = 0


Here your normal is the object's local y-axis, transform.up.

So you want to find a coordinate triple (x, y, z) perpendicular to transform.up. We can solve:

dot((x, y, z), transform.up) = 0
y * transform.up.y + dot((x, 0, z), transform.up) = 0
y * transform.up.y = -dot((x, 0, z), transform.up)
y = (-x * transform.up.x - z * transform.up.z)/transform.up.y


And now we have an expression for y in terms of x & z, without using any transcendental functions, just ordinary multiplication subtraction and division. :)

• THANK YOU @DMGregory!!! That is absolutely perfect and exactly what I need. I need to read up on how best to use the dot() command. – Nick Nov 20 '16 at 20:47

Ah - looks like you just add them together!

float angX = Mathf.Sin(Mathf.Deg2Rad * transform.eulerAngles.z);
float angZ = Mathf.Sin(Mathf.Deg2Rad * transform.eulerAngles.x);

foreach(GameObject item in GameObject.FindGameObjectsWithTag("Fart")) {
float yx = fart.transform.position.x * angX;
float yz = fart.transform.position.z * -angZ;
item.transform.position = new Vector3(item.transform.position.x, (yx + yz), item.transform.position.z);
}

• This looks a bit sketchy to me. Have you tried it with large angles? Some approximations hold decently well for shallow angles but blow up once the object tilts further. – DMGregory Nov 19 '16 at 6:54
• You're right; in my case, as the item moves across the plane, this becomes less accurate. My plane only moves on a +/- 15 degree tilt, so it wasn't initially obvious. – Nick Nov 20 '16 at 20:43