I need a solution
I need to find the distance down a line. Just wondering if there is a package (or anything really) that can perform Inverse Interpolation.
you can use the distance formula, here is a sample:
I know 2 points of a line. Given a distance I need to find the point along the line and not the total distance.
I'm not exactly sure what you are looking for but does this help?
Private Function GetPointByLength(ByVal P1 As PointF, ByVal P2 As PointF, ByVal DistanceFromP1 As Single) As PointF
Dim Length As New Drawing.SizeF(P1.X - P2.X, P1.Y - P2.Y)
Dim Angle As Single = CSng(Math.Atan2(Length.Hei
Dim nx As Single = CSng(Math.Cos(Angle) * DistanceFromP1)
Dim ny As Single = CSng(Math.Sin(Angle) * DistanceFromP1)
Dim NewPoint As New Drawing.PointF(P1.X - nx, P1.Y - ny)
Give it two points and the distance and it will return the point, which is the given distance from P1. You can test it by dropping a text box on a form and naming it: txtLength
Then put this code, along with the above function into the form.
Private Sub Form_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.Mouse
Dim gr As Drawing.Graphics = Me.CreateGraphics
Dim p1 As New Drawing.PointF(CSng(Width / 2), CSng(Height / 2))
Dim p2 As New Drawing.PointF(e.X, e.Y)
lack, p1, p2)
DrawPoint(gr, p1, Drawing.Color.Blue)
DrawPoint(gr, p2, Drawing.Color.Black)
Dim NewLength As Single = CSng(Val(txtLength.Text))
Dim aPt As PointF = GetPointByLength(p1, p2, NewLength)
DrawPoint(gr, aPt, Drawing.Color.Red)
Private Sub DrawPoint(ByVal gr As Drawing.Graphics, ByVal p As PointF, ByVal C As Drawing.Color)
Dim s As Single = 4
Dim b As Drawing.Brush = New Drawing.SolidBrush(C)
gr.FillEllipse(b, New Drawing.RectangleF(CSng(p.
X - s / 2), CSng(p.Y - s / 2), s, s))
I had to modify the code so it wouldn't draw, but otherwise everything was there.
Be seen. Boost your question’s priority for more expert views and faster solutions
Tackle projects and never again get stuck behind a technical roadblock.
How it Works
Plans and Pricing
Become an Expert
Who We Are
Join Our Team
Hall of Fame
Experts Exchange, LLC.
All rights reserved. Covered by US Patent.