POV-Ray : Newsgroups : povray.off-topic : Math question (inside box) : Re: Math question (inside box) Server Time
28 Jul 2024 22:29:27 EDT (-0400)
  Re: Math question (inside box)  
From: scott
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

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