简体   繁体   中英

ArcSegment C# Formula To Get A Specific Point on Arc WPF

I have arc in a canvas drawn from Path with the following details. I want to get Point(115,225). Please see screenshot to get more details. Please help me getting the formula to get to point (115,225).

startX=250
startY=250
ArcSegment Size (70,70)
ArcSegment Point (250,200)

Computation
var meanX=(startX+startX)/2-rX;//(250+250)/2-70=180 
var meanY=(startY+ArcSegment.Point.Y)/2-rY;//(250+200)/2-70=225
//center Point (180,225)
//What is the formula if I want to get Point(115,225)

XAML

<Canvas Name="canvas" Background="White" Opacity="99">
         <Path Stroke="Blue" MouseLeftButtonDown="Path_MouseLeftButtonDown" >
            <Path.Data>
                <PathGeometry>
                    <PathFigureCollection>
                        <PathFigure StartPoint="250,250" IsClosed="True">
                            <ArcSegment Size="70,70" IsLargeArc="True" SweepDirection="Clockwise" Point="250,200"/>
                        </PathFigure>
                    </PathFigureCollection>
                </PathGeometry>
            </Path.Data>
        </Path>
    </Canvas>

C#

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 startX = figure.StartPoint.X;
            var yStart = figure.StartPoint.Y;
            var startAngle = arcSegment.Point.X;
            var sweepAngle = arcSegment.Point.Y;
            var rX = arcSegment.Size.Width; 
            var rY = arcSegment.Size.Height; 
            var endAngle = startAngle + sweepAngle;
            var meanX = (startX + startAngle) / 2 - rX;
            var meanY = (yStart + sweepAngle) / 2 - rY;
            
        }

Screenshot输出截图

After hours of research, I found out everything is here.

 var geometry = path.Data as PathGeometry;
 var leftX=geometry.Bounds.Location.X;
 var topY=geometry.Bounds.Location.Y;

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM