JimYuan's Blog

Sharing the things I learned

0%

PhysicalSimulationIntrodutionInGH

Intro

In grasshopper field, there’re some useful and famous plug-ins for phyiscal simulation. Just to mention a few, Kangaroo, Flexhopper,… and etc.
I always think it’s more fun to play around the modelling which mimic the realistic phyiscal behaviours. This post is for noting down some developers’ thoughts while developing the phyiscal simulation tools.

And again this amazing tutorial is from Professor. Jose.
Here’s the link:

https://www.youtube.com/watch?v=kG-AxzMPjxk&t=5311s

Also, one important concept before doing simulations would be iteration.

Iteration

Usually, the physic behaviors are related to time, meaning it’s a function of time.
In code, we need to make sure the result of previous round can be brought to the next round.
Might be seen something like this.

1
NextRound += PreviousRound;

Iteration In C# script Component

https://www.youtube.com/watch?v=ek2iL88WqGQ&t=497s
Professor Jose well explained the scope of the variables in C# script component, which is one of the vital ingredient before you do any simualtion related to time.

Code

Here I would like to share one of the example in this tutorial.
idea

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
private void RunScript(bool reset, Point3d anchorPoint, Point3d startPoint, double radius, Vector3d gravity, double stiffness, double friction, ref object L, ref object S, ref object P, ref object V)
{
//Algorithm
if(reset)
{
currentLocation = startPoint;
currentVelocity = Vector3d.Zero;
}

// Calculate all forces acting on the particle
Vector3d gravityForce = gravity;
Vector3d springForce = -stiffness * (currentLocation - anchorPoint);

Vector3d totalForces = gravityForce + springForce;

// Update the currentVelocity with all the acting forces
currentVelocity += totalForces;

// Damp down velocity a little assuming friction on the system
currentVelocity *= friction;

// Update the location based on the velocity
currentLocation += currentVelocity;

// Output
L = new Line(anchorPoint, currentLocation);
S = new Sphere(currentLocation, radius);
P = currentLocation;
V = currentVelocity;
}

// <Custom additional code>
Point3d currentLocation = Point3d.Unset;
Vector3d currentVelocity = Vector3d.Unset;