且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何:沿另一个圆圈的圆周移动一个圆圈?

更新时间:2023-01-08 12:41:55

你好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