Skip to content
Advertisement

Get 3D coordinates of vertices of rotated and scaled cuboid with scale, center position and rotation on all axis

I have been wrecking my brain trying to figure out this problem I have. I have a cuboid, its rotation on all 3 axis in relation to the world from its center (it’s on 3D space), the cuboid’s center’s position and the scale of the cube in all axis (width, height and depth). I need to find the coordinates of all of the vertices of the cuboid.

While browsing the internet, I only found examples for the 2D cases, and couldn’t figure out how to advance to 3D space.

Can anyone help me please? I will use it in a game engine made with LWJGL (Light Weight Java Game Library).

Edit: (for @httpdigest):

JavaScript

This still isn’t accurate, can anyone spot the problem?

Edit: Solution: The angles needed to be in radians, thanks for the support!

Advertisement

Answer

If you are using LWJGL you can also use JOML, in which case the following is probably what you might want:

JavaScript

It computes a transformation matrix M = T * Rx * Ry * Rz * S given the center position, Euler rotations around x, then y and then z and the given scaling factors of the unit axes, and then transforms the positions of the unit cube corners by that matrix via P' = M * P.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement