Tag Archives: Co-ordinates



Mathematica is perfect for working with lists and matrices.  Essentially making it useful for defining and manipulating geometry through rotations and later on analysing the forces through stiffness methods.

A key task when working with series of co-ordinates is to check that the relative distances between points don't change so that the structural elements in between remain the same, even though the structure may have changed position and shape.  When you're working with Mathematica and there's a task that you need to do repeatedly it's often worth creating a custom function that can be called whenever needed.

A couple of the functions that I've written can determine the distance between each co-ordinate in a list for 2D and 3D co-ordinate lists.

First, create some co-ordinates to work with on the examples.

Now that we've got some points to work with we can create a function to determine the distance between the points in 2D.  On 2D points, Mathematica has an inbuilt function called  EuclideanDistance[] which is nice and fast when determining the distance between 2D points.

There are two key parts to the function, the first part maps a list of points across the   EuclideanDistance[] function, with the second section essentially iterating the co-ordinates to restructure the list so that the function can be mapped across the list by rearranging it in a  (First point, Second point)(Second point, Third point) format.... until the last element in the list.

This is nice and zippy for 2D co-ordinates, but won't work unfortunately for 3D and needs modifying to make use of the inbuilt function  Norm[] .

Running a comparison on speed for how 2D points are handled can be compared by zeroing out the Z ordinate.

As can be seen, EuclideanDistance[] is faster, but Norm[] is more flexible and can be used on 2D and 3D co-ordinates.



One of the things that I spend a lot of time doing in Mathematica is creating lists of co-ordinates so that I can export them into structural analysis software, either before or after I've rotated and transformed them through space to mimic a deployable structure.

Most of these methods I've picked up along the way through trawling Stack Exchange which I find a great resource for learning Mathematica, I'm not able to link to all of them as I've hoovered them up into a notebook over a long period of time and not kept all of the original links...

Creating lists.

Frequently I'll create a list of x co-ordinates, then y co-ordinates, then the z co-ordinates.  There are a multitude of ways to do this, a few of the ways to create a list of co-ordinates are linked below:

Other ways of creating lists, could make use of functions.

{0, 2, 4, 6, 8, 10}

{1, 4, 9, 16, 25}

Creating points

And there are dozens of other methods that are available, but once you have your list of x, y, and z co-0rdinates then the next step is to combine them.  You could certainly type them in long hand as below, but the more nodes you have the longer it takes.

You could automate a simple list of co-ordinates like above in a couple of ways:


Both return the same list of co-ordinates:

{{0, 0, 0}, {1, 0, 0}, {2, 0, 0}, {3, 0, 0}, {4, 0, 0}, {5, 0, 0}}

Combining lists.

Or you might have created a list of points, the same as the lists x,y, and z at the top of this post and now want to combine them...


Thread[ ] is available and is one of the quicker methods for knitting together lists.

{{0, 10, 0}, {1, 11, 1}, {2, 12, 2}, {3, 13, 3}, {4, 14, 4}, {5, 15, 5}, {6, 16, 6}}


An alternative is  MapThread[ ]


both return.

{{0, 10, 0}, {1, 11, 1}, {2, 12, 2}, {3, 13, 3}, {4, 14, 4}, {5, 15, 5}, {6, 16, 6}}


Transpose[ ]   can be used for nice tidy syntax


If there is a simple 2D set of co-ordinates, then these can be combined using  Inner[ ]


Again for simple 2D lists, the function  Riffle[ ] can be used, but needs to be used in combination with  Partition[ ]

If you're working with multiple lists, then a function called multiRiffle can be written, taken from here.


{{0, 10, 0}, {1, 11, 1}, {2, 12, 2}, {3, 13, 3}, {4, 14, 4}, {5, 15, 5}, {6, 16, 6}}


Custom functions.

If you only have 2D data points then a function could be written to knit them together, these functions can check to see if the lists are of the same length too which can be beneficial.

{{0, 10}, {1, 11}, {2, 12}, {3, 13}, {4, 14}, {5, 15}, {6, 16}}

Which can be adapted for 3D data points easily enough.

{{0, 10, 0}, {1, 11, 1}, {2, 12, 2}, {3, 13, 3}, {4, 14, 4}, {5, 15, 5}, {6, 16, 6}}

Hopefully this will help someone who's learning Mathematica who's going to be working with data points and co-ordinates a lot.  It seems to be a topic that gets asked a lot on Mathematica Stack Exchange so I thought it would be helpful to try and summarise up in one post.

General Tutorial


Following on from my last post where I was investigating how to determine the parabolic equation when only provided with three co-ordinates, I wanted to extend that knowledge and create a Mathematica sheet to allow me to do this without having to rely on Wolfram Alpha.  This is for two reasons, firstly if I don't have an internet connection, then I'm screwed as Wolfram Alpha isn't going to work for me... secondly I need to encourage a deeper understanding of the procedure and process if I'm going to get the most from Mathematica.

Screen Shot 2012-06-03 at 19.22.03

The first part is trying to determine the parabolic equation when I know three points on the curve, typically these are going to be the start, midpoint, and the end support point.  To give an appreciation of the geometry, it's important to firstly understand that parabolic curves are defined by the common equation:

f(x) = a{x^2} + bx + c

Determining the length of a parabola with cartesian co-ordinates is done through applying the equation below over the limits being considered.

Length = \int\limits_a^b {\sqrt {1 + {{\left( {\frac{{dy}}{{dx}}} \right)}^2}} dx}

As three co-ordinates are known along the curve, the equations can be expressed as follows, with (x1,y1) (x2,y2) (x3,y3) being taken as the co-ordinate points... this gives a nest of simultaneous equations that can be solved using traditional matrix methods or in this case elimination could be used given that one of the input variables is 0.

\begin{array}{l} ax_1^2 + b{x_1} + c = {y_1}\\ ax_2^2 + b{x_2} + c = {y_2}\\ ax_3^2 + b{x_3} + c = {y_3} \end{array}

 Taking the co-ordinates above as (0,500) (2050,0) (4100,500) for the input variables, this gives the simultaneous equations below to solve:-

{a{{\left( 0 \right)}^2} + b\left( 0 \right) + c = 500}

{a\left( {2050} \right)_{}^2 + b\left( {2050} \right) + c = 0}

{a\left( {4100} \right)_{}^2 + b\left( {4100} \right) + c = 500}

However, Mathematica is well equipped for solving simultaneous equations and simply requires that the expressions are stacked up neatly and logically.... there can be a few problems with mixing bracket types, but this is just down to practice.  To solve the simultaneous equations above, the following code will solve them, the double equals signs are used just to push up the accuracy of the expressions and Reals is used as an additional parameter just incase any of the solutions are imaginary numbers.

Solve[{a x1^2 + b x1 + c == y1, a x2^2 + b x2 + c == y2, a x3^2 + b x3 + c == y3}, {a, b, c}, Reals]

Which will return the following solution:-

a = \frac{1}{{8405}};b = - \frac{{20}}{{41}};c = 500

Substituting this back into the general expression determines the parabolic equation for this particular curve to be...

f(x) = \frac{{{x^2}}}{{8405}} - \frac{{20x}}{{41}} + 500

The last thing to do is to work out the length of the curve between the two support points, this is a simple process determined by:-

Length = \int\limits_0^{4100} {\sqrt {1 + {{\left( {\frac{{dy}}{{dx}}} \right)}^2}} dx}

For those of us with too little time on our hands, this calculation can easily be automated and defined within Mathematica using the following code, where f'[x] is used to differentiate the term within the brackets.

f[x_]:=500 - (20 x)/41 + x^2/8405;

NIntegrate[Sqrt[1 + (f'[x])^2], {x, 0, 4100}]

Which gives the length of the cable to be  4,257.24m  which matches Wolfram Alpha's answer perfectly... the next step is defining equal length links to segment this curve to start creating the geometry for parabolic cable-chain structures... that's definitely a post for another day.

The intention with this post is to help anyone who is trying to define parabolas and arc lengths using Mathematica... or traditional methods, if they've got time on their hands...