# Calculating a dividing plane

This topic is 3763 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Well, once again I turn the brave and bright minds of GameDev.net for a bit of feedback/help on an idea. This one seems pretty simple, so put your vector calculus hat on for a minute. So, I've got two triangles making a square. Each triangle has a fixed XZ coordinate set, but the height for each vertex varies (think: heightmap for terrain). Each square is divided by a line going from the bottom right to the top left. In ASCII art:
o-----o
|   / |
| /   |
o-----o

I need to find which triangle a point is in, topographically. My idea was to create a vertical plane effectively slicing the square along the dividing line. Once I have a plane it would be trivial to determine which side of the plane a point is on. But I wasn't sure exactly how to calculate the plane itself. Here is my idea: I know the XYZ position of each vertex, and therefore, I can find the equation of the line that goes from the bottom right to the top left. I figured I could find a vector that was perpendicular to the dividing line, by doing something like line crossed with the up vector, and use a point on the line (e.g. a vertex of the quad) to calculate the plane. Does this check out mathematically? Does anyone have any suggestions for a better (i.e. faster performance)? I intend on precalculating the plane for each quad and storing it.

##### Share on other sites
Your idea for finding the dividing plane should work. I don't think you'd need to do the actual cross product, though. If (a,b) is a vector pointing along the dividing line (say from bottom-left to upper-right), then (-b,a) is a normal to the plane (it's the vector (a,b) rotated 90 degrees counter-clockwise). In fact, given this vector (-b,a) and a point that's on the dividing line (say the center C of the square, assuming it's a perfect square), then you can just examine the sign of ((x,y) - C) dot (-b,a) to determine which side of the square the point (x,y) is on.

Here's a rough idea:

Project the point onto the xz-plane (just take out the y coordinate). Find the coordinates of the projected point relative to the lower-left corner of the square. Suppose these are (x,z). If arctan(z/x) > pi/4, then it's in the left triangle. If arctan(z/x) < pi/4, then it's in the right triangle. Otherwise it's on the dividing line. If x = 0 (making the inverse tangent undefined), then the point is just along the left-side of the square. This assumes the point is actually in the box. It also assumes the square is indeed a perfect square and not a non-square rectangle.

1. 1
Rutin
45
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633407
• Total Posts
3011699
• ### Who's Online (See full list)

There are no registered users currently online

×