Simple Interpolation in Numpy?

Hendrik van Rooyen mail at microcorp.co.za
Fri Feb 9 01:18:10 EST 2007


 LAPI, VINCENT J, ATTLABS  wrote:


>Hi,
>Please bear with me as I am new to Python and have not done any programming in
about 20 years. I am >attempting to do a simple interpolation of  a line's
intermediate points given the x,y coordinates of the line's two >endpoints
within an Active State Python script that I am working with. Is there a simple
way to do this simple >interpolation in the Active state Python 2.4 that I have
or do I need to get Numeric Python? And where do I get >it?

You don't need anything fancy, the bulk standard python should do this:

untested:

ep0 = (x0,y0)        # known endpoints
ep1 = (x1,y1)

dx = x1-x0            # calculate span
dy = y1-y0

y = y0 + dy*(x-x0)/dx    # to give y from known x

x = x0 + dx*(y-y0)/dy    # to give x from known y

The interactive interpreter is your friend.
(you activate it by typing "Python" at the command prompt)
(don't type the quotes..)
Use it for playing with this kind of stuff.

And other stuff too - it answers most questions of the:

"can I do this? "  and
"what happens when I ..."   variety.

Also read the tutorial - if you have done programming
twenty years ago, you will take to it like a duck to water.

It really works much easier than a teletype...

hth - Hendrik




More information about the Python-list mailing list