sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Catenary curve

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 1.1k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • V Offline
      vitaleMarco
      last edited by

      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 Catenary curve with height 1, height 2, catenary_distance catenary_length

      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:

      **

      1. all the input-parameters are in [mm]
      2. the height of the right pole must be greater than 0 (height_2 > 0)
      3. the height of the right pole must be greater than 0 (height_2 > 0)
      4. the distance must be greater than 0 (catenary_distance > 0)
      5. 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)
      6. 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

      1 Reply Last reply Reply Quote 0
      • sdmitchS Offline
        sdmitch
        last edited by

        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

        Nothing is worthless, it can always be used as a bad example.

        http://sdmitch.blogspot.com/

        1 Reply Last reply Reply Quote 0
        • V Offline
          vitaleMarco
          last edited by

          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

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            Where were you 7 years ago?? πŸ˜„

            Thomas Thomassen β€” SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • V Offline
              vitaleMarco
              last edited by

              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 πŸ˜„

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                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.

                Thomas Thomassen β€” SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Buy SketchPlus
                Buy SUbD
                Buy WrapR
                Buy eBook
                Buy Modelur
                Buy Vertex Tools
                Buy SketchCuisine
                Buy FormFonts

                Advertisement