Constrain Within Circle?
alex at tweedly.net
Sat Nov 5 07:18:05 EST 2005
Scott Rossi wrote:
>Anyone have a formula to constrain object dragging within a circular region?
There are 3 (or more) versions of "constrain object dragging within a
1. constrain the mouse location to be within the circle
(easy - use this if you can)
2. constrain the object to be within the circle
(hard - especially for ellipses, polygons, etc.)
3. constrain the bounding rect of the object to be within the circle
(fairly easy - calculate the offsets of the four corners from the
mouseloc, and then its only two or four checks per mouse move, though
the math to calculate the correct position to bring the bounding rect
just within the circle is a bit more complex).
Assuming you can get away with version 1, then TJ or Malte has given you
a good answer (though I think Malte's constrained to *on* the circle
perimeter rather than within it :-)
If you need 2, you're on your own :-)
If you need 3, I have code to do that I can dig out (and translate into
xtalk) and send - just let me know.
Alex Tweedly http://www.tweedly.net
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.12.8/161 - Release Date: 03/11/2005
More information about the Use-livecode