Reputation: 13
After thinking about this for a while, it seems like there are 3 main cases:
And there are 2 unlikely cases where the two are perpendicular when the intersect:
However identifying these cases hasn't really gotten me closer to a solution. I'm hoping someone can point me in the right direction for how to solve this problem. I want to solve it fast for a small number of rectangles x a large number of triangles.
Context: the larger problem I'm trying to solve is I want to wrap a rectangle around a closed polygonal mesh. I wish to do this step by step by rotating the rectangle until it intersects, then rotating the remaining rectangle around the intersection point, etc.
Upvotes: 0
Views: 327
Reputation: 29126
When you rotate a rectangle around one of its sides, you get a cylinder. Intersect each of the lines with the cylinder. The position of the intersection points gives you the rotation angles. Since this doesn't catch the case where the triangle is completely contained within the cylinder, test whether the vertices' distance to the cylinder's axis is smaller than the cylinder's radius, too.
Say your rectangle has the vertices A
to D
. You want to rotate around the side AB
. The radius of your cylinder is then r = |AD|
.
First, transform the coordinates so that the rectangle is placed with the side that you want to rotate about along the z
axis and the adjacent side along the x
axis.
A′ = {M} · A = {0, 0, 0}
B′ = {M} · B = {0, 0, |AB|}
C′ = {M} · C = {r, 0, 0}
Apply the same transformation {M}
to the vertices of the triangle.
Now find the intersections of all three sides of the triangle with the cylinder. Because the cylinder is aligned to the z
axis, the problem can be separated into two subproblems: (1) Find any intersections with the top and bottom surfaces a z == 0
and z == |AB|
. (2) Find the intersections with the "coat" of the cylinder; this is the intersection of a line with a circle in the xy
plane.
You can then calculate the rotation angles with the tangent function of the y
and x
coordinates of these points as atan2(y, x)
.
If you need the coordinates of the intersection points in the original coordinates, don't forget to undo the transformation.
Upvotes: 1