Intersections, interpolations, and rotations

Amongst the many and varied functions provided by Excel (or as far as I know any other spreadsheet) there are none that provide a one step process for linear interpolation, finding the intersection points of lines, or conversion between polar and rectangular coordinates, and related operations.

These functions and more can be found in the spreadsheet: which includes open source code for the following functions:

Update 29th March 2011:  For the latest version of this spreadsheet, including many additional functions download  See also the latest related blog post.

Intersection Functions
Finds the intersection points of two 2D lines or polylines
=ip(Line1,LINE2,Optional Coordinate, Optional Point no)
“Line1” and “Line 2” are ranges listing the XY coordinates for the two lines
“Coordinate” specifies the ordinate required, 1 = X, 2 = Y
“Point No” specifies which intersection point is required
If “Point No” is not provided IP returns an n x 2 array, where n is the number of intersection points.
If “Coordinate” is not provided IP returns a 1 x 2 array if “Point no” is provided, or an n x 2 array if not.
If “Line2” is a single point IP returns intersection points for a line through this point and parallel to the X axis if XY = 1, or the Y axis if XY = 2

Intersection points of two polylines

Intersection points of two polylines

Finds if a specified point is inside a closed polyline
=INSIDE(Polyline, Point)

Finds the intersection points of a 2D line and a circle
=IPLC(Line, CircleXY ,Radius)

Finds the intersection points of two circles
=IPCC(Circle1XY, Radius1, Circle2XY, Radius2)

IPSSS finds the 3D intersection points of three spheres
IPSS finds the location and radius of the intersection circle of two spheres,
and the polar coordinate angles of the line connecting the two cenrtres
=IPSSS(Sphere1XYZR, Sphere2XYZR, Sphere3XYZR)

=IPSS(Sphere1XYZR, Sphere2XYZR)
Distance from centre sphere1 to centre intersection circle, radius intersection circle,
and angle of line connecting sphere centres in XY plane and perpendicular plane (radians)

Rectangular to Polar Functions
RtoP, PtoR
Converts rectangular to polar coordinates and polar to rectangular
=RtoP(Rectangular Coordinate range, Origin, Coordinate number)
=PtoR(Polar Coordinate range, Origin, Coordinate number)
Coordinate number 1 2 3
Rectangular X Y Z
Polar R Theta1 Theta2
Theta1 = angle in XY plane
Theta2 = angle in perpendicular plane

Where an origin is given the origin is moved to the coordinates specified

Rotates 2D or 3D rectangular axes about any axis
Rotate(Rectangular Coordinate range, Rotation in radians, Axis, Optional Coordinate Number)

Interploation Functions
interp =interp(tablerange, value, column no) Linear interpolation
interp2 =interp2(tablerange, row value, column val) 2 way linear interpolation
loginterp =loginterp(tablerange, value, column no) Log interpolation
loginterp2 =loginterp2(tablerange, row value, column val) 2 way log interpolation
quadinterp =quadinterp(tablerange, value, column no) Quadratic interpolation

Interpolation functions

Interpolation functions

This entry was posted in Coordinate Geometry, Excel, UDFs, VBA and tagged , , , , , , . Bookmark the permalink.

