#### Archived

This topic is now archived and is closed to further replies.

# Height calculation on terrain

This topic is 5890 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I know this have been asked before but I have never seen any realy good answers. My terrain consists of a grid. When have the three points on that grid that''s closest to the camera i want to calculate the height on the point where the camera is. point1 = [x1,y1,z1] point2 = [x2,y2,z2] point3 = [x3,y3,z3] camera = [X,Y,Z] What do I do next to calculate the cameras Y coordinate given the cameras X and Z and the three points. Thanks

##### Share on other sites
Find the normal of the plane by taking (p2-p1) X (p3-p1) (cross product). Call it vector n=(nx,ny,nz)

Then plug camera X and Z into the equation

nx * X + ny * Y + nz * Z = n * p1 (dot-product)

You get

Y = (n * p1 - nx * cameraX - nz * cameraZ) / ny

I think that''s right.

My vector and plane algebra might be a little rusty.

##### Share on other sites
Thanks!
It''s working perfectly

##### Share on other sites
Wow, I wasn''t even sure.

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
5. 5
A4L
13

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633744
• Total Posts
3013652
×