0
votes

I'm trying to figure out the math to find a random point inside a cube.

I have something small but it can't take into account the rotation of the cube.

Here are some images of my results.

enter image description here

enter image description here

Here you can see the cube is rotated to some degree but when I generate some points it retains the shape as if the cube was normal (I think the term is called axis aligned but I'm not sure).

I'm using a Vector to represent the extent of the cube but for the life of me I can't figure out how to get the points to follow it when it's rotated.

Can someone point me in the right direction as to how I would do this?

EDIT1:

enter image description here

Now its misaligned and it goes even weirder when I rotate it sideways.

Can someone walk me through it from the beginning? I think my base line math is all wrong to begin with.

1
Generate the points in the straight position then apply the rotation.Yves Daoust
Ok i think i did what you suggested but its all out of alignment.DevilsD
I added an image to main threadDevilsD
Check the origin of the coordinates.Yves Daoust
I was adding the worldlocation of the cube before rotating it. Adding it to the rotated vector has aligned it properly.DevilsD

1 Answers

1
votes

Generate the points in the straight position then apply the rotation (also check the origin of the coordinates).