Reputation: 199
3d terrain.
I have 3 vertices that define a plane. (the 3 nearest pixels in a height map)
I have an x,z on that plane. (my location in the world)
How do you find the y-intercept? (so that I stand on the surface of that plane)
Upvotes: 0
Views: 1476
Reputation: 2380
You say that you are looking at the three nearest pixels in the height map, which makes me assume that you have a regular grid from which you extract your vertices. In this case, you can use image interpolation methods to perform linear being similar to the answer from eboix or bicubic interpolation. Your height value is then equivalent to the brightness value in the image processing domain. The math is much easier in the linear case, and the grid structure makes it possible to use a simple form. Let c by your cell size, and p, q, r the height values of your 3 vertices, like this
p q
+--.
| /
|/
r
and x, and y the distances along the legs of your right angled triangle. Where the triangle is of course the projection of your 3 vertices on the x, y plane. Then your interpolated height value is
z = (q-p)/c * x + (r-q)/c * y
Upvotes: 0
Reputation: 5133
The equation of a plane is:
Ax + By + Cz = D, where D = Ax0 + By0 + Cz0,
If you have three vertices, find two vectors from the vertices. For example, for three vertices T, U, V, there would be, for example, a vector TU, and a a vector UV.
Find the cross product of the two vectors. That's your normal vector, n, which has three components n1, n2, and n3.
A = n1
B = n2
C = n3
Take one of the points. The coordinates of that point are x0, y0, and z0.
Input this into the equation to calculate D.
Then substitute your x and z for x and z and solve for y!
So in the end y is:
y = (A*x0 + B*y0 + C*z0 - A*x - C*z)/B
Somebody correct me if my algebra was wrong.
You can calculate the cross product like this:
For two vectors a and b, with components a1, a2, a3 and b1, b2, b3, respectively, the cross product is :
which goes to:
A = the coefficient of i-hat (the bolded i)
B = the coefficient of j-hat (the bolded j)
C = the coefficient of k-hat (the bolded k)
Upvotes: 2