# GM:S 1.4 Maths | Quadrilateral - Height at point given 4 corners

Discussion in 'Programming' started by Pandavim, Jun 26, 2016.

Tags:
1. ### PandavimMember

Joined:
Jun 20, 2016
Posts:
34
Hey everyone! (sorry for asking so many questions on this forum)
I've been working on an isometric engine with height in it. What I've done so far V I tried summing up the question in the title, but in much more detail: I have a quadrilateral, each point is at a certain height, if I'm given the point on the quadrilateral (from above), how would someone calculate the height of that point. Thanks!

2. ### jo-thijsMember

Joined:
Jun 20, 2016
Posts:
2,844
Why would you be sorry for asking many questions on the forum?

Anyway, if I understand you correctly, you've got a bunch of points at certain heights.
You then divide the entire field into quadrilaterals with the given points as vertices.
You now pick a random point on the field and you want to know what height it has.

With this information, it is impossible to determin the height of a random point.
You will need to define a correlation between the height of a random point
and the heights of the vertices of the quadrilaterals on which the random point lies.

You could say you want a linear interpolation between the points,
but then you'll get inconsistent results when the 4 vertices are not coplanar.
And even if they are coplanar, they can still give inconsistent results.

So, you probably won't be able to use linear interpolation,
but then what do you want to use?

Pandavim likes this.
3. ### icuurd12b42TMC FounderGMC Elder

Joined:
Apr 22, 2016
Posts:
1,840
if the 4 points are on the plane (coplanar), you can use a point to plane distance function
if the 4 points are not on the same plane like it's 2 different triangles, but form the shadow it does not look like they are, they you need to figure out which triangle you are on to figure out the plane data to use...

Making the points co-planar is a little tedious beccause you have to smooth the points until they are "flat" enough on the plane but it makes for faster grid lookup

the resust is a fast lookup, in this case one check in the middle of the tank is good enough. minor errors here and there

In my case I got a grid, top down all the grid cells are the same size. each cell holds an array of 4 points for the 4 corners the cell covers, each point is an array of 3 elements, x,y,z. when I create the terrain I average the cells corner points with the connected neighbour cells points iteratively like 8 times until all the points are relatively co planar

Pandavim and jo-thijs like this.
4. ### PandavimMember

Joined:
Jun 20, 2016
Posts:
34
Ah I see, thanks!