Box

Started by
6 comments, last by Zakwayda 16 years, 10 months ago
hi, i have some tricky question, i have a box, i want to find the furthest point on that box in a certain direction. for a sphere you do: center + direction*radius is there any direct formula for the box? the way i would do it, form a ray going from the box center, having the direction of the vector, and test it against the plane of the boxes. any better ideas? the box has a center, width, height, and depth. thank you in advance
Advertisement
If you wanted to speed things up a little, (I assume this would be a slightly better way of doing it) you could represent your direction in spherical coordinates, and then project this onto the relevant plane.

For the 2-d case: Assume there is a rectangle around the origin. If your direction is the unit vector (u,v), and in polar coordinates (r, theta), then for theta between 0 and arctan(h/w), your point furthest away is (r*w/cos(theta),theta). For theta between arctan(h/w) and arctan(h/-w), your point is (r*h/sin(theta),theta). And so on. Just draw the unit circle inside the rectangle. There'll be an identical case for 3 dimensions which I can work out later if you still need it. I assumed the box was axis-aligned, but it's not a problem if it isn't.
Quote:Original post by DaBookshah
If you wanted to speed things up a little, (I assume this would be a slightly better way of doing it) you could represent your direction in spherical coordinates, and then project this onto the relevant plane.

For the 2-d case: Assume there is a rectangle around the origin. If your direction is the unit vector (u,v), and in polar coordinates (r, theta), then for theta between 0 and arctan(h/w), your point furthest away is (r*w/cos(theta),theta). For theta between arctan(h/w) and arctan(h/-w), your point is (r*h/sin(theta),theta). And so on. Just draw a circle inside the rectangle. There'll be an identical case for 3 dimensions which I can work out later if you still need it. I assumed the box was axis-aligned, but it's not a problem if it isn't.




umm, it can be any box, can you develop it for 3D please?
The support mapping for an axis-aligned box is simply:
S(v) = (center.x + sign(v.x)width /2,        center.y + sign(v.y)height/2,        center.z + sign(v.z)depth /2)
Or equivalent.

You can find support mappings for various shapes in Gino van den Bergen's book 'Collision Detection in Interactive 3D Environments', as well as in the open-source versions of his SOLID collision detection library.
Quote:Original post by jyk
The support mapping for an axis-aligned box is simply:
S(v) = (center.x + sign(v.x)width /2,        center.y + sign(v.y)height/2,        center.z + sign(v.z)depth /2)
Or equivalent.

You can find support mappings for various shapes in Gino van den Bergen's book 'Collision Detection in Interactive 3D Environments', as well as in the open-source versions of his SOLID collision detection library.




i'll check that out, thank you for your help,
however, what if it wasnt an aligned box? i want it to be general, and what do you mean by sign??? is it the absolute value?
Convert unit vector (x,y,z) to (ρ, φ, θ). Nice picture. Take w=width, parrellel to the x-axis, d=depth parrellel to the y-axis, and h=height for the z-axis dimension of the box. The idea is to split up the area of the rectangle of values (φ, θ) [(0,0),(0,2*pi),(2*pi,2*pi),(2*pi,0)] into smaller regions where you know which plane to project onto in each case.

First case: φ<=arctan(width/height) and -arctan(depth/width) <= θ <= arctan(depth/width), we intersect the plane z=h.

Then you have to go through and enumerate all the cases. I'm not sure how many there'll be - quite a few.

EDIT: Sign function
Quote:Original post by DaBookshah
Convert unit vector (x,y,z) to (ρ, φ, θ). Nice picture. Take w=width, parrellel to the x-axis, d=depth parrellel to the y-axis, and h=height for the z-axis dimension of the box. The idea is to split up the area of the rectangle of values (φ, θ) [(0,0),(0,2*pi),(2*pi,2*pi),(2*pi,0)] into smaller regions where you know which plane to project onto in each case.

First case: φ<=arctan(width/height) and -arctan(depth/width) <= θ <= arctan(depth/width), we intersect the plane z=h.

Then you have to go through and enumerate all the cases. I'm not sure how many there'll be - quite a few.


i guess JYK gave me what i need, thank you though!
I'm not sure that spherical coordinates are the optimal solution to this particular problem...

In any case, the support function for the axis-aligned box that I posted can easily be adapted for an oriented box by first transforming v into the local space of said box. The details will be a little different than the axis-aligned case, but I doubt you'll have much trouble working them out.

This topic is closed to new replies.

Advertisement