Search code examples
openglgraphics3dgame-physics

how to find slope of a 3D plane


I have a 3D terrain in my scene, I have the location of all the vertices of the terrain.

I want to place any geometry on this terrain procedurally. At the moment I can place the 3D models only on the vertices, as seen in the image below.

If I were to render grass for example in the plane which is highlighted, I need to calculate the slope of the plane, hence the question.

How do one go about calculating slope of a plane in 3D in order to get the coordinates inside the planes which is made by the 4 points? As stated earlier I have all the 4 points which make the plane.

Also Is there any other more efficient way to achieve what I am trying to do [collision detection with the plane may be?]

enter image description here


Solution

  • Turn the rectangles into triangles. That will make many things more simple since the rectangles in your example probably aren't planar.

    Select two sides of the triangle and create two vectors which point along those sides (i.e. v1 = p2 - p1 and v2 = p3 - p1). To get a random point on the, use:

    p = p1 + v1*x + v2*y
    

    where p1 is the common starting point of the two vectors and x and y are random numbers between 0 and 1. If the sum of (x+y)/2 is > 0.5, then the point is outside of the triangle (you could also say that it's in the second triangle).

    Related: