Rod Goal and Bomb Goal code?

@DanielPiker, I am working on a goal, similar to Kangaroo’s Bomb Goal, that has an effect (basically an anti-gravity force for quicker form-finding) that would stop after a certain number of iterations as opposed to the Bomb Goal which has a force that starts after a certain number of iterations. It would be great to see the source of your Bomb Goal to understand how to go about this, but it’s not in your GitHub. Would you mind posting it there so I could see how that could work? I tried connecting the Iterations output from the Solver into a logic gate that would pass a Load Goal to the Solver until a specific number of iterations, but got a warning about recursion…see attached definition.

Also, do you happen to have the source for the Rod Goal that you could post on GitHub? That’s another one I wanted to clone and customize…

Thanks!

reverse_bomb.gh (9.8 KB)

Hi @wicket

Yes, I think making a goal dependent on the iteration count isn’t really possible without scripting.
Here’s the code from inside the bomb goal. Basically it knows the solver will call its calculate method every iteration, so it increments a counter each time this happens:

public class Bomb : GoalObject
    {
        int Count;       
        int DetonationTime;
        double Strength;

        public Bomb(Point3d Location, List<Point3d> Pts, int DetonationTime, double Strength)
        {
            Count = 0;
            this.DetonationTime = DetonationTime;
            this.Strength = Strength;

            PPos = new Point3d[Pts.Count + 1];
            PPos[0] = Location;
            for (int i = 0; i < Pts.Count;i++)
            {
                PPos[i + 1] = Pts[i];
            }
            Move = new Vector3d[Pts.Count + 1];
            Weighting = new double[Pts.Count + 1];
        }

        public override void Calculate(List<KangarooSolver.Particle> p)
        {
            Count++;

            int timeAfterDetonation = Count - DetonationTime;
            if (timeAfterDetonation > 0 && timeAfterDetonation < 100)
            {
                for (int i = 1; i < PIndex.Length; i++)
                {
                    Vector3d V = p[PIndex[i]].Position - p[PIndex[0]].Position;
                    double d = V.Length;
                    
                    if (timeAfterDetonation > d && timeAfterDetonation < d + 1)
                    {
                        V *= 3 / Math.Max(V.Length, 0.001);
                        Move[i] = V;
                        Weighting[i] = Strength;
                    }
                    else
                    {
                        Weighting[i] = 0;
                        Move[i] = Vector3d.Zero;
                    }

                }
            }
            else
            {
                for (int i = 0; i < PIndex.Length; i++)
                {
                    Weighting[i] = 0;
                }
            }
        }

    }

The rod component is actually not technically really a single goal, but in fact a tiny script that creates a list of angle goals and length goals.
It’s just like what you might create manually by combining those components, like shown here, but it takes care of the list shifting and matching for convenience.

Awesome, thank you @DanielPiker …super helpful. I’m not the best at C#, but I think I got my script/custom goal to do what I wanted it to: applying force to a bunch of points in the +Z direction for a limited amount of time. I’m attaching the .gh with the script for anyone else that may be interested.

templifter_goal.gh (15.0 KB)

1 Like