在两个任意点之间使用 ArcSegment 的半圆的 WPF 数学

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5336131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:40:09  来源:igfitidea点击:

WPF Math for semi circle using ArcSegment between two arbitrary points

wpfgeometry

提问by NVM

Can someone show the math for drawing a semi circle between two arbitrary points using an ArcSegment in WPF.

有人可以展示在 WPF 中使用 ArcSegment 在两个任意点之间绘制半圆的数学方法。

I am quite confused with the RadiusX, RadiusY in the ArcSegment. It does not seem to be relative to the two points but rather to the X and Y axis. Is that how it really should be?

我对 ArcSegment 中的 RadiusX、RadiusY 很困惑。它似乎不是相对于这两个点,而是相对于 X 和 Y 轴。真的应该这样吗?

回答by Jarek

You are right, Sizeof ArcSegmentis not radius between points that define the start and end of the arc. This property describes how big the ellipse that will be drawn between those points, should be. If you want to have a circle instead of an ellipse, you must remember to always set size's x and y values to be the same. If you want to always have half of the circle drawn, you also need to make sure Sizewill be half of the distance between those two points.

您是对的,SizeofArcSegment不是定义圆弧起点和终点的点之间的半径。此属性描述将在这些点之间绘制的椭圆应该有多大。如果你想要一个圆而不是一个椭圆,你必须记住始终将 size 的 x 和 y 值设置为相同。如果您想始终绘制圆的一半,您还需要确保Size将是这两点之间距离的一半。

For example look at the code below:

例如看下面的代码:

<Canvas>
    <Path Stroke="Black">
        <Path.Data>
            <PathGeometry>
                <PathFigure StartPoint="100,100">
                    <ArcSegment IsLargeArc="True"
                                Size="50, 50"
                                Point="200, 100"
                                SweepDirection="Clockwise" />
                </PathFigure>
            </PathGeometry>
        </Path.Data>
    </Path>
</Canvas>

This will draw upper half of the circle, that starts at point 100, 100and ends at point 200, 100. Since I've set Sizeproperty to50, 50(distance between those points is 100), this will create exactly half of circle. SweepDirectionstates, that circle should be drawn clockwise, and that's the reason why it will draw upper half. Check out the difference between Clockwiseand Counterclockwiseon screens below:

这将绘制圆的上半部分,从点开始到点100, 100结束200, 100。由于我已将Size属性设置为50, 50(这些点之间的距离为 100),因此这将正好创建一半的圆。SweepDirection状态,那个圆圈应该顺时针绘制,这就是它绘制上半部分的原因。在下面的屏幕上查看Clockwise和之间的区别Counterclockwise

50, 50, clockwise50, 50, counterclokwise

50, 50, 顺时针50, 50, 逆时针

IsLargeArcchooses whether to draw bigger part of ellipse or smaller. Since I'm drawing half of circle, this has no meaning, but if you would draw ellipse with different size, this would significantly change output look, just play with it to see how it works.

IsLargeArc选择绘制椭圆的较大部分还是较小部分。因为我画了一半的圆,所以这没有意义,但如果你画不同大小的椭圆,这会显着改变输出外观,只需玩一下看看它是如何工作的。

This is how it looks when you try to put 200, 200sized arc, clockwiseusing its large arc part. As you can see - arc does not even fit the window (this is shot from WPF designer, in normal app overflowing part would be cut off)

这是当您尝试使用大圆弧部分放置200, 200大小圆弧时的外观clockwise。如您所见 - arc 甚至不适合窗口(这是从 WPF 设计器拍摄的,在正常的应用程序中溢出的部分会被切断)

200, 200, clockwise, largearcAnd this is the same thing but set to display small arc: 200, 200, clockwise, not largearc

200, 200, 顺时针, largearc这是同样的事情,但设置为显示小弧: 200, 200,顺时针,不是大弧

When I changed Sizeproperty to 200, 200, drawn circle is simply 4 times bigger, but still starts and ends at exact points you defined. Sizehas nothing to do with points, between which you're drawing your ellipse/cricle, but it changes the ellipse look.

当我将Sizeproperty更改为 时200, 200,绘制的圆只是大了 4 倍,但仍然在您定义的确切点处开始和结束。Size与点无关,在点之间绘制椭圆/圆角,但它会改变椭圆的外观。

I hope that it shows you what's the meaning of Sizein ArcSegment, feel free to ask more detailed questions, if you're still confused.

我希望它向您展示了Sizein的含义ArcSegment,如果您仍然感到困惑,请随时提出更详细的问题。