These forums are CLOSED. Please visit the new forums HERE
vector mathematics problem |
|
|
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
|
05-09-2008 19:49
It's been a long while since I've picked at vector algebra/calculus, so please excuse me if the solution is rather simple. I have a set of bounding boxes (stored in ordered pairs in a list), and I need to know if a line drawn between two given points passes through any of those bounding boxes
_____________________
My SLExchange shop
Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not. The function is working perfectly fine. It's just not working the way you wanted it to work. |
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
05-09-2008 20:30
This is a raytracing problem. See:
http://en.wikipedia.org/wiki/Ray_tracing If your bounding boxes are aligned with the global x, y, and z axes the equations become pretty simple, but you'll still need to test for intersection with each of the six faces of the box. To do that you'll cast the ray to the planes of the sides that are perpendicular to say the x axis, then test the y and z location of the intersection point to see if it is in the bounds given by the other faces. Then repeat for y and z. |
|
Nexii Malthus
[Cubitar]Mothership
Join date: 24 Apr 2006
Posts: 400
|
05-09-2008 23:36
Maybe this can help: https://wiki.secondlife.com/wiki/Geometric
_____________________
![]() Geometric Library, for all your 3D maths needs. https://wiki.secondlife.com/wiki/Geometric Creator of the Vertical Life Client |
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
05-10-2008 02:03
I have a set of bounding boxes (stored in ordered pairs in a list), and I need to know if a line drawn between two given points passes through any of those bounding boxes Could you settle for the distance box(center) to line? That would be pretty much more simple _____________________
From Studio Dora
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
05-10-2008 11:02
Well, here's how you find the intersection between a ray (starting at 'origin' with a unit tangent vector of 'dir') and a bounding box aligned with the global x, y, and z axes (box defined by minXYZ.x <= x <= maxXYZ.x, minXYZ.y <= y <= maxXYZ.y, minXYZ.z <= z <= maxXYZ). Here I assume you won't be interested in intersections "behind" the origin point. This returns the distance to the nearest intersection, or a negative number if there is no intersection. (Hasn't yet been compiled; may need minor syntax fixes.)
CODE
|
|
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
|
05-10-2008 12:19
thanks to all who've replied. The script posted will be a great starting point, but I will have to extrapolate it to function with objects that are rotated.
_____________________
My SLExchange shop
Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not. The function is working perfectly fine. It's just not working the way you wanted it to work. |
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
05-10-2008 22:52
Okay. Here is a modified version. This time, boxCenter is the center of the box in global coordinates, boxSize is the total size of the box on its local axes (like what llGetScale() would give you), and boxRot is the rotation of the box relative to the global coordinate system.
(Not yet compiled; may require some syntax fixes.) CODE
|
|
Jaxx Tardis
Registered User
Join date: 9 Oct 2006
Posts: 11
|
05-19-2008 17:28
Amazing bit of work. I'm trying to find the inverse, outside looking in at a distance up to 30 meters? So, define the box location and size and then shoot rays from an external vector. I've written something like what i need using the SL physics engine but as you would understand that has proven to be a less than ideal solution (not to mention incredibly slow).
This script seems to be assuming your ray source exists within the defined box and then returns the distances to the walls from the inside? Or is there a depth modifier I'm overlooking? |
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
05-19-2008 20:06
Actually the code should find ANY intersection between the ray and the box as long as the intersection is in front of the origin point (meaning if your eye was at the origin, it would find intersections you are looking at, but not ones behind your head). It should always find such an intersection when you are inside the box. It may or may not find a suitable intersection when the origin is outside the box, depending on where the origin is and the direction the ray is pointing relative to the box.
|
|
Jaxx Tardis
Registered User
Join date: 9 Oct 2006
Posts: 11
|
05-19-2008 20:59
I'll experiment more, only had half an hour to play with it before i had to DJ an event tonight. Here's the scenario i'm trying to render...
The point of origin exists outside of the box on an xy grid, it fires off the rays toward standard spaced blocks (0.25x0.25 meters is the spacing). i fire a ray toward one of the grid points and need to find out if it passes through box (target) and if so, where. I might have something odd in my rotation math, should the beam direction be entered in radians or degrees? |
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
05-20-2008 00:12
The beam direction should be a unit vector. A ray is generally described as an origin point and a vector pointing in the direction of travel. For example, an origin of <1,1,1> and a direction of <0,0,-1> would be a ray starting at one along each of the three axes and pointing straight down in the direction of the negative z-axis. All points <1,1,z> with z<1 will be on this ray.
To find the point at which the intersection occurs, just take the distance along the ray (as returned by the ray tracing function I posted above) and plug it back into the equation of the ray: origin+distance*direction. |
|
Jaxx Tardis
Registered User
Join date: 9 Oct 2006
Posts: 11
|
05-20-2008 08:13
Thank you for all your help, after posting I started thinking (yes i actually am capable of such a thing) and realized how to make it work. Thank you for a very handy little snip of code, and for letting me say neener neener to those who told me a raytrace function was impossible in LSL.
|
|
Nexii Malthus
[Cubitar]Mothership
Join date: 24 Apr 2006
Posts: 400
|
05-21-2008 07:37
Hey Hewee, mind if I add that under the Geometric Library? Would be a superb addition since I haven't made any box functions yet. Credit goes to you of course.
_____________________
![]() Geometric Library, for all your 3D maths needs. https://wiki.secondlife.com/wiki/Geometric Creator of the Vertical Life Client |
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
05-21-2008 08:21
Hey Hewee, mind if I add that under the Geometric Library? Would be a superb addition since I haven't made any box functions yet. Credit goes to you of course. Go for it. ![]() |