Click here to Skip to main content
15,885,100 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hi there,
I'm writing a GUI program that makes a point of an arrow or a line follow a circle, but I just don't know how to make it. Is like this, if you move the circle the point of origin of the arrow must move with the circle and the point of destiny of the arrow doesn't has to move. And the arrow must be on the periphery of the circle. A little help here would be rewarding for me and you.

PS: I know how to draw an arrow and a circle and making a hittest.

Thanks in advance!
Posted
Updated 12-Feb-11 10:45am
v4
Comments
Manfred Rudolf Bihy 12-Feb-11 15:48pm    
Your question not clear. By "follow a circle" do you mean that the circle is moving and the arrow should follow the moving circle, or is it that there is a circle and you want the arrow to move along the circumference (clockwise or counterclockwise)?
[no name] 12-Feb-11 16:08pm    
I mean that the circle is moving and the arrow must follow the moving circle.
Manfred Rudolf Bihy 12-Feb-11 18:30pm    
Since you totally changed your requirements from your first question I hereby resign from trying to answer you.
[no name] 13-Feb-11 8:22am    
Although, thanks for the idea.

1 solution

I'll give you an idea and hope it will suffice to get you going on your own.

  1. A circle is defined by a center point (x,y) plus a radius C(x,y,r).
  2. An arrow is defined by a starting point A and an end point B where each of these points is a coordinate (X,Y). For an arrow there will be a constraint of a given length l. L(A,B)
  3. It's taken as a given that the code to move the circle C is already in place.
  4. Start condition:
    The circle C is positioned in Cx,Cy and given the arrows starting point and length you determine the endpoint of the arrow A. Hint: For that you'll have to determine the angle of the line form A's starting point to the center of C and then calculate the endpoint given the starting point of A the length of the line and the angle.
  5. Move of circle takes place
  6. The new starting point A for the arrow must be determined which depends on the new direction (angle relative to the circle's center) and the speed of the arrow. Given that new starting point and the angle towards the circle's center recalculate the arrows endpoint analogous to point 4.
  7. End Condition:
    The distance between the endpoint B of line L is less than or equal to the radius of circle C added to the length of line L. If this happens the arrow has caught the circle.

Hope this helps some!

Cheers!
 
Share this answer
 
v2
Comments
Sandeep Mewara 13-Feb-11 2:18am    
Perfect! 5++

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900