1
\$\begingroup\$

Image attached below for clarification: image

So here we have a plane with a random rotation in 3D space, and we have the values for P1, P2, and the plane normal. How do I find the points X1 and X2?

This quad can have any width/height, any position, and any rotation.

\$\endgroup\$
10
  • 1
    \$\begingroup\$ I think we still have one degree of freedom too many here. With two diagonally opposite points in a plane, there are multiple possible rectangles that could be drawn through them, with different aspect ratios and "twist" about the plane normal. Do you have any additional constraint we can use to pick just one of these rectangles? It may help to explain what this is used for in your game — that application may suggest a metric that makes some rectangles a better choice than others. \$\endgroup\$
    – DMGregory
    Oct 6, 2022 at 13:57
  • \$\begingroup\$ @DMGregory Unfortunately these are all the constraints I have, other than world position and rotation. The two points are random and change at runtime. \$\endgroup\$
    – Pooper
    Oct 6, 2022 at 14:06
  • \$\begingroup\$ Is it OK if we always return a square then? Or do you sometimes want rectangles of different aspect ratios for your application? I'll reiterate that telling us how this is used in your game would help us find suitable solutions. \$\endgroup\$
    – DMGregory
    Oct 6, 2022 at 14:07
  • 1
    \$\begingroup\$ To illustrate the point by @DMGregory, this rectangle would be possible as well: i.stack.imgur.com/ckQnP.png. You would need to know either the aspect ratio of the rectangle or its rotation angle around the plane normal to find out the other two points. \$\endgroup\$
    – Philipp
    Oct 6, 2022 at 14:10
  • \$\begingroup\$ @Philipp Thanks, I can see why that causes an issue. \$\endgroup\$
    – Pooper
    Oct 6, 2022 at 14:15

1 Answer 1

1
\$\begingroup\$

As discussed in the comments, to make this align with the texture displayed on your touch screen object, you'll also need a tangent vector. With that in hand (and assuming your tangent has unit length), we just do vector projection:

Vector3 diagonal = p2 - p1;
float width = Vector3.Dot(diagonal, tangent);
Vector3 side = tangent * width;

x2 = p1 + side;
x1 = p2 - side;
\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .