Catenary curve
-
Hi this is my second post in this Forum, so forgive me for any mistake I do in this post, but I have some code I want to share with you.
As I posted before, I'm not the big ruby-developer and I honestly am not an UI-designer, but I know my math and did some calculations for catenary curves. I thought here in this Forum are a lot of great developers, who might be interested in my code and have the ability to use it for their plugin, so Sketchup-Users can profit from it.
The catenary curve is basically a part of a hyperbola and represents the curve of a rope or chain between two poles, this code draws a catenary curve by the given height of the left pole (height_1), the height of the right pole (height_2), the distance between the poles (catenary_distance), length of the "rope" (catenary_length) and the number of edges(stepCount).
The trick is to find the radius 'a' at the curve's minimum, which can only be determined by approximation:
catenary_a(catenary_length, h2, catenary_distance, initial)
this could also be done by using the newton raphson method, but in this case I think my function works very well.
Before we get to the code, here some backgroundinfo on the math. I created a graph on https://www.desmos.com/calculator/xdjl6lqo3b, which shows you the basic calculations and the resulting curves, you can play around with the variables to see what happens, so you don't have to rewrite the code everytime you change a parameter.
To draw the curve you just have to call this function:
drawCatenary(height_1, height_2, catenary_distance, catenary_length, stepCount)
but there are some conitions you should handle before you call the function:
**
- all the input-parameters are in [mm]
- the height of the right pole must be greater than 0 (height_2 > 0)
- the height of the right pole must be greater than 0 (height_2 > 0)
- the distance must be greater than 0 (catenary_distance > 0)
- the for the length of the rope (catenary_length) the following condition has to be true:
catenary_length > Math.sqrt((height_2 - height_1)**2 + catenary_distance**2)
- the stepCount(Number of edges) should be greater than 0 (stepcount > 0), to get an exact drawing it should be greater than 12**
Finally here is the code The Ruby Code for the Catenary Curve
I hope somebody with more programming skills, can use this to build a plugin. I also hope that you will test this code and reply for errors or mistakes, so I can fix them. For any questions on the code, please don't hesitate to ask.
Have fun with it
All the best Marco
-
There is an existing plugin you might want to look at and compare to yours.
http://sketchucation.com/forums/viewtopic.php?f=323%26amp;t=45616%26amp;hilit=wire
-
Yes that's exactly what I was trying to do. that wiretool is great.
Thanks for that, but anyway my code is online, so if somebody wants to play around with this feel free to do so.
Marco
-
Where were you 7 years ago??
-
I was drawing with AutoCAD and wrote a lisp-script for that I just recently switched to Sketchup. But I read your posts from 2009 and I was working very hard to translate it from lisp to ruby a few weeks ago. By the way, you are one of the developers I was adressing, because I love your CleanUp Plugin, that's one of the reasons I switched from AutoCAD to Sketchup, because skilled developers do things like that. Maybe you can use my codes to program a nice plugin. Or if anyone has some Ideas, I would be glad to help with the math
-
I always wanted an extension that added a tool that let you specify the length of a curve, and then you could adjust the start and end of it within that constraint.
I had a quick look the other day of the code - looking at how it could be adapted to taking input from a Ruby tool.
Advertisement