For an arbitrary rectangle you'll have to do some math.  Of the top of
my head, here's a way to do it:

First you'll need to be familiar with vector math, including dot products:
http://mathworld.wolfram.com/DotProduct.html

So, pick an arbitrary point on the rectangle and get the vectors for
the 2 sides.  So, for a rectangle at:

p0----------p1
 |            |
 |   x        |
 |            |
p2----------p3

calculate:
v1 = p1 - p0 // This is the vector from p0 to p1
v2 = p2 - p0 // This is the vector from p0 to p2
vX = x - p0  // This is the vector from p0 to your point

Now, do:
d1 = dot(vX, v1)
d2 = dot(vX, v2)

Now, if the point is in the rectangle then:

0 <= d1 <= 1
0 <= d2 <= 1

That is, assuming I got my math right (doing this all in my head w/o any paper).

Try that.  And if anyone sees any problems with my math, let me know.

  -Andy



On 12/21/06, slangeberg <[EMAIL PROTECTED]> wrote:
>
> The rectangle is not parallel to the axes, instead its rotating all the
> time.
>

I don't believe that using the bounds of a clip will account for any
rotations.-Scott

-Scott

On 12/21/06, Janis Radins <[EMAIL PROTECTED]> wrote:
>
> Check whteher your point is iniside boundries by something like this:
> if(point.x > rect.minX && point.x < rect.maxX && point.y > rect.minY &&
> point.Y < rect.maxY)
>
> guess something like that should work.
>
> 2006/12/21, Oliver Müller <[EMAIL PROTECTED]>:
> >
> > Hi all,
> >
> > I'm looking for a mathematic way to check if a point resides within a
> > rectangle.
> > The rectangle is not parallel to the axes, instead its rotating all the
> > time.
> > It's not a movieclip so hitTest is out of the question.
> > Any suggestions how I could solve this problem ?
> >
> > cheers,
> > olli
> > _______________________________________________
> > [email protected]
> > To change your subscription options or search the archive:
> > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >
> > Brought to you by Fig Leaf Software
> > Premier Authorized Adobe Consulting and Training
> > http://www.figleaf.com
> > http://training.figleaf.com
> >
> _______________________________________________
> [email protected]
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>



--

: : ) Scott
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to