POV-Ray : Newsgroups : povray.off-topic : Math question (inside box) Server Time
28 Jul 2024 20:31:12 EDT (-0400)
  Math question (inside box) (Message 11 to 19 of 19)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Patrick Elliott
Subject: Re: Math question (inside box)
Date: 6 Aug 2013 00:11:20
Message: <52007768$1@news.povray.org>
On 8/5/2013 4:38 AM, scott wrote:
> There are much easier, well documented, ways for doing bounding box
> tests, you don't need to go into splitting it up to squares and
> triangles and measuring areas as you seem to have done. If that's what
> you want to do?
>
Yeah, basically. What I searched google for was, basically, "Find if 
point is in a box". And, well, adding "in 3D" didn't seem to help much. 
lol I completely forgot to search on "bounding box". :p

My actual theory here though, if its more understandable, was like.. If 
you had an aquarium, which you could look into, from any two sides, and 
a 90 degree angle from each other, but you couldn't get around to any of 
the other sides, and you needed to "prove" mathematically, that an 
object in it was "actually" in the aquarium, and not outside.

So, logically, you take two sides, that are at 90 degrees from each 
other, than mathematically test of you can "see" the object from those 
two sides, "inside" of the rectangle each side represented.

In principle, this should work. What I screwed up with was that I need 
two sets of calculations. One set is other original, from here (if your 
mouse is in the box, the box turns red):

http://www.emanueleferonato.com/2012/03/09/algorithm-to-determine-if-a-point-is-inside-a-square-with-mathematics-no-hit-test-involved/

Then, completely screwed up, by trying to reuse the same exact 
equations, for both sides (or, rather, the same "components" of the 
vectors).


Post a reply to this message

From: Patrick Elliott
Subject: Re: Math question (inside box)
Date: 6 Aug 2013 00:20:50
Message: <520079a2@news.povray.org>
On 8/5/2013 4:43 AM, Le_Forgeron wrote:
>
> The test against 6 planes would work, and is easy if it is axis aligned.
 > ...
> What I said was that extending the "smart" 2D triangle-based-tests to 3D
> are to be a nightmare.
>
Still not seeing why two planes wouldn't, see my "is it in the aquarium" 
explanation from my reply to scott.

But, in any case, I think there may be a simpler solution, which, like 
my original thought, only requires "adjusting" the location of the 
object being tested for, by canceling its apparent rotation (or, rather, 
getting it lined up so its where the box would be, if the box wasn't 
rotated either), and, it doesn't require a box at all, just an angle 
test, and a distance (which depends on the angle). It does require some 
checking, to make sure they are actually within the allowed angles, but..

Hmm. Actually, now that I think of it, that also have issues.. I am 
thinking I need to check the distance, as per "directly in front" of 
something, like a big door, but the "center" might be, itself, several 
meters over the ground, so.. I need draw a "wall" with a piece of chalk, 
on string, attached to a fixed "center point", not just a line... Sigh.. 
Why does 3D have to get so complicated? lol


Post a reply to this message

From: Patrick Elliott
Subject: Re: Math question (inside box)
Date: 6 Aug 2013 01:40:10
Message: <52008c3a@news.povray.org>
On 8/5/2013 9:00 PM, Patrick Elliott wrote:

> avPos = llDetectedPos(0);
> cPos = llGetPos(0);
> ab = llGetAngleBetween(avPos, cPos);
> TestDistance = ???(ab) * 5;

Range = 5;
TestDistance = (Range - x * cos(ab)))/sin(ab);

So.. How do I get that to make a "wall" instead of just a 2D line? Use z 
in a second one, then check both?

Uh, coordinate system they use is Z = up.

No, wait, that just give me a plain, without telling me if its inside 
the box on that plane.. Sigh.. Right back to having to test if its in 
the box... Suppose, combining the two..

:head-> desk, head-> desk, head-> desk, head-> desk, head-> desk, ouch!: lol


Post a reply to this message

