POV-Ray : Newsgroups : povray.off-topic : Math question (inside box) : Re: Math question (inside box) Server Time
28 Jul 2024 16:27:14 EDT (-0400)
  Re: Math question (inside box)  
From: Le Forgeron
Date: 5 Aug 2013 07:43:05
Message: <51ff8fc9@news.povray.org>
Le 05/08/2013 11:17, Patrick Elliott a écrit :
> On 8/5/2013 1:44 AM, scott wrote:
>>>   vector bbox1 = <pos.x - left, pos.y + boxlen, pos.z - bottom>;
>>>   vector bbox2 = <pos.x + right, pos.y + boxlen, pos.z + top>;
>>>   vector bbox3 = <pos.x - left, pos.y + boxlen + length, pos.z -
>>> bottom>;
>>>   vector bbox4 = <pos.x - right, pos.y + boxlen + length, pos.z + top>;
>>
>> Do you mean "pos.x + right" in that last line?
>>
>>> integer isInsideBox(vector bbox1, vector bbox2, vector bbox3, vector
>>> bbox4)
>>> {
>>>    vector P = llDectectedPos(0);
>>>    vector A1 = <bbox1.x,bbox2.y,bbox1.z>;
>>>    vector B1 = <bbox2.x,bbox2.y,bbox1.z>;
>>>    vector C1 = <bbox2.x,bbox1.y,bbox1.z>;
>>>    vector D1 = <bbox1.x,bbox1.y,bbox1.z>;
>>  >    vector A2 = <bbox3.x,bbox4.y,bbox3.z>;
>>  >    vector B2 = <bbox4.x,bbox4.y,bbox3.z>;
>>  >    vector C2 = <bbox4.x,bbox3.y,bbox3.z>;
>>  >    vector D2 = <bbox3.x,bbox3.y,bbox3.z>;
>>
>> If you substitute in your values for bbox1-4 from above you get the
>> following (I left out the pos.x,pos.y,pos.z):
>>
>> A1 = <-left  , boxlen , -bottom>
>> B1 = < right , boxlen , -bottom>
>> C1 = < right , boxlen , -bottom>
>> D1 = <-left  , boxlen , -bottom>
>>
>> A2 = <-left  , boxlen+length , -bottom>
>> B2 = < right , boxlen+length , -bottom>
>> C2 = < right , boxlen+length , -bottom>
>> D2 = <-left  , boxlen+length , -bottom>
>>
>> Is this really what you are expecting?
>>
>> If you are trying to see if a point is inside a box, then it might be
>> simpler to think of the box as being bounded by 6 infinite planes (one
>> for each face), then testing which side of each plane the point is on.
>> If it's on the "inside" of all 6 planes then it's inside the box.

That's a good idea.

>>
> lol What part of, "I know I screwed up the math.", did people miss. ;)
> 
> Seriously though, Le_Fogeron says it wouldn't work anyway... :p

The test against 6 planes would work, and is easy if it is axis aligned.
If it is rotated, you have "just" to apply the same maths, it's just the
formula which become a bit harder (a plane equation is ax+by+cz+d = 0,
one side of the plane is wherer ax+by+cz+d > 0, and the other side is <0)
There is an infinity of 4D vector <a,b,c,d> to match a single plane
(indeed, if V is such vector, k.V is also another vector)
(also notice that if V is such vector, -V is the same plane but with the
inversion of the sides)
So, instead of thinking "corner of box" (8) to be grouped in
squares/side, you should have to think "plane's equation" (6).

Notice that scaling & shearing leaves plane as plane, so even if you
were to use a sheared box (such as a truncated pyramid), it would still
works.

What I said was that extending the "smart" 2D triangle-based-tests to 3D
are to be a nightmare.



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


Post a reply to this message

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