4
\$\begingroup\$

I would like to clip a triangle if its bounds lie partially out of a cube. I guess I would need some kind of Triangle Plane intersection code - I'm not well versed with math but I do have the points of the triangle in 3d space (P1, P2, P3).

How do I get the 2 points of intersection of the triangle with one of the planes of the cube?

\$\endgroup\$
1
  • \$\begingroup\$ Is your triangle a surface? In which case, you may have a line of intersection between two planes. \$\endgroup\$ Commented Feb 8, 2011 at 22:25

2 Answers 2

5
\$\begingroup\$

If cube is axis-aligned, then it's easy.

You can compare each vertex of triangle with each face (plane) of cube. If it's out of cube (just compare apropriate coordinates), then find two new points, which lie on line connecting two other vertices with that one out of cube and which lie on plane (their coordinate is same as the plane). This is common linear interpolation. So I think you would handle it.

But you should be aware of case, which is on picture. Everytime choose point, which is closer to vertex, which is not out of cube (inner vertex). Choose green point, not red (which is closer to vertex out of cube). triangle plane intersection

Well. And if cube is not axis-aligned, you can look here: http://www.softsurfer.com/Archive/algorithm_0105/algorithm_0105.htm#Triangle-Plane

There is intersection of triangle and plane (not axis aligned). You can use it and test it with all cube faces.

I hope I answered your question. If not, then punch me and ask again :)

\$\endgroup\$
3
  • 3
    \$\begingroup\$ Next time you can try to find something here: realtimerendering.com/intersections.html \$\endgroup\$ Commented Feb 9, 2011 at 0:06
  • \$\begingroup\$ Many thanks for the answer, I decided to change my strategy and do some intersection check in 2d rather than 3d, but I'm still clueless about them math? \$\endgroup\$ Commented Feb 9, 2011 at 13:21
  • \$\begingroup\$ My new question is gamedev.stackexchange.com/questions/8326/… \$\endgroup\$ Commented Feb 9, 2011 at 13:47
0
\$\begingroup\$

A good explanation of a solution can be found at http://geomalgorithms.com/a06-_intersect-2.html:

1) Use the dot-product to determine whether the triangle lies fully on one side of the plane and does not intersect the plane at all.
2) If there is an intersection, use a line-plane-intersection-algorithm for the two edges hitting the plane (algorithm on the same page)

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.