From: Le Forgeron
Subject: Re: Math question (inside box)
Date: 6 Aug 2013 02:16:34
Message: <520094c2$1@news.povray.org>
Le 06/08/2013 06:20, Patrick Elliott a écrit :
> On 8/5/2013 4:43 AM, Le_Forgeron wrote:
>>
>> The test against 6 planes would work, and is easy if it is axis aligned.
>> ...
>> What I said was that extending the "smart" 2D triangle-based-tests to 3D
>> are to be a nightmare.
>>
> Still not seeing why two planes wouldn't, see my "is it in the aquarium"
> explanation from my reply to scott.

the "Aquarium" is using projections (2) and has hidden implication (the
projections are at 90° angle).

you could as well use only 1 projections and an additional "distance
from point to its projection".
Your main issue so far is projecting on arbitrary rotated plane/square.
and it won't be easy.

> 
> But, in any case, I think there may be a simpler solution,

Simpler than evaluating the sign of 6 first-degree equations ?
P(x,y,z) the point to test,
 Vn(An,Bn,Cn,Dn) [n:1 to 6], the 4D vector representing the planes of
the box (oriented so that inside is >0)
 are all signs of x.An+y.Bn+z.Cn+Dn positive ?

the plane XY at height z=10 is <0,0,1,-10> (or in the opposite direction
<0,0,-1,10> ), where is the difficulty ?

-- 
Just because nobody complains does not mean all parachutes are perfect.


Post a reply to this message

