Grasshopper

algorithmic modeling for Rhino

Hello,

i want to generate sequence of numbers as following

X/30 (1st and last divided length of curve)

X/10 (repeated 6 times and alternate)

X/15 (repeated 5 times and alternate)

X/10

X/15

X/10

X/15

X/10

X/15

X/10

X/15

X/10

X/30

X = length of a curve. When added these will add upto length of curve too.

Then divide curve with these numbers.

Can can any-1 help out with generating number sequence to begin with?

Regards,

AB

Views: 1634

Replies to This Discussion

I think there might be a subtle error in your description of the problem...?

When I look at your sequence, I see it this way: 1,3,2,3,2,3,2,3,2,3,2,3,2,1 (1/30, 3/30ths, 2/30ths, etc.)

But those add up to 32, not 30.  I didn't see anything about the pattern that inspired me to generate the sequence parameterically, so I moved on to dividing the curve.

  1. I entered the sequence of numbers in a 'Panel', parsed them using 'Text Split (Split on comma)', divided the length of the curve by their sum (32 from 'Mass Addition').
  2. Multiply each number in the list by that result.  This gives the length of each sub-curve/segment.
  3. 'Remap Numbers (ReMap)' lengths from '0 to curve length' to '0..1'.
  4. Use 'Series' and 'Sub List (SubSet)' to sum up ('MA') the segment lengths preceding each curve point (0..0, 0..1, 0..2, 0..3, etc.).  These are the 't' values needed for 'Shatter'.
  5. 'Flip' the output of 'MA' before passing the list of 't' values to 'Shatter'.  "Flatten' would work here too but experience shows that 'Flip' works better if you want to handle multiple curves.

This works with any sequence of numbers as inputs - integers or floating points.

Attachments:

Hello Joseph,

Very kind of you to reply :-). Probably i did not describe my problem properly.

X = total length of original curve. Say for instance X = 1200mm

X/30 = 40mm is repeated 2 times i.e. at the start & end

X/10 = 120mm is repeated 6 times (but alternates with X/15)

X/15 = 80mm is repeated 5 times (alternates with X/10)

So if you add (2x40) + (6x120) + (5x80) = 1200mm this should hold true for any integer.

The way i have tried to resolve is

weave repeat data X/10 6 times, X/10 5 times and weave the data. then insert X/30 as item 0. Then shatter the curve.

However, i was wondering if there was a formula and more straightforward way to handle it :-D

Hi Agneesh, not sure if this can be called straightforward but here's my two cents.

* = (2*x)-1

Attachments:

Pieter, I like the way you think!

I hadn't noticed the 'Partial Results (Pr)' output of 'Mass Addition' - that is very handy and simplifies my code:

Attachments:

OK, silly me.  I included an extra "2" in my sequence.  Change the panel to this:

1,3,2,3,2,3,2,3,2,3,2,3,1

At first, I did the same thing you did using 'Repeat Data', but I didn't see the point of going to the trouble since it wasn't easily adaptable to other patterns.  Hence my choice of the panel with a sequence of numbers that represent ratios of the line segments to each other.

As usual, Pieter's solution (below) is incredibly elegant and to the point!

N.B.: the parameter on the curve domain is not the same as (or directly comparable to) the distance along the curve. You'll need the EvaluateLength component to find the correct parameters.
Do a search for curve parameter length and you'll find dozens of discussions, some of which with a clear explanation.

"N.B."?  I thought "newbie" was one word?

You must be talking to me(?) because I can see the error I made using 'ReMap', correlating lengths to 't' values.  My bad, thank you.  (I knew better)

Revised:

Attachments:

Haha - you're joking, right?
It stands for 'nota bene', which is Latin for 'note well'.

So I didn't call you a newbie, grasshopper.  ;) 

Joseph & Pieter thanks for your inputs.

This is a wonderful community and very helpful members.

Pieter, i have used repeat data > weave > insert > shatter

but your definitions is 1 step less and relatively more refined.

Thanks for that.

AB

I tried applying this solution in another thread (How to divide a circle in segments of 2 different lengths) and discovered an off-by-one error in the previous code! An unnecessary 'Shift' that resulted in one fewer segments than expected. Don't know how I missed this...

Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service