-1

As the title suggests, I am trying to find the height of an arbitrary point in a triangle given the height of the vertices of that triangle. The triangle would be a polygon in a height map and the point I need to find would be the height I need to assign to the player.

I have searched methods like Barycentric Coordinates and Bilinear Interpolation, but I can't seem to find how to actually implement them using C#.

Here is a visual of what I am trying to find:

Example

I am trying to find the height of the red dot using the heights of the vertices, which in this case are 4, 5 and 2

Spektre
  • 49,595
  • 11
  • 110
  • 380
Matttske
  • 9
  • 1
  • 1
    Does this answer your question? [Linear interpolation of three 3D points in 3D space](https://stackoverflow.com/questions/18755251/linear-interpolation-of-three-3d-points-in-3d-space) – user4157124 Jun 03 '20 at 21:42
  • Yes, thank you, I was able to solve it using DanialKO's answer. I tried posting the same thread myself as well before but the post got deleted for some reason. – Matttske Jun 05 '20 at 06:21

1 Answers1

0

I would start with a generic triangle-ray intersection algorithm. Assuming your point is in x,y coordinates you would use origin = x,y,0 and direction 0,0,1. You can then simplify a bunch of the operations since you will know that some of the parameters are always zero.

There might be some clever math that could be used to make it even faster, but that is the approach I would take, and performance would probably more depend on putting triangles in some fast search structure than optimizing the intersection test..

JonasH
  • 28,608
  • 2
  • 10
  • 23