From: scott
Subject: Re: Math question (inside box)
Date: 6 Aug 2013 06:19:11
Message: <5200cd9f$1@news.povray.org>
> Or, in the specific case that led me to hunt for a solution, they can't
> be a) on the wrong side of a counter, b) farther than 3 meters from the
> safe, c) outside the building (i.e., behind the thing), or d) standing
> on the other side of the wall, near the safe (SL lets you pan you camera
> through things, with some of its controls, so you can't stop them
> clicking the thing, through a wall. This means a very narrow range of
> "usable" space, and distance. And the "alley" I need to test, is not
> much wider than the safe itself.

Sounds to me like you just have to bite the bullet and define a custom 
bounding box (or group of bounding boxes if the shape you want isn't a 
box) for each object.

FWIW most 3D games work like this, each object has the geometry, and 
then also some form of bounding object (far less complex than the 
geometry) for the purposes of collision detection. It looks like you 
want something similar, a bounding object that defines the space within 
which you can interact with the object.


Post a reply to this message

From: Patrick Elliott
Subject: Re: Math question (inside box)
Date: 6 Aug 2013 21:19:24
Message: <5201a09c$1@news.povray.org>
On 8/6/2013 3:19 AM, scott wrote:
>> Or, in the specific case that led me to hunt for a solution, they can't
>> be a) on the wrong side of a counter, b) farther than 3 meters from the
>> safe, c) outside the building (i.e., behind the thing), or d) standing
>> on the other side of the wall, near the safe (SL lets you pan you camera
>> through things, with some of its controls, so you can't stop them
>> clicking the thing, through a wall. This means a very narrow range of
>> "usable" space, and distance. And the "alley" I need to test, is not
>> much wider than the safe itself.
>
> Sounds to me like you just have to bite the bullet and define a custom
> bounding box (or group of bounding boxes if the shape you want isn't a
> box) for each object.
>
> FWIW most 3D games work like this, each object has the geometry, and
> then also some form of bounding object (far less complex than the
> geometry) for the purposes of collision detection. It looks like you
> want something similar, a bounding object that defines the space within
> which you can interact with the object.
>
>
Yeah, that was.. kind of what I thought I was doing, just.. really 
badly. lol


Post a reply to this message

From: Patrick Elliott
Subject: Re: Math question (inside box)
Date: 6 Aug 2013 22:07:01
Message: <5201abc5$1@news.povray.org>
On 8/5/2013 11:16 PM, Le_Forgeron wrote:
> Le 06/08/2013 06:20, Patrick Elliott a écrit :
>> On 8/5/2013 4:43 AM, Le_Forgeron wrote:
>>>
>>> The test against 6 planes would work, and is easy if it is axis aligned.
>>> ...
>>> What I said was that extending the "smart" 2D triangle-based-tests to 3D
>>> are to be a nightmare.
>>>
>> Still not seeing why two planes wouldn't, see my "is it in the aquarium"
>> explanation from my reply to scott.
>
> the "Aquarium" is using projections (2) and has hidden implication (the
> projections are at 90° angle).
>
> you could as well use only 1 projections and an additional "distance
> from point to its projection".
> Your main issue so far is projecting on arbitrary rotated plane/square.
> and it won't be easy.
>
>>
>> But, in any case, I think there may be a simpler solution,
>
> Simpler than evaluating the sign of 6 first-degree equations ?
> P(x,y,z) the point to test,
>   Vn(An,Bn,Cn,Dn) [n:1 to 6], the 4D vector representing the planes of
> the box (oriented so that inside is >0)
>   are all signs of x.An+y.Bn+z.Cn+Dn positive ?
>
> the plane XY at height z=10 is <0,0,1,-10> (or in the opposite direction
> <0,0,-1,10> ), where is the difficulty ?
>
Ah, I see. Your looking at 'ax + by + cz - d = 0' It should be - for the 
last term, right, to be correct, or is it + because of what you are 
trying to do with it? The dots, instead of * threw me there, for a second.

Hmm.. I need to work out "where" the planes are, to test them, and that 
means the vector normal for it, which is dependent on the object 
rotation, right? So.. Which, if I am right, means I don't need to even 
know where the corners are (which was a "big") problem, when the thing 
was rotated.

norm = llVecNorm(<1,0,0> * llGetRot() * dist);

would give me "one" plane, and I can get another from that too, with a 
farther/shorter distance, where the results are <norm.x, norm.y, norm.z, 
dist> and <norm.x2, norm.y2, norm.z2, dist2>, but the I need to find the 
vector normals for the other four sides.

Mind, such a test could handle even non-box results, like trapezoids, 
but requires.. Ah, I know.. I need to just add in a rotation for the 
axis I want to test my other "sides" against, which are at:

llVecNorm(<1,0,0> * llGetRot() * <90,0,0> * dist3);
llVecNorm(<1,0,0> * llGetRot() * <90,90,0> * dist4);
llVecNorm(<1,0,0> * llGetRot() * <90, 180,0> * dist5);
llVecNorm(<1,0,0> * llGetRot() * <90,270,0> * dist6);

(or the quaternion equivalent, since Euler will go batshit if I try to 
rotate two axis at once, using their conversion functions...)

Realizing that,
dist1 = from the door/object.
dist2 = length of bounding box.
dist3 = left distance, from center of bounding box.
dist4 = up distance, from center of bounding box.
dist5 = right distance, from center of bounding box.
dist6 = down distance, from center of bounding box.

Or.. which ever directions those are.. ;) It doesn't matter though, 
since its still going to be right, I think. Unless I got the 90 degree 
angle I need to also twist around wrong, somehow). Yeah, that is doable, 
I think.

Hmm. Wait, that gives me planes, but.. how does the test happen? 
Actually, I think you may have really lost me, or I missed something, or 
you assumed I had a clue about something I didn't, or.. something.. lol


Post a reply to this message

From: scott
Subject: Re: Math question (inside box)
Date: 7 Aug 2013 05:11:52
Message: <52020f58$1@news.povray.org>
> Mind, such a test could handle even non-box results, like trapezoids,
> but requires.. Ah, I know.. I need to just add in a rotation for the
> axis I want to test my other "sides" against, which are at:

Indeed, the multiple-planes approach can handle any convex object. If 
you want a concave object (eg an "L" shape) you need to split it up in 
to multiple boxes and test each one separately.

> Hmm. Wait, that gives me planes, but.. how does the test happen?
> Actually, I think you may have really lost me, or I missed something, or
> you assumed I had a clue about something I didn't, or.. something.. lol

Once you've got the equations for your planes (ie Ax+By+Cz+D=0) then you 
plug in your point position for xyz and evaluate the result.

If the result is 0 then the point is exactly on the plane, if it's >0 
it's on one side, <0 the other side.

So for example suppose your "right" plane is at a distance 5 along the X 
axis, your plane equation would be 1*x + 0*y + 0*z - 5

Now you can take some points and plug it into that equation:

P=(0,1,2) gives 1*0 + 0*1 + 0*2 -5 = -5 (negative, so on left of plane)

P=(10,5,4) gives 1*10 + 0*5 + 0*4 -5 = 5 (positive, so on right of plane)

You just need to check that your point is on the "inside" of each of the 
6 planes that make up your box, then you know for sure it is inside the box.

Your other plane equations for the box might be:

-1*x + 0*y + 0*z - 3 (left plane)
  0*x + 1*y + 0*z - 2 (top plane)
  0*x - 1*y + 0*z - 0 (bottom plane)
  0*x + 0*y + 1*z - 4 (front plane)
  0*x + 0*y - 1*z - 1 (back plane)

Slightly off-topic I know, but those are the same numbers you can use in 
the POV "plane" object :-)


Post a reply to this message

From: Patrick Elliott
Subject: Re: Math question (inside box)
Date: 8 Aug 2013 02:55:57
Message: <520340fd$1@news.povray.org>
On 8/7/2013 2:11 AM, scott wrote:
>> Mind, such a test could handle even non-box results, like trapezoids,
>> but requires.. Ah, I know.. I need to just add in a rotation for the
>> axis I want to test my other "sides" against, which are at:
>
> Indeed, the multiple-planes approach can handle any convex object. If
> you want a concave object (eg an "L" shape) you need to split it up in
> to multiple boxes and test each one separately.
>
>> Hmm. Wait, that gives me planes, but.. how does the test happen?
>> Actually, I think you may have really lost me, or I missed something, or
>> you assumed I had a clue about something I didn't, or.. something.. lol
>
> Once you've got the equations for your planes (ie Ax+By+Cz+D=0) then you
> plug in your point position for xyz and evaluate the result.
>
> If the result is 0 then the point is exactly on the plane, if it's >0
> it's on one side, <0 the other side.
>
> So for example suppose your "right" plane is at a distance 5 along the X
> axis, your plane equation would be 1*x + 0*y + 0*z - 5
>
> Now you can take some points and plug it into that equation:
>
> P=(0,1,2) gives 1*0 + 0*1 + 0*2 -5 = -5 (negative, so on left of plane)
>
> P=(10,5,4) gives 1*10 + 0*5 + 0*4 -5 = 5 (positive, so on right of plane)
>
> You just need to check that your point is on the "inside" of each of the
> 6 planes that make up your box, then you know for sure it is inside the
> box.
>
> Your other plane equations for the box might be:
>
> -1*x + 0*y + 0*z - 3 (left plane)
>   0*x + 1*y + 0*z - 2 (top plane)
>   0*x - 1*y + 0*z - 0 (bottom plane)
>   0*x + 0*y + 1*z - 4 (front plane)
>   0*x + 0*y - 1*z - 1 (back plane)
>
> Slightly off-topic I know, but those are the same numbers you can use in
> the POV "plane" object :-)
>
Ah. OK. That make perfect sense. Definitely need, one of these days, to 
take more math. lol Though, honestly, I have always had much the same 
problem with "equations" as with function calls. Remembering what I want 
to do (or, say.. the function name) is the easy part, its all the fiddly 
bits, which make it work, like.. the actual written equation, or the 
parameters for the call, which screwed me up. lol

Hmm. I do, in this case, since there are "at origin", need to also do:

AVPos = llDetectedPos(0) - llGetPos();

I think, so that the "location" I am testing against is actually based 
on where the box is, not some other place. Otherwise, I would have to 
"add" that position, to all the values. After all, its not at the 
origin, but the equations "assume" that it is.


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.