Grasshopper

algorithmic modeling for Rhino

One reason behind the rewrite of Kangaroo was to give you the power to customize and extend it.

This could include your own custom goal types, or scripts which make use of the solver to perform custom iteration, new components, or even whole new plugins.

In release 2.01 I've added some new functions to make such customization easier than before. To create a custom goal, you can now inherit from the abstract class GoalObject, and just provide a constructor and a Calculate method which tells the particles where it wants them to move to. A basic example of this is included in the 2.01 download as CustomGoal.gh.

This can be done in the Grasshopper scripting components without the need to compile anything, and you can even edit and update the scripts while the solver is running for instant debugging!

For custom iteration, I have also added a method PhysicalSystem.AssignPIndex to simplify the process of automatically indexing particles given by position. This is shown in the updated CustomIteration.gh example included with the download. The TensileRelaxScript.gh example on the additional examples page also shows how the particle indexes can assigned directly by the script.

I will be posting some further scripting examples here shortly.

This is a thread to answer any questions you might have about getting started with this. Feel free to ask about specific features, or for things you would like to see more examples of, or more general questions if there is something you'd like to use this for and want to know what is possible or where to start.

Views: 2602

Replies to This Discussion

Here's another example of a scripted custom goal. This time acting on 3 points and making use of a slider input

Attachments:

Thanks Daniel :)
I would love to know simple, easy things, from VB. Using gravity force (to move) or hold two points at the same distance. What I want to know is the declarations, access the library and a bit of internal logic. By this I mean things that maybe for you and other things are too obvious, but I think for me (and I guess for all novice in code) would be very important examples to start.

I agree :) But I understand how time consuming a better documentation could be...so, if this kind of posts could help to initiate that possible documentation of the library.  

I assume that a goal is a custom class defined in the kangaroo library namespace. So I guess it is the same as a Line or Circle (related to RhinoCommon)...it could be nice to have a more insightful conversation about it.

I would like to write a custom iteration component where some goal strengths/weightings are increased in each iteration to allow the solver to converge properly.

How do I go about doing this? I have tried playing about with the Goal.Weighting property but this doesn't seem to work. Any hints?

Cheers,

Sam

Is the above even possible with the current Kangaroo 2.02 scripting capabilities?

It basically involves changing weighting not at the goal definition but per solver iteration. This would be really handy, allowing slowly introducing hard constraints.

Hi Daniel,

I would like to know : is there a way to assign Goals such as CyclicQuads or Planarize to only a portion of a quad mesh ? For example, apply it only to the quads whose vertices verify z > 0. Scripting looks like a good option for this, but I do not see how to call the goals you implemented.  

Thanks in advance !

Hi Xavier,

Depends if you want the definition to update while solving. I.e. if during finding a solution the quad mesh portion changes (goes from z > 0 to z < 0) then this would have to be done via scripting. Otherwise you can simply split the mesh into two meshes and apply the goal to the appropriate portion.

Hi Sam,

Thank for your reply. Yes the mesh portion needs to change, so splitting would not work. And for scripting, I was wondering if the code written for CyclicQuad was accessible somehow from inside a C# box so that I do not have to re-code it.

The calculate method needs overwriting otherwise the z check won't be checked in each iteration I believe. So writing from scratch is your only option. Maybe Daniel Piker could give hints on how to write CyclicQuad?

Try to define an average circle - for each combination of 3 sets of points get the circle defined by the 3 points (rhino has an inbuilt Circle(p1, p2, p3) method). Next average the centre points and radii for all 4 circles. Finally move the points closer or further away from this average centre point based on the average radius??

If the latter then I think the only way would be to write a new custom goal yourself which checks for z > 0 / z < 0 within Calculate() method, otherwise this will not be updated within the solution.

Writing CyclicQuads and Planarize goals should just be a few lines of code.

Start with Daniel Pikers example above (April 7, 2015)

I will roll up my sleeves then ! Thank for your help Sam.

Just doing this in a non kangaroo context the following worked for me:

Circle c1 = new Circle(Pts[0], Pts[1], Pts[2]);
Circle c2 = new Circle(Pts[3], Pts[1], Pts[2]);
Circle c3 = new Circle(Pts[0], Pts[3], Pts[2]);
Circle c4 = new Circle(Pts[0], Pts[1], Pts[3]);
Point3d P_ave = 0.25 * (c1.Center + c2.Center + c3.Center + c4.Center);
double R_ave = 0.25 * (c1.Radius + c2.Radius + c3.Radius + c4.Radius);

List<Point3d> p_out = new List<Point3d>();

p_out.Add(P_ave + (Pts[0] - P_ave) * R_ave / P_ave.DistanceTo(Pts[0]));
p_out.Add(P_ave + (Pts[1] - P_ave) * R_ave / P_ave.DistanceTo(Pts[1]));
p_out.Add(P_ave + (Pts[2] - P_ave) * R_ave / P_ave.DistanceTo(Pts[2]));
p_out.Add(P_ave + (Pts[3] - P_ave) * R_ave / P_ave.DistanceTo(Pts[3]));

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service