34 Responses to Intersections, interpolations, and rotations

  1. Pingback: Excel Links of Week - Who is Obama edition? [Aug 12] | Pointy Haired Dilbert -

  2. Pingback: IP.xls updated « Newton Excel Bach, not (just) an Excel Blog

  3. mike seymour says:

    Briliiant solution. I have a function that finds intersections of two polylines but it is not nearly as elegant as yours. Regards, Mike


  4. dougaj4 says:

    Mike – thanks for the comments, glad you found it useful.

    I have just uploaded the latest version, with the “pdist” function modified to deal with duplicate points.


  5. Mike Seymour says:

    I am not sure why excel have never developed a function for finding intersections. I think you should try and sell it to microsoft as it will be a great addition to the standard functions.

    One thing that would be useful (maybe if it can be done with existing functions) is to have a separate function (line intersections) that can input data from separate ranges i.e. at the moment as far as I see from your function is that the Line 1 array (and Line 2 array) are input as a single array containing both x and y coordinates. However, I have found that often the x range may not be alongside the y range (i.e. at different locations in the spreadsheet) and it would be useful to input them as separate distinct ranges i.e. for Line 1 a X1 range and Y1 range and for Line 2 a X2 range and a Y2 range. You may be able to do this with existing functions. but I am not that famliar with array commands.

    PS I also tried your function that calculates values from formulaes. However, it didn’t seem to work for me – not sure what I am doing wrong – does it work with excel 2007?


  6. dougaj4 says:

    Mike, good suggestion, I’ll add that as an option when I have time.

    In the meantime the easiest thing is to use worksheet formulas to create a new range with adjacent X and Y values

    The eval spreadsheet works in XL 2007, or should do. Do the examples in the downloaded file not work on your machine? If you want you can send me a sample at dougaj4 at gmail and I’ll have a look at it.


  7. Mike Seymour says:

    Hi Doug, Yes one can modify the spreadsheet to do that but if you have got a number of intersections to determine then it can become unwieldy. I have been trying to modify function to do this but my knowledge about how arrays work is limited so I am not sure about my sucess. Basically I have inserted Line1X, Line1Y, Line2X and Line2Y into the function arguements (replacing Line1 and Line2) and then have attempted to transfer this data into your original Line1 and Line 2 arrays so that there should not be to much affect on the downstream code. Not working as yet will have another attempt tonight (the function output is #VALUE! at the moment, which was an improvement on my earlier attempts.

    I will keep an eye on this page in the meantime for any upgrades.

    I couldn’t seem to download the spreadsheet for some reason so pasted the code into a module and it didn’t work – not sure what I was doing wrong. However, I have now been able to download the spreadsheet and it works fine. Thanks for that.

    Great site.

    Regards, Mike


  8. dougaj4 says:

    Mike – I have added an IP_4 function in the IP_4.wks spreadsheet you can download from:

    I haven’t tested it thoroughly, so please let me know if you have any problems with it, or if you have any other comments.

    With the evaluation function, it looks like you have been hit by the dreaded WordPress quote bug. The WordPress software changes all “” into something that looks the same, but isn’t. If you copy and paste code you have to do a search and replace for all the “”, and replace them with proper quotes. The same applies to apostrophes.

    I should have a standard note to append to all posted code. Better still, the WordPress people should fix it.


  9. Mike Seymour says:

    Hi Doug, Just checked and found your update – thanks for that. I did do some tinkering with your earlier code (with a lttle help) and did manage to get it to accept separate x and y ranges. The code is not as efficient as yours, however, the problem now is that it doesn’t give any results if the line ranges are horizontal. How to get it to work for a combination of horizontal or vertical x, y ranges is beyond my abilities i’m afraid. Need to have some code that transposes the x,y data if it in a horizontal range so the it is in a form for the rest of your code to work.

    Best regards, Mike


  10. dougaj4 says:

    Mike – I have added a transpose function, that transposes the range if there are more than 2 columns wiith IP() or more than 1 column with IP_4().

    With IP_4 it checks both lines, but assumes the Y data for each line has the same orientation as the X data. Is that a problem?

    Actually I’ll amend it to check both X and Y later; probably by tomorrow.


  11. mike seymour says:

    Hi, Doug, You’ve been very tolerant. The function is going to be very useful. I do a lot work with data that requires interpolation. As I said I have a function that does do this but it is not as good as yours as it only finds one intersection point. I use it regularly and has been a very useful function. I will be replacing my existing function with yours. I’ve been searching the net regularly for a similar function and have only ever seen very basic functions that do this. Will keep an eye on your web page for the update.
    Regards, Mike
    PS I see that you live in Sydney – I’m in Brisbane – It’s pouring down with rain at the moment. Looks like easter may be wet.


  12. dougaj4 says:

    Mike – I appreciate getting the feedback, and I enjoy playing with these things anyway. Glad you found the function useful.

    That’s Queensland, beautiful one day, besodden the next🙂.

    (Sydney has been raining every day for the ast week, and another week to come by the way)


  13. Mike Seymour says:

    I think the rain is here to stay until well into Easter. I’ve been trawling the web lately for excel code and that is how I find your site. Its amazing what you can find. I also found an excellent method for allowing you to set max and min values on x and y coordinates along with titles and chart types using functions. Always used macro’s in the past to do that, however, using functions is much better as it is automated and much simpler as you can call it from anywhere and it does not require a macro button, etc.


  14. Pingback: Another update to IP.xls « Newton Excel Bach, not (just) an Excel Blog

  15. mike seymour says:

    Hi Doug, I made a few changes to your code to allow line1 ranges to be either in columns or rows eg line1x in rows and line1y in columns, etc.

    Have also adjusted function it so it can find intercepts on vertical or horizontal lines by simply inputing the x coord for vertical lines. and y coord for horizontal lines. This saves having to make worker columns in the spreadsheet. I use that a lot in determining intermediate populations in projections, etc

    The last change that I made was including a comment of “no intercept” when that was the case (at the moment) it outputs 0 which may actually be correct.

    It took me a while to work that all out but it was fun. I am sure that you would have done it much quicker. I can email you the file with the changes that I made. I am sure that you would have done it in a more efficient method.

    All the best, Mike


  16. dougaj4 says:

    Mike – if you’d like to send your spreadsheet to my gmail address (dougaj4 ), I’d be very interested to see it.


  17. Mike Seymour says:

    Hi Doug, I emailed the spreadsheet earlier. Hope that you got it. Mike


  18. mani says:

    how to create y axes, y1axes,x axes


  19. dougaj4 says:

    Mani – can you give more details of what you are wanting to do?


  20. Michael says:

    Hi Doug –

    The link to appears broken.



  21. dougaj4 says:

    Michael – thanks for letting me know.

    I have fixed the link, but note that the latest version (IP2.ZIP) is now at:



  22. Michael says:

    Hi Doug –

    Thanks. I went and got v2.0.

    Have you looked at Euler #246? It looks right up your alley as a geometry problem. It’s been stymieing me for a while, and I was thinking your intercept routines might help. I want to solve simultaneous equations, but keep stumbling over the quantity of the slopes of the tangent of an ellipse. My premise is to set the slope of the line equal to the slope of the tangent, or m of the line equal to dy/dx of the ellipse. Ought to be doable, but I’m not seeing the way. Everything I’ve tried is either circular or assumes I know the value ;-(

    It’s the highest number I’ve attempted.



  23. Gus says:

    Hi! good day!! I am working in a very similar project, waht i have is this:
    * i have a Line-graph (line with markers). It graphs time vs a value
    * the user will draw a shape (a FreeForm), and i want to get the points of my graph that are under the area of my shape.

    Thanks a lot already for any possible help on this matter!


  24. dougaj4 says:

    Gus – you will need to get the coordinates of the graph line and the freeform shape with a common frame of reference. My posts on drawing in Excel (for example should give you enough information to get the screen coordinates of the shape. I’m not sure if the screen coordinates of the chart line are easily available or not, and I don’t have time to look into it at the moment. Jon Peltier’s site would be a good place to start looking for that, or a question on one of the big Excel forums.

    Once you have got the screen coordinates you could either use the IP function to find the crossing point(s), or the Inside function to find those points outside the shape.

    If you find a solution I’d appreciate it if you could post it here.


  25. Miguel says:

    Congratulations on this task,

    Please help me with the following problem …
    can’t get good results

    for example, given the following data :

    Plane1 0,000 0,000 0,000
    Plane2 14,000 0,000 2,000
    Plane3 0,000 3,000 0,000

    Line1 1,000 1,000 -1,000
    Line2 0,500 0,500 1,000

    PointIntersc(IP2) 0,741935484 0,741935484 0,032258065
    PointIntersc(Autocad) x=0.7241379 Y=0.7241379 Z=0.1034483

    graphically, the right is Autocad…

    I’m doing wrong? please

    Thank you,


    • dougaj4 says:

      Miguel – Thanks for letting me know. I get the same results. I’ll look into it and when i get time and post results here.


    • dougaj4 says:

      Miguel – you can download a corrected version at:


      I will write it up some time in the next few days, but I’d be grateful if you could have a look and confirm that you agree that it is now OK.


  26. Pingback: IP2 Update, ByRef and ByVal | Newton Excel Bach, not (just) an Excel Blog

  27. Karla says:

    I’d like to graph intersections, without connecting lines. For example, I need to graph the intersecting points for 4 sectors:
    Sector x, y
    North 50, 50
    South 60, 40
    East 30, 70
    West 10, 90
    where the x-axis is number of strategic initiatives, y-axis is number of operational initiatives. The range of each of the axis should be 0 to 100.
    seems like it would be very simple to do in excel, but I don’t know how to do it. PLEASE HELP! TIA.


  28. dougaj4 says:

    Karla – I don’t know what intersections you want to plot. The points you gave are all on the same straight line. A sketch would be helpful. You can e-mail to dougaj4 at gmail.


  29. Petrus says:

    Would it be possible to use the IPSSS Function to do 2d Trilateration with provided GPS decimal lat long circle centres and a specified radius for each circle. If possible, how can it be done


  30. Pingback: Anonymous

  31. Pingback: Daily Download 16: Intersections, interpolations, and rotations | Newton Excel Bach, not (just) an Excel Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s