What kind of interpolation does PhysX or Unity use for heightfields? There is a total paucity of code out there for Heightfields, and I can't quite figure out how to implement one.
Heightfield
Also the question doesn't make sense (just like the older post linked by Lactose). You need to explain what you're asking about.
PhysX defines exactly how it does intersection testing to heightfield triangles in its documentation.
You sample the 3 vertices from the heightfield that forms a triangle around your position, and then calculate the height of the triangle at that position.
Not sure why you would do that manually when you have PhysX though.. as there's a method to get the height anywhere in the height-field, the getHeight(x, y) method.
I'm sure Unity has similar methods exposed to scripts, a quick Google shows TerrainData.GetHeight(x, y).
If you need to do it manually, you have to do the same triangle-grid as PhysX does. Each triangle forms a plane, the height of which you should be able to easily calculate when you have a position (calculate intersection of the plane along the vertical line at that position).
If you need to do it manually, you have to do the same triangle-grid as PhysX does. Each triangle forms a plane, the height of which you should be able to easily calculate when you have a position (calculate intersection of the plane along the vertical line at that position).
One interesting mathematical trick is using a determinant to check if 4 points in R^3 are coplanar:
(x1 y1 z1 1)
det(x2 y2 z2 1) = 0
(x3 y3 z3 1)
(x4 y4 z4 1)
In your case, you know everything but z4. So expand that determinant along the last row and you get a formula with this shape: x4 * det(...) - y4 * det(...) + z4 * det(...) - det(...) = 0
Now computing the value of z4 is trivial.
PhysX only expose the elevation for the specific posting on the heightfield. You supplied the data to PhysX so you will have to do the work yourself to figure out the inter-post elevation. Interpolating between the posted elevation sample should work. I suppose you could hack it by doing a raycast against the terrain and using the resulting position as a source for your elevation providing, there is no elevation scaling.