[Gllug] Algorithm question
John Hearns
john.hearns at streamline-computing.com
Tue Feb 27 10:45:19 UTC 2007
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)
A stupid answer.
Rotate your axes till the cube's faces are parallel to X/Y/Z
Scale the axes till it has unit sides (or to extend this, scale 3 axes
differently so XYZ faces of a cuboid are unity).
Place one vertex at the origin.
Apply same transformation to the coordinates of the point.
Point's new co-ordinates are a,b,c
If modulus (a | b | c ) > 1 then point is outside the cube.
I guess figuring out the tensor to do the rotation and scaling would be
more complicated than any sensible answer.
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list