如何沿直线找到一个点 [英] How to find a point along a straight line

查看:84
本文介绍了如何沿直线找到一个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个点(x1,y1)和(x2,y2)并且在两个点之间有一条直线。从线的距离我必须减少一些长度(原始长度的百分比)。如何获得新长度在(x1,y1)和&之间绘制路径的点。 (x3,y3)



到目前为止,我已经在WPF C#中开发了这个:#/>


I have two points (x1, y1) and (x2,y2) and have a straight line between the 2 points. From the distance of the line I have to decrease some length (Percentage of the original length). How do I get the point where the new length is to draw a path between (x1,y1) & (x3,y3)

So far I have this and developed in WPF C#:

private void DrawPath(Point origination, Point destination, float decreasePct)
        {
            Canvas.Children.Clear();
            var distance = GetLineLength(origination, destination);
            
            var path = new PathFigure();

            path.StartPoint = origination;

            path.Segments.Add(new LineSegment(destination, true));

            // Create a PathGeometry to contain the figure.
            var pathGeometry = new PathGeometry();
            pathGeometry.Figures.Add(path);

            // Display the PathGeometry.
            var myPath = new Path {Stroke = Brushes.Black, StrokeThickness = 6, Data = pathGeometry};

            Canvas.Children.Add(myPath);
        }

private int GetLineLength(Point origination, Point destination)
        {
            var x = destination.X - origination.X;
            var y = destination.Y - origination.Y;

            var pyth = Math.Pow(x, 2) + Math.Pow(y, 2);

            return (int)Math.Sqrt(pyth);
        }





任何帮助都将不胜感激!!!



Any help would be appreciated!!!

推荐答案

当然是

of course it is
x3 = x1 + (x2-x1)*p/100;
y3 = y1 + (y2-y1)*p/100;


这篇关于如何沿直线找到一个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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