|
-
You could represent the rectangle parametrically and pick a point along the edge by clamping your variables to certain values. The advantage of this is that it will work for any parallelogram in any orientation, but the disadvantage is that there may be more intuitive solutions for your specific problem and/or which utilize the AS standard library, if you don't like the math behind it.
I'll stick to the way Flash generally represents rectangles.
For a rectangle defined by x, y, w, h, take a point P0 as <x,y>, the two points connected to P0 as P1: [x+w, y] and P2: [x, y-h]. The edges can be defined, then, as E0: P1 - P0 and E1: P2 - P1. The parametric equation:
Code:
R(s, t) = P0 + s*E0 + t*E1
will represent a point within the rectangle given s: [0.0,1.0] and t: [0.0, 1.0].
A point along the rectangle's edge can be found by evaluating R(s,t) where s is any number in the interval [0,1] while t is either 1 or 0, or vice versa.
If you wanted to, then, march around the edge of the rectangle, you could start with s and t as 0, and then increment s until it reached 1. After this, increment t until it reaches 1, then decrement s to 0, and finally t to 0.
Hopefully I'm correct about the above. It should be simple to verify, but I'm not at home at the moment and tend to screw up even math this simple. Let me know if you're having trouble and I'll see if I can't get a hold of a compiler later.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|