Code to calculate Catenary curves?
-
Anyone know of some code, in Ruby or some other language, that creates an Catenary curve between two points given the length of the cable/chain? 2D or 3D, preferable 3D.
The only stuff I find is written formulas, like the ones on Wikipedia, http://en.wikipedia.org/wiki/Catenary but I' not sure how to translate that into code.
-
Oh wait,..
@unknownuser said:
In physics and geometry, the catenary is the theoretical shape of a hanging flexible chain or cable when supported at its ends and acted upon by a uniform gravitational force (its own weight) and in equilibrium.
Does that mean the two points are at the same height? So if the points are at different height the catenary doesn't apply? -
hmmm... this seem to do what I want to,.. but the code is still not code in a format I'm familiar with. http://demonstrations.wolfram.com/CatenaryTheHangingChain/
-
No, in equilibrium just means that it is in a stable condition - for example, it is not still swinging around because you have just hung it up. The position of the endpoints does not matter.
-
I think ruby has a cosh method
Math.cosh
which should do it.The general equationm for the curve is: a cosh (x/a)=y
where a is a constant related to the weight of the chain and the tension on the chain.
As for putting this in to ruby, you'll probably need something like this:
a*(Math.cosh (x/a))
which will output the height for a point x units away form the lowest point of the curve.I'll stop there for the moment, if this is sounding like the sort of thing your after i'll keep going, if not i'll leave it there.
p.s. here is a graph which might make it a little easier to comprehend.
-
Thanks remus. This sound like what I'm after. I'm not used to interpreting equations like this.
btw, I don't see any graph.
-
Onwards it is.
I'll try and explain it in 2d first.
Essentially we need to get all the right bits to put in to the equation. Once we've got all the bits we can put the values in and get the co-ordinates of lots of points on the curve, which you'll then hopefully be able to turn in to a curve with some ruby magic.
First we need to find the lowest point on the curve. This is fairly easy to do if the points your going to be hanging your curve from are at the same height, it is simply the mid point between them. this point is x=0.
youll then need to choose a few points between x=0 (aka the lowest point on the curve) and the point from which the curve is hanging (on each side.) For example, looking at the a=2 graph i edited into my last post, if your hanging points are at x=3 and -3 we might then decide to use x=-3, -2, -1, 0, 1, 2 and 3 as our points.
We now need a value for a. Im not really sure how youre meant to work this out, so id suggest fudging it unless you really really need it to be accurate. Going by the graph, values from 2 to 5 would probably be ok.
all that is left to do now is put the values in to the equation, which will look something like this:
(a*Math.cosh (x/a))+(height of hanging point-(a*Math.cosh(x co-ordinate of hanging point/a))
This will give you the height of each point.We then have the height of each point and their distance along the the 'x-axis.' This is your series of points which you can then join up to make your curve.
Feel free to ask lots of qusetions, as that was quite a ramble and i could well have made a mistake somewhere.
-
Does the length of the curve vary here?
What I want to do, is connect a 'rope' between two point (height vary) where the length of the rope is given. So if the two points are close together it'll hang down allot, if the points are far away the rope straightens.
I don't understand in your example what gives the length of the curve.
From Wiki:
@unknownuser said:
The scaling factor a can be interpreted as the ratio between the horizontal component of the tension on the chain (a constant) and the weight of the chain per unit of length.
So a is affecting the tension of the 'rope'?
-
Could be quite tricky, although my understanding of catenary curves is pretty vague.
Im off for a few hours, so i'll think about it a bit and get back to you.
-
Thanks remus. I've found myself on deep water with this problem. Been a while since I've done any math beyond simple + - * /, but I've never done this kind of math.
(I can hear all my former math teachers laughing, quoting me "I'll never have any use of that in real life!" sigh )
-
Looking at: http://mathworld.wolfram.com/Catenary.html
@unknownuser said:
The arc length, curvature, and tangential angle for t>0 are given by
Is the first one the arch length?
-
Indeed i think the first one is arc length.
i've found another form that might be a bit more useful:
arc length = (2H/w)* sinh (wl/2H)
where H=horizontal tension on the cord, w=weight of the cord and and l=distance between the 2 points.
thinks a bit more
-
I've been searching some more on Catenary and it appears that the formulas assume the two points to be at equal height.
The example at wolfram site has code which generates a curve from points at different heights. http://demonstrations.wolfram.com/CatenaryTheHangingChain/
But I can't interpret the code. And it also appears to not be a variable width arc.The thing is, it's not required that I use the Catenary equation. It's just what seemed to be to be related to what I wanted to do. If anyone got other suggestions, I'm all ears.
-
Ok, i think i've sort of got it.
Essentially the problem boils down to finding the correct value of
a
for your length of rope and the distance between the 2 fixing points.This is given by
a=w/H
wherew
=weight of the rope andH
=horizontal force tensioning the rope. If you have got some accurate values for w and H you should be able to work out a and then substitute it back in to the original catenary equation (y=a*cosh(x/a)
)Thats the easy version, if you cant make that work i think it gets yet more complicated, as i dont think you can get a value for
a
easily only knowingL
.It should also be possible to make it work with points at unequal heights, although again it would add an extra level of complication.
p.s. the parabola is a reasonable approximation to a catenary curve, and could simplify the maths quite a bit. Probably worth having a look in to it if you dont need to be entirely accurate.
-
@remus said:
p.s. the parabola is a reasonable approximation to a catenary curve, and could simplify the maths quite a bit. Probably worth having a look in to it if you dont need to be entirely accurate.
Good point. I think that's worth investigating. I don't want to do a true physic simulation. Just something that closely looks like ropes.
The whole idea comes from last week when I modelled an old boat crane located on the site for a project at work. It has lots of wires hanging about. I had it rigged, but at some point I wanted to adjust it's arm positions, which resulted in me having to re-rig all the wires. So I thought I'd try to make a plugin which allowed you to pick to vertices in the model, specify a length and it'd make the rope. As you move/rotate the objects the rope/cable/wire is attached to they'll deform accordingly. That an making a plugin to allow me to set up pivot points which I can control from a webdialog so I get a control panel for the crane, or whatever you set up.)
Ok, parabola...
-
Having heard a bit more about your idea, are you absolutely sure you want to do it by specifying the length? i'm fairly sure you could do it by specifying the value of a.
-
How would that work? I'd still like it to hang more when the points are closer together. Would it do that?
Came across this: http://mathforum.org/library/drmath/view/53706.html looks interesting. Though, it's getting late now. Need to get some sleep. This stuff bends my brain.
-
Found two more resources about and unequal heights.
http://home.earthlink.net/~w6rmk/math/catenary.htm <- got an approximation, might be useful
http://members.chello.nl/j.beentjes3/Ruud/catfiles/catenary.pdf <- got some sample C code, but it seem to solve it by doing trial and error...now, seriously, sleep.
Again, thank you very much Remus for your input.
-
You would have to set a value of a for each curve, but then youd also have to set a length for each curve as well, so id imagine it'd work out pretty similar in terms of the amount of effort on the part of the user. I suppose you could also set the value for a relative to the distance between the 2 points, which should give you quite a similar effect to setting a length but without all the hard work.
As for the problem of unequal heights, from the links you provided it would seem an iterative method is necessary, although i'll look in to it a bit more.
If i remember i'll ask my maths tutor at college about it. Might know a good way of doing it.
-
Check out this port, this might help you.
http://sketchucation.com/forums/viewtopic.php?f=180%26amp;t=64842
All the best Marco
Advertisement