home processing download documents tutorial python tutorial gallery source about
 Python Tutorials (back to the list of tutorials)

Particle-based Branching Algorithm with Spring Force(requires iGeo version 0.9.1.5)

     Line Agent with Particle and Spring

This page shows branching algorithm with particle and spring integrating particle-based agents and reproduction-based agents.

The first code below has a line agent class LineAgent which reproduces a child line agent in a specific direction but the agent class inherits IParticle class instead of inheriting IAgent class in the previous line agent classes like the ones in this page. In the update method, the agent instantiates ISpringLine which is a line with spring force to maintain the distance of two end point particles instead of a simple line in the previous line agents.


Warning: include(codepy/igeo_tutorial57_1/igeo_tutorial57_1.html): failed to open stream: No such file or directory in /home/mj7789dybiu5/public_html/igeo/tutorial/tutorial.php on line 66

Warning: include(): Failed opening 'codepy/igeo_tutorial57_1/igeo_tutorial57_1.html' for inclusion (include_path='.:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php') in /home/mj7789dybiu5/public_html/igeo/tutorial/tutorial.php on line 66

The below codes shows the response of particle-based line agents to some force fields like attractors.


Warning: include(codepy/igeo_tutorial57_2/igeo_tutorial57_2.html): failed to open stream: No such file or directory in /home/mj7789dybiu5/public_html/igeo/tutorial/tutorial.php on line 66

Warning: include(): Failed opening 'codepy/igeo_tutorial57_2/igeo_tutorial57_2.html' for inclusion (include_path='.:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php') in /home/mj7789dybiu5/public_html/igeo/tutorial/tutorial.php on line 66


     Branching Particle-based Line Agent

The code below adds the branching logic in the update method with random probability of 5% and shows the response of the all branching lines to the force fields. It also adds coloring logic to the line based on time.


Warning: include(codepy/igeo_tutorial57_3/igeo_tutorial57_3.html): failed to open stream: No such file or directory in /home/mj7789dybiu5/public_html/igeo/tutorial/tutorial.php on line 66

Warning: include(): Failed opening 'codepy/igeo_tutorial57_3/igeo_tutorial57_3.html' for inclusion (include_path='.:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php') in /home/mj7789dybiu5/public_html/igeo/tutorial/tutorial.php on line 66


     Collision Detection

The code below adds the logic of collision detection for branching lines not to intersect each other during the growth. The interaction method is added in LineAgent to check collision with other LineAgent instances by calculating intersection of line segments. The result of the collision detection is stored in the boolean variable isColliding in the interact method and used in the update method either to delete the agent instance or to make a spring line and child agents.


Warning: include(codepy/igeo_tutorial57_4/igeo_tutorial57_4.html): failed to open stream: No such file or directory in /home/mj7789dybiu5/public_html/igeo/tutorial/tutorial.php on line 66

Warning: include(): Failed opening 'codepy/igeo_tutorial57_4/igeo_tutorial57_4.html' for inclusion (include_path='.:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php') in /home/mj7789dybiu5/public_html/igeo/tutorial/tutorial.php on line 66


     Branching and Growth Angle Control

To change the branch geometry not too straight or parallel, the next codes changes the way of defining the child agents' direction. Now both of two child agents are bent one direction and the opposite direction. Bending the first child agent towards the left or the right is determined randomly.


Warning: include(codepy/igeo_tutorial57_5/igeo_tutorial57_5.html): failed to open stream: No such file or directory in /home/mj7789dybiu5/public_html/igeo/tutorial/tutorial.php on line 66

Warning: include(): Failed opening 'codepy/igeo_tutorial57_5/igeo_tutorial57_5.html' for inclusion (include_path='.:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php') in /home/mj7789dybiu5/public_html/igeo/tutorial/tutorial.php on line 66

     Setting Spring Length

The code below explicitly set the length of the spring line with len() method. When the length is not set by len() method, the spring length is set to the initial length of the line. This line in the code
ln.len(ln.len()*2);
set the spring length to be the double of the initial length.


Warning: include(codepy/igeo_tutorial57_6/igeo_tutorial57_6.html): failed to open stream: No such file or directory in /home/mj7789dybiu5/public_html/igeo/tutorial/tutorial.php on line 66

Warning: include(): Failed opening 'codepy/igeo_tutorial57_6/igeo_tutorial57_6.html' for inclusion (include_path='.:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php') in /home/mj7789dybiu5/public_html/igeo/tutorial/tutorial.php on line 66

As a result of setting the spring length to be the double of the original branch length, it expands after it's created making the lines jaggy.


     Smoothing Branch Lines with Straightener

To make the branch lines smoother, the agent in the next code adds straightening force which applies force to three particle points of the agent, the parent agent and the grandparent agent. IStraightenerCurve applies the straightener force and also creates a curve out of three points.


Warning: include(codepy/igeo_tutorial57_7/igeo_tutorial57_7.html): failed to open stream: No such file or directory in /home/mj7789dybiu5/public_html/igeo/tutorial/tutorial.php on line 66

Warning: include(): Failed opening 'codepy/igeo_tutorial57_7/igeo_tutorial57_7.html' for inclusion (include_path='.:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php') in /home/mj7789dybiu5/public_html/igeo/tutorial/tutorial.php on line 66


     Bundling Close Branches

The code below adds lines of codes in the interact method after collision detection codes to tie close agents together with ISpringLine. The code also introduces the variable root to know which branch each agent belongs to. The tie is made only when the two agents belong to different branches. The length of the ISpringLine instance connecting two agents is set to be dir.len()*1.5 to keep consistent distance when branches are tied together. As a result of this logic, the branches are bundled together in a smooth and consistent way.


Warning: include(codepy/igeo_tutorial57_8/igeo_tutorial57_8.html): failed to open stream: No such file or directory in /home/mj7789dybiu5/public_html/igeo/tutorial/tutorial.php on line 66

Warning: include(): Failed opening 'codepy/igeo_tutorial57_8/igeo_tutorial57_8.html' for inclusion (include_path='.:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php') in /home/mj7789dybiu5/public_html/igeo/tutorial/tutorial.php on line 66


     Applying More Force Field

To demonstrate a variation of branch formation, the next code adds one more force field of IPointCurlField in the beginning. This single force fields is applied to all branch agents and deform the whole branch to the twisted formation.


Warning: include(codepy/igeo_tutorial57_9/igeo_tutorial57_9.html): failed to open stream: No such file or directory in /home/mj7789dybiu5/public_html/igeo/tutorial/tutorial.php on line 66

Warning: include(): Failed opening 'codepy/igeo_tutorial57_9/igeo_tutorial57_9.html' for inclusion (include_path='.:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php') in /home/mj7789dybiu5/public_html/igeo/tutorial/tutorial.php on line 66


(back to the list of tutorials)

HOME
FOR PROCESSING
DOWNLOAD
DOCUMENTS
TUTORIALS (Java / Python)
GALLERY
SOURCE CODE(GitHub)
PRIVACY POLICY
ABOUT/CONTACT