Advertisement

Finding height on tri (for Terrain)

Started by October 27, 2002 03:11 AM
4 comments, last by VanKurt 22 years, 3 months ago
Hello! Let''s imagine I have a simple triangle: A (0 | Y1 | 0) B (1 | Y2 | 0) C (0 | Y3 | 1) and a point, that is above the triangle (X|Z). How would I find out, at which height the point should be placed (Y), so that it is on the triangle ? Of course I could do that with the help of the plane equation, but it should work faster with interpolation. And because of the fact that it is a rectangular triangle, this should be not too difficult... But I just don''t get that working..... ;-( Can you help me ? Thanx
Y1 + (Y2-Y1) x + (Y3-Y1) z

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
hum, this seems not to work very well...
No matter, thanks!

Other ideas? Thank you
This one is a little better, but sucks also:

a + ((b-a)*fx + (c-a)*fz)/2;


More ideas?? ;-)
Not sure what a rectangular triangle is

Here''s a bit of Pascal for ya!


  function gety(p1: 3Dpoint; p2: 3Dpoint; p3: 3Dpoint; p4: 3Dpoint; getx: single; getz: single): single;begin  result := (getx * getz * p1.y) +            ((1-getx) * getz * p2.y) +            ((1-getx) * (1-getz) * p3.y) +            (getx * (1-getz) * p4.y) ;end;P1---P2|   / ||  /  || /   | P3---P4  


Where getx and getz are the coordinates within the rectangle, both in the range 0 to 1. This works for rectangles, I''m guessing you''re trying to get the height in a heightmap so it would work for that

Mmmh, that looks cool. I''ll check that out soon...

Thaaank you!

This topic is closed to new replies.

Advertisement