2

From the graphic depicted in this question: Check if a point is inside a rectangular shaped area (3D)?

Points $P_1$ and $P_7$ are known. They are opposite corners of the box. I can obtain Min/Max with $Min(P_1, P_7)$ and $Max(P_1, P_7)$. Although I'm not sure I need the actual min/max as long as both points are opposite.

I have a point $P_A$ between $P_1$ and $P_2$ on a vector $\lvert \vec V_2\rvert$ headed towards $P_2$.

How do I determine points $P_2$, $P_4$, and $P_5$?

What I have done so far:

  • Got the center point $P_C$ doing $(P_1$ + $P_7) / 2$.
  • Got and X (pitch) and Y (yaw) angles between $P_1$ and $P_A$.
  • Translated points $P_1$ and $P_7$ using $P_C$ to be center with origin.
  • Rotated the translated points $P_1$ and $P_7$.
  • Assuming the box is now axis aligned, computed $P_2$, $P_4$, and $P_5$ locally.
  • Rotate and then translate $P_2$, $P_4$, and $P_5$ back.

This seems to work. But it seems a bit cumbersome.

Is there an easier way?

My Goal is to "draw" a Box in 3D space that encompasses a room that is already 3D rendered. I'm working with a scripting language that is layered on top, and it gives very limited access. I can add to the environment and I have access to a Vector object, trig functions (sin/cos/tan/asin/acos/atan), cross product, and dot product. I don't have a Matrix, or other tools often found in graphics frameworks.

The room is sometimes axis aligned, and other times it is rotated from origin 45 degrees. Or a different angle. In this case I'm only dealing with Yaw rotation. In another case I may need to also apply Pitch, for going up or down a staircase. I will never need to apply Roll.

Jeff
  • 23
  • Question is not entirely clear. I understand that you know locations of longest diagonal of a cuboid and direction of one of the edges. This is not enough to reconstruct such cuboid if it's rotated. Can you be more specific what is the goal and what are the known quantities? – Radost Aug 06 '20 at 18:51
  • @Radost The end goal is to draw a box in 3D space inside an existing "room" that is already 3D rendered and obtain P1, P2, P4 and P5 for hit detection using the linked question. I have no control the environment itself, but can add to it using a script, which has basic trig functions. Sometimes the room is axis aligned, Sometimes rotated, often 45 degrees. In these cases I'm only dealing with Yaw rotation. If doing a staircase, Yaw and Pitch. Never Roll. – Jeff Aug 06 '20 at 20:02

1 Answers1

1

If your box is axis-aligned, and $P_1 = (x_1, y_1, z_1)$, $P_7 = (x_7, y_7, z_7)$ in world space coordinates.

If $(P_1 P_4)$ is the oriented $x$-axis, $(P_1 P_2)$ is the oriented $y$-axis, and $(P_1 P_5)$ is the oriented $z$-axis.

Then:

$$P_4 = (x_7, y_1, z_1)$$ $$P_2 = (x_1, y_7, z_1)$$ $$P_5 = (x_1, y_1, z_7)$$

Simple right ? That's the interest of axis-aligned bounding boxes in a nutshell: you can define all vertices of your cuboid with just 2 vectors, and they give minimal computations (not just to find the vertices of the cuboid; they simplify intersections with the cuboid faces/planes as well, intersection becomes a simple bounding of a value between two others).

In any other case (not axis-aligned), you're going to need to handle at least rotations.

You're asking if there's a simpler way to do things... In the language of graphics pipelines, if your AABB is aligned in object space rather than world space, you'll generally use the "homogeneous model" (an embedding of $\mathbb{R}^3$ into a special version of $\mathbb{R}^4$) in order to convert a combination of rotation+scaling+translation of your object into a linear operation (since translations are not linear maps, as they move the origin of your vector space) to transform your data from world space to object space, and do your AABB intersections in object space.

This scheme (using a 4*4 matrix to translate a non-axis aligned box into an AABB) can be generalized to any two spaces. However, if your pipeline structure is not well thought-out, that might actually make you have extra computation, and oblique plane intersections in world space (or "unaligned space") might be faster to render than object space (or "aligned space").

AABBs are used in general to avoid having to do extra computations: if my ray doesn't even hit the surrounding AABB, it has no chance of hitting the curved object it contains (say a sphere, a 3D triangle-based model or a 3D fractal, for which intersections are much more costly to compute). This small extra check can often remove lots of costly computation.

  • I updated my question with some more specifics of what I'm trying to do. So from what you're saying, translation and rotation is the solution? I was hoping perhaps I could use a cross product. I was able to get Vectors from P1 towards P2, P4, and P5, but my problem is establishing the width/height/length of the box. I was hoping that by asking the user for P7 I could establish that. Which is sounds like I can, but not with normalized vectors coming from P1. – Jeff Aug 06 '20 at 20:10
  • You get the dimensions of an AABB by doing $P_7 - P_1$: the absolute value of each coordinate is the dimension of the AABB for the corresponding axis. If you're not allowed to use matrices, I suggest just doing the operations to-and-from by hand. Ie, first rotate (cos & sin), then translate (+t), to get from your not-aligned cuboid to your AABB (you'll need to apply these operations for your rays as well); then do the inverse operation if your rays have to bounce: first the opposite translation (-t), then the opposite rotation (cos & sin). – Tristan Duquesne Aug 06 '20 at 22:20