[Gllug] Algorithm question

Richard Jones rich at annexia.org
Mon Feb 26 23:26:41 UTC 2007


On Mon, Feb 26, 2007 at 10:43:45PM +0000, Adrian McMenamin wrote:
> I need to find an algorithm that will determine whether a cartesian
> point is inside a cube. Happy to look on google for such a thing, but I
> don't even know what it is called ... can anyone help (if you can find
> me a CAPAN module that does this even better, but I doubt whether one
> exists as I have been looking for some time now)

Google: distance point to plane

You need an algorithm which will tell you whether a point is on one
side of the other of a plane[1].  Then just compare your cartesian
point to all six planes of the cube.  If it's "inside"[2] all of them,
then it's inside the cube.

I haven't used any particular CPAN packages related to this, but it
looks like either:
http://search.cpan.org/~prbrenan/Math-Zap-1.07/lib/Math/Zap/Triangle.pm#distance
or our very own Greg McCarroll's
http://search.cpan.org/~gmccar/Math-Geometry-0.04/Geometry.pm may be
able to do this.

Rich.

[1] The plane itself is defined as a normal vector and a point.  Think
of a large, thin, flat piece of wood with a nail hammered through it.
The piece of wood is the plane.  The nail is the normal vector.  And
the place where the nail and the wood meet is the point.

[2] Assume all the normals (nails) point inwards towards the centre of
the cube.  It depends on the distance function, but often they will
return positive if the point is on one side of the plane and negative
on the other, so you just need to arrange "inside" & "outside" to
correspond to these.

-- 
Richard Jones
Red Hat UK Limited
-------------- next part --------------
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug


More information about the GLLUG mailing list