Solved

Inverse Interpolation

Posted on 2006-11-01
4
472 Views
Last Modified: 2009-07-29
I need to find the distance down a line.  Just wondering if there is a package (or anything really) that can perform Inverse Interpolation.

Cheers.
0
Comment
Question by:nebbles
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 10

Expert Comment

by:gangwisch
ID: 17852588
you can use the distance formula, here is a sample:
http://www.purplemath.com/modules/distform.htm
0
 

Author Comment

by:nebbles
ID: 17853204
I know 2 points of a line.  Given a distance I need to find the point along the line and not the total distance.
0
 
LVL 5

Accepted Solution

by:
xersoft earned 500 total points
ID: 17866863
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.Height, Length.Width))


        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)

        Return NewPoint
    End Function

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.MouseEventArgs) Handles MyBase.MouseMove
        Dim gr As Drawing.Graphics = Me.CreateGraphics


        gr.Clear(Drawing.SystemColors.Control)
        Dim p1 As New Drawing.PointF(CSng(Width / 2), CSng(Height / 2))
        Dim p2 As New Drawing.PointF(e.X, e.Y)

        gr.DrawLine(Drawing.Pens.Black, 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)
    End Sub
    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))

        b.Dispose()
    End Sub

0
 

Author Comment

by:nebbles
ID: 17883547
I had to modify the code so it wouldn't draw, but otherwise everything was there.

Thanks.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question