如何:沿另一个圆圈的圆周移动一个圆圈? [英] How to: Move a circle along the circumference of another circle?

查看:188
本文介绍了如何:沿另一个圆圈的圆周移动一个圆圈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要沿着运行RotateTransform的另一个圆圈的圆周移动一个圆圈。第一个圆可绕其中心旋转到位,角度偏移传递给动画例程。第二个圆必须同时跟随第一个圆的旋转,其中心以第一个圆旋转的相同角速率跟踪第一个圆周的路径。在该操作期间,第二圈可以可选地执行其自己的RotateTransform。我一直在玩MatrixAnimationUsingPath但没有成功。我也是WPF的新手。

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.

推荐答案

你好LEastburn,



创建一个WPF应用程序,打开主窗体,把它放在你的XAML中。您可能希望并排设计视图和XAML视图。

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.
<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>



尝试更改第二个圆圈的RotateTransform对象的角度属性。你会看到它沿着圆周移动。所以SA试图告诉你的是,在你的应用程序中进行这种计算。你应该记住几件事。

1.找到相对于你要旋转的圆的另一个圆的中心,并将其设置为RotateTranform的'CenterX'和'CenterY'属性

2.必须相对于它们所属的圆圈指定'CenterX'和'CenterY'。即它是从圆圈的左上角开始的距离,而不是画布。

3.由于您想沿着圆周移动圆圈,请进行必要的数学运算并将其放在另一个圆圈附近。



之后你需要做的就是,在RotateTransform中更改'Angle'或者为它设置动画,它会围绕圆圈移动。



希望这有帮助,干杯


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


这篇关于如何:沿另一个圆圈的圆周移动一个圆圈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