WPF中从中心点到特定点的路径、弧段计算

WPF中从中心点到特定点的路径、弧段计算,wpf,wpf-controls,Wpf,Wpf Controls,我在XAML中定义了弧段,在代码中,我需要计算从弧的中心点到特定Y点的Y值。请看图片以便更好地理解 XAML <Canvas Name="canvas" Background="White" Opacity="99"> <Path Stroke="Red" MouseLeftButtonDown="Path_MouseLeftButtonDown">

我在XAML中定义了弧段,在代码中,我需要计算从弧的中心点到特定Y点的Y值。请看图片以便更好地理解

XAML

 <Canvas Name="canvas" Background="White" Opacity="99">
        <Path Stroke="Red" MouseLeftButtonDown="Path_MouseLeftButtonDown">
            <Path.Data>
                <PathGeometry>
                    <PathFigureCollection>
                        <PathFigure StartPoint="250,250">
                            <ArcSegment Size="70,70" IsLargeArc="True" SweepDirection="Counterclockwise" Point="250,200"/>
                        </PathFigure>
                    </PathFigureCollection>
                </PathGeometry>
            </Path.Data>
        </Path>
       
    </Canvas>
屏幕截图


中心的y值是起点和终点y值的平均值(因为它们的x值相同),即225。减去70是155,不是154。嗨,克莱门斯,非常感谢你!这解决了我的问题。确实是155。我只是依靠我的鼠标指针。我的公式是var meanY=(yStart+扫掠角)/2-70;中心的y值是起点和终点y值的平均值(因为它们的x值相同),即225。减去70是155,不是154。嗨,克莱门斯,非常感谢你!这解决了我的问题。确实是155。我只是依靠我的鼠标指针。我的公式是var meanY=(yStart+扫掠角)/2-70;
//I got this from StackOverflow maybe someone can figure out for the correct computation.
     private void Path_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                var curve = sender as Path;
                var geometry = curve.Data as PathGeometry;
                var figure = geometry.Figures.FirstOrDefault();
                var arcSegment = figure.Segments.FirstOrDefault() as ArcSegment;
                var xStart = figure.StartPoint.X;
                var yStart = figure.StartPoint.Y;
                var startAngle = arcSegment.Point.X;
                var sweepAngle = arcSegment.Point.Y;
                var Rx = arcSegment.Size.Width; // this is radius width
                var Ry = arcSegment.Size.Height;  // this is radius height
                var centerX = xStart - Rx * Math.Cos(startAngle);
                var centerY = yStart - Ry * Math.Sin(startAngle);
                var endAngle = startAngle + sweepAngle;
                var xEnd = centerX + Rx * Math.Cos(endAngle);
                var yEnd = centerY + Ry * Math.Sin(endAngle);
            }