DevilsD
DevilsD

Reputation: 597

How to calculate a random point inside a cube

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.

Upvotes: 0

Views: 587

Answers (1)

user1196549
user1196549

Reputation:

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

Upvotes: 1

Related Questions