Grasshopper

algorithmic modeling for Rhino

How to create a recursive loop to find the minimum common denominator between two given numbers in grasshopper

Hi all,

I'm trying to develop the structure using the Euclid's Algorithm to map any two chosen numbers in 3d space after they have gone through the algorithm. 

Please see attached images.

I choose 20 and 12 as the first two numbers to find the greatest common divisor. For the numbers I got when it went through algorithm I assigned points and mapped on xyz plane and then connected them with lines to develop the structure.

The problem is, that at the moment, I am able just to input these numbers manually.

Is it any way that I could develop the grasshopper script to be able to input any two random numbers and then it would expand these numbers through Euclid algorithm that finally I could get points in 3d space???  

The script should create a recursive loop to find the minimum common denominator between two given numbers. 

All the numbers that would come out from the algorithm would be assigned as coordinates for the points .

Views: 2601

Attachments:

Replies to This Discussion

Recursion is basically impossible to achieve using standard Grasshopper networks.

--

David Rutten

david@mcneel.com

Tirol, Austria

Attachments:

Thanks, for your reply. This seems close from what I'm trying to get. But I don't know how is it possible to extract reminder as z value or in general assign generated numbers as coordinates? Because coordinates are shown as  {0;0;0}  {0;0;1}...and it doesn't position the points in the way I need it.

Attachments:

You pull apart your coordinates using [Deconstruct Point], run the X and Y's through the script and then you reassemble the points on the other end using [Construct Point] with the original X and Y's but using the gcd output as Z.

Or I misunderstood what you're trying to do...

--

David Rutten

david@mcneel.com

Tirol, Austria

Thanks! Almost there! Just z coordinate doesn't change when it should change after every round. Because Z coordinate is not gcd, is the reminder, left after num1 mod num2 , so every time it has a different value. The algorithm, which finds gcd, was chosen to generate numbers that could be assigned as coordinates. Found gcd will be used later on as the division number to divide the distances between points.

The points after run through the script, should match the points that I input manually,  then it will be exactly what I'm trying to get.

I have the script for the processing which generates these numbers (in attached image it is shown in the bottom line with black background).

Is it anyhow possible to input this into a VB script? Maybe that would help...?

Attachments:

Alternatively, you can also find the greatest common divisor without going through any recursions, like this (screenshot):

Though I have to admit I didn't really get what's going on with the algorithm. How did it help to find the GCD?

It finds all the divisors for both numbers, then finds the divisors that are in both lists, sorts them and picks the biggest one. It's a neat solution Sridevi, good call.

--

David Rutten

david@mcneel.com

Tirol, Austria

Thanks! I call this Sridevi's algorithm (uggh...how vain). But it doesn't apply Euclid's algorithm, so maybe its not very useful in this case, after all.

Cool Definition. I like brute force calculations. Takes 10 The time to calc but hey tomorrow we will have another theory how to weld to pieces of metal together. So whats the ratio of calculation time to development time in a develop and throw away World?

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service