#### Archived

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

# Help Slacker with Terrain Height?

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

## Recommended Posts

Do I need to use line intersections for something as simple as getting the walking height of the terrain? My terrain is divided into 32.0 x 32.0 sized tiles. The tiles are pretty simple, but can contain several faces in them. None of the faces would overlap on the Y axis. All I want to do is get the Y height of a specific X,Z point in the mesh. Any help or a point in the right direction is appreciated. [edited by - Jiia on May 10, 2004 1:43:59 PM]

##### Share on other sites
I suppose you can calculate it by using some linear interpolation between the y-coordinates of the edges of the tiles.

##### Share on other sites
Well I can''t say specifically how to do it without the source, but first you need to find which triangle in the terrain the point (x,z) is over. Then simply find the plane equation for that triangle which will be y = F(x,z) [to derive plane equations I usually just do something like y = (height of origin of triangle) + (slope along x-axis)*x + (slope along z-axis)*z ].

Anyways forgive me if that doesn''t make sense, but in any case I can always elaborate more.

##### Share on other sites
Assuming that your faces are triangles, I've solved this problem not too long ago using this method:

1) Identify the triangle in your mesh which your X,Z coordinates correspond to.

2) Find the surface normal vector of this triangle. If you haven't precalculated normals for your terrain, then just make two vectors (p2-p1) and (p3-p1) where p1,p2,p3 are the triangle's vertices. Take their cross product to get your normal vector. After that, make this vector's length 1 (normalize it).

3) Solve for the constant D. D = -DotProduct(p1, N) where N is the normal vector from step 2. We now have a plane equation Ax + By + Cz + D = 0 where (A,B,C) is your normal vector and (x, y, z) is any point in the plane (we used p1), and D we just solved for.

4) Back to the initial problem: you know the X,Z but don't know the Y (height) of the terrain point. Given the above equation, solve for it, giving you your height:

height = Y = -(AX + CZ + D) / B

where (A,B,C) is your normal vector, and X/Z are your query coordinates.

[edited by - Schmerm on May 10, 2004 8:20:50 PM]

1. 1
Rutin
22
2. 2
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633306
• Total Posts
3011287
• ### Who's Online (See full list)

There are no registered users currently online

×