Click here to Skip to main content
15,905,420 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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)
            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();

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


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!!!

1 solution

of course it is
x3 = x1 + (x2-x1)*p/100;
y3 = y1 + (y2-y1)*p/100;
Share this answer
Kavan Rathnayake 24-Jun-14 4:48am    
Thanks :)
Feel so dumb atm
Thanks again
CPallini 24-Jun-14 5:13am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900