Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to move a circle along the circumference of another circle that is running a RotateTransform. The first circle can be rotated in place, about its center, with an angular offset passed to the animation routine. The second circle must simultaneously follow the rotation of the first circle, with its center tracing the path of the first circle's circumference at the same angular rate the first circle is rotating. The second circle may optionally execute its own RotateTransform during this operation as well. I have been playing with MatrixAnimationUsingPath with no success. I'm new to WPF as well.
Posted
Comments
Sergey Alexandrovich Kryukov 31-Mar-14 18:18pm    
If, instead "playing with", you could sit down with a piece of paper and do elementary-school level calculations, you would solve this problem in no time. Please try it, and, if you face any problems, show us what have you tried.
—SA
LEastburn 31-Mar-14 19:13pm    
Not sure why you feel the necessity to insult. Either offer something useful or don't. I said I'm new to WPF but I have done this with WinForms, so the elementary concepts are not an issue. My question has to do with which WPF animation methods are pertinent.
Sergey Alexandrovich Kryukov 31-Mar-14 19:47pm    
What do you call insult? The suggestion to solve the problem yourself? Okay, this is the same very RotateTransform. It sounds like you can do it (you can animate any transform). All you need it to calculate parameters of such transform. Also note that rotation of a circle around its own center transforms a circle to itself. Does it make sense now?

—SA

1 solution

Hi LEastburn,

Create a WPF application, open up the main form, put this inside your XAML. You may want to have the design view and the XAML view side by side.
XML
<Canvas x:Name="LayoutRoot" Background="AliceBlue">
    <Ellipse Height="150" Width="150" Canvas.Top="275" Canvas.Left="250" Stroke="LightSlateGray" StrokeThickness="2" />
    <Ellipse Height="150" Width="150" Canvas.Top="275" Canvas.Left="100" Stroke="LightSlateGray" StrokeThickness="2">
        <Ellipse.RenderTransform>
            <RotateTransform CenterX="225" CenterY="75" Angle="120" />
        </Ellipse.RenderTransform>
    </Ellipse>
</Canvas>

Try changing the 'Angle' property of the 'RotateTransform' object of the second circle. You'll see it moves along the circumference. So what SA is 'trying' to tell you is, do this calculation in your application. There are couple of things you should remember.
1. Find the center of the other circle relative to the circle you want to rotate and set it to 'CenterX' and 'CenterY' properties of the RotateTranform
2. 'CenterX' and 'CenterY' must be specified relative to the circle in which they belong to. I.e. it's the distance from top-left corner of the circle, not the Canvas.
3. Since you want to move the circle along the circumference, do the necessary math and place it adjacent to the other circle.

After that all you have to do is, change the 'Angle' in RotateTransform or animate it, it will move around the circle.

Hope this helps, Cheers
 
Share this answer
 
Comments
LEastburn 2-Apr-14 14:50pm    
Hi CodeHawkz. I appreciate your help, but there is one more aspect that makes the solution unclear to me. The second circle (rotating with its center tracing the circumference of the first circle) needs to be independently oriented. So it can remain with its initial angle about it's center or it can rotate about that center, but that angular animation needs to be independent of the other motion it's tracing around the first circle. I can do what you suggested, and that works fine for the case where the second circle is like an extension of the first, but I'm trying to simulate a linkage similar to an upper arm swinging from a shoulder (circle 1) and the forearm pivoting from the elbow (circle 2). I don't think I can do it without a translation move along the circumference of the first circle. The transforms I've seen that come close only approximate that motion with multiple arcs. I need an elliptical translation for the second circle.
CodeHawkz 2-Apr-14 18:46pm    
So basically, what you are trying to achieve is the next step of this solution I suggested. You achieved the first part of your task, now you want the first circle to maintain it's distance and angle with respect to the second circle, when you move the second circle. So you need to implement what you call an observer pattern, where the first circle is subscribed to second circle's movements and updates itself when it's notified. The second circle should notify it's 'observers' when it moves.

Hope this helps, Cheers

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