POV-Ray : Newsgroups : povray.off-topic : Math question (inside box) : Re: Math question (inside box) Server Time
28 Jul 2024 16:21:30 EDT (-0400)
  Re: Math question (inside box)  
From: scott
Date: 5 Aug 2013 07:38:14
Message: <51ff8ea6$1@news.povray.org>
On 05/08/2013 10:17, Patrick Elliott wrote:
> 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.
>>
> lol What part of, "I know I screwed up the math.", did people miss. ;)

I was really having trouble trying to understand what you actually 
wanted to do! I don't know which parts of the above are math screw ups 
or what you actually want to do...

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?


Post a reply to this message

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