Advertisement

Height calculation on terrain

Started by November 01, 2002 02:24 PM
2 comments, last by ArchMiffo 22 years, 3 months ago
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
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.
It's not what you're taught, it's what you learn.
Advertisement
Thanks!
It''s working perfectly
Wow, I wasn''t even sure.

Glad I could help
It's not what you're taught, it's what you learn.

This topic is closed to new replies.

Advertisement