I have an object Rectangle and it is draggable. The object is inside a circle. How can I restrict the path of the rectangle inside the circle, i.e the rectangle cannot be drag outside but within the circle.
Please tell me the code..
Object dragged inside a circle
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Livecode Opensource Backer
- Posts: 328
- Joined: Mon Dec 05, 2011 5:34 pm
- Location: Thailand
- Contact:
Re: Object dragged inside a circle
You know the position of the centre of the enclosing circle. You know the current position of the centre of the dragged object. You know the radius of the enclosing circle. You know the size of the dragged object.
Use the basic distance calculation from the centre of the circle to the centre of the dragged object. Don't allow the object to move if the distance is more than the radius of the circle minus half the size of the object. The object should not then be able to appear outside the circle.
The actual code will be up to you, but the distance calculation is a simple Google search away and the rest is very simple.
Hope that helps.
Dave
Use the basic distance calculation from the centre of the circle to the centre of the dragged object. Don't allow the object to move if the distance is more than the radius of the circle minus half the size of the object. The object should not then be able to appear outside the circle.
The actual code will be up to you, but the distance calculation is a simple Google search away and the rest is very simple.
Hope that helps.
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.
Visit http://electronic-apps.info for released App information.
Re: Object dragged inside a circle
Thnx Dave....
Will give it a try....
Will give it a try....