sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Sine Curve (wave) script?

    Scheduled Pinned Locked Moved Developers' Forum
    24 Posts 6 Posters 4.5k Views 6 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.
    • J Offline
      Jim
      last edited by

      Here you go.

      
      a = 10.0.feet
      b = 250.0.feet
      pts = []
      0.step(b, 1.feet) do |x|
        y = a * Math;;sin( (x / b) * 2 * Math;;PI)
        pts << [x, y]
      end
      Sketchup.active_model.active_entities.add_edges pts
      
      

      Edited to use feet, and use Greyhead's example, and Math::PI.


      sine_wave.skp

      Hi

      1 Reply Last reply Reply Quote 0
      • T Offline
        todd burch
        last edited by

        FYI Jim - you can use Math::PI.

        Todd

        1 Reply Last reply Reply Quote 0
        • G Offline
          gata
          last edited by

          Another way is to make a rectangle or construction lines 20' x 250' and scale the wave.

          The formulas watkins and I gave are the same. When you add variables and other decorations to y = sin x, all you are doing is shifting and stretching the wave on the xy plane. SU can adjust the equation after a basic wave is created by using Move and Scale.

          1 Reply Last reply Reply Quote 0
          • G Offline
            gata
            last edited by

            This is interesting. I began trying the tricked out formulas listed above last night. All those formulas and others are clearly detailed in my old math text. I even copied and pasted the ones above. But k_tools would not generate anything. I was stuck with using the simplified formula.

            I was repeating things so often I almost wanted to tweak the script so is would remember last settings. The last time I looks, I think that means only adding a few additional lines of code.

            1 Reply Last reply Reply Quote 0
            • JClementsJ Offline
              JClements
              last edited by

              Thanks, all!

              Jim, about the code you posted.

              Is that a snippet from a Ruby script and can it be run from the Ruby console window? Or, could a Sine Script be written that asks user for unit of measure, length and amplitude and maybe the number segments?

              John

              John | Illustrator | Beaverton, Oregon

              1 Reply Last reply Reply Quote 0
              • G Offline
                GreyHead
                last edited by

                In K-tools you want the 2D-Graph Cartesian; Plane xy; Range & resolution 0 : 250 : 1; then Mathematical formula '10 * sin((x/250)2PI)'

                Bob

                PS Later: Actually this gives you 250m x 10m so needs rescaling.

                sine.jpg

                1 Reply Last reply Reply Quote 0
                • W Offline
                  watkins
                  last edited by

                  Dear John,

                  I do not know if this thread is still open, but the last post suggested that you still need a little help. Something more prescriptive perhaps.

                  Suggested approach:

                  1. use k_tools,
                  2. select 2D_Graph cartesian, and
                  3. select the plane.

                  Okay, you have to make a number of choices. Let us assume that you have elected to draw the sine wave on the XY plane. The first box you have to fill in is the plotting function's starting point on the X-axis. The second box is the end point for the plotting function. The step is how often you want the plotting function to calculate the equation Y=sin(theta); theta is a function of X and is dimensionless. Suppose you select X=0 as the start point, X=100 units as the end point, and X=1 units as the step, then the equation is solved at 100 points between X=0 and X=100. If you changed the step to 0.1 units then the equation would be solved at 1000 points.

                  The next box asks you to enter the equation for the sine wave. I imagine that at this point you are interested in:

                  1. the amplitude of the sine wave (call this A),and
                  2. the wavelength, or the distance between the beginning and end of a single wave (call this B).

                  The equation to use is Y = A * sin ((X/B) * 2 * 3.14159); you may recognise the numerical value of π. Extract from Wikipedia:

                  "Pi or π is one of the most important mathematical constants, approximately equal to 3.14159. It represents the ratio of any circle's circumference to its diameter in Euclidean geometry, which is the same as the ratio of a circle's area to the square of its radius. Many formulas from mathematics, science, and engineering involve π."

                  ..and this is where it all goes pear-shaped. Because if you use 0 units, 100 units, 1 unit for the start, stop and step, and Y = 100 units * sin(( X units/100) * 2 * 3.14159) for the function, then one might expect to see a sine wave starting at X=0, finishing at X=100, with an amplitude of 100 units and a wavelength of 100 units. In other words, a single complete sine wave of amplitude 100 units between X=0 and X=100. Well, the plotting function does produce one complete wave, but with all values multiplied by 1000. Don't ask me why. It might have something to do with the way Sketchup handles small entities.

                  So for a single sine wave of amplitude 100 units and wavelength 100 units plotted every 1 unit, enter 0,0.1,0.001, and then use Y = 0.1 * sin((X/0.1)* 2 * 3.14159). Don't forget the multipliers '*'and the extra brackets around (X/B).

                  For one complete sine wave of unit amplitude and unit wavelength use k_tools and enter 0,0.001,0.00001 and then use the formula Y=0.001 * sin((x/0.001)* 2 * 3.14159). Multiply the amplitude and the wavelength to scale in amplitude and wavelength. Change the end-point for plotting (increase the distance between start and stop) for more complete waves.

                  Hope this helps.

                  Regards,
                  Bob

                  1 Reply Last reply Reply Quote 0
                  • JClementsJ Offline
                    JClements
                    last edited by

                    Thank you Bob, for the clarification.

                    Regards, John

                    John | Illustrator | Beaverton, Oregon

                    1 Reply Last reply Reply Quote 0
                    • G Offline
                      GreyHead
                      last edited by

                      Just a couple of notes to add to the other Bob's last post.

                      • You can use PI in K2 Graphs formulae (saves having to type in 3.14159)
                      • K2 Graphs appears to use meters as a default unit. However the dimensions will show up in whatever units you have set to display. In Bob's case this seems to be millimeters, hence the need to correct by 1000. The scale factor to correct from meters to feet is .3048
                        Bob
                      1 Reply Last reply Reply Quote 0
                      • W Offline
                        watkins
                        last edited by

                        From one Bob to another,

                        Oops! Should have figured that out. Must be getting slow.

                        Regards,
                        Bob

                        1 Reply Last reply Reply Quote 0
                        • J Offline
                          Jim
                          last edited by

                          @jclements said:

                          Thanks, all!

                          Jim, about the code you posted.

                          Is that a snippet from a Ruby script and can it be run from the Ruby console window? Or, could a Sine Script be written that asks user for unit of measure, length and amplitude and maybe the number segments?

                          John

                          John,

                          If you still want it, I can write it up.

                          Hi

                          1 Reply Last reply Reply Quote 0
                          • JClementsJ Offline
                            JClements
                            last edited by

                            Jim, yes please. I am sure to use it. 😄

                            John | Illustrator | Beaverton, Oregon

                            1 Reply Last reply Reply Quote 0
                            • G Offline
                              gata
                              last edited by

                              Pathcopy.rb has a feature that allows you to copy to spacing http://www.smustard.com/script/PathCopy. So if you rather have a nice-looking, higher-poly curve and space components by a set distance along the curve, it seems possible.

                              1 Reply Last reply Reply Quote 0
                              • JClementsJ Offline
                                JClements
                                last edited by

                                Hi Gata.

                                I do use the copy along path script and it works nicely. But the trick here is to space (subdivided) equi-distant if you will, along an existing curve. The functions that Fred06 has provided are flexible enough to aid in doing this, plus, re-manipulate/smooth some complex curves.

                                John | Illustrator | Beaverton, Oregon

                                1 Reply Last reply Reply Quote 0
                                • J Offline
                                  Jim
                                  last edited by

                                  @jclements said:

                                  Thanks, all!

                                  Jim, about the code you posted.

                                  Is that a snippet from a Ruby script and can it be run from the Ruby console window? Or, could a Sine Script be written that asks user for unit of measure, length and amplitude and maybe the number segments?

                                  John

                                  John,

                                  301 Moved Permanently

                                  favicon

                                  (www.sketchucation.com)

                                  Hi

                                  1 Reply Last reply Reply Quote 0
                                  • JClementsJ Offline
                                    JClements
                                    last edited by

                                    Thank you, Jim!

                                    It works beautifully.

                                    Regards, John

                                    John | Illustrator | Beaverton, Oregon

                                    1 Reply Last reply Reply Quote 0
                                    • J Offline
                                      Jim
                                      last edited by

                                      I have updated the script to make it remember values between calls.

                                      301 Moved Permanently

                                      favicon

                                      (www.sketchucation.com)

                                      Hi

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

                                      Advertisement