[Gllug] Algorithm question
Greg McCarroll
greg at mccarroll.org.uk
Tue Feb 27 05:38:13 UTC 2007
On 27 Feb 2007, at 00:44, Adrian McMenamin wrote:
> Actually I discovered that there is a package in CPAN which determines
> whether or not a 2D point falls within a polygon.
M::G::Planar?
Anyway, here is how I would solve the problem for the special case of
a cube. It's 5:30am, I haven't opened a geometry book in around 7 years,
so please take this as just a random idea intended to stimulate
discussion.
Squares and cubes are great if they are aligned to the coordinate system
for this sort of thing. If the point P (Xp,Yp) satisfies for a square S
(Xmin,Xmax,Ymin,Ymax) ...
Xmin < Xp < Xmax
&& Ymin < Yp < Ymax
you are good to go (you may wish to use <= instead of <).
The problem is that squares and cubes don't necessarily align themselves
neatly.
So the way I would have approached this is, choose an edge of the cube,
and calculate the transform required to move it into alignment with
an axis
vector. Apply this transform to all the points (the corners of the
cube and
the point itself) involved. Work out the X,Y,Z max/mins and then do
something
like the above test on all transformed points.
Does this make sense?
I'm sure there is a better way, but I thought It couldn't hurt to
suggest
a whacky one (which may be wrong).
G.
-------------- 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