We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Vector Fields And Dynamic Attractors
Page Index Toggle Pages: 1
Vector Fields And Dynamic Attractors (Read 1128 times)
Vector Fields And Dynamic Attractors
Apr 26th, 2008, 6:32am
 
I'm working on a sketch that for now will start in 2 dimensions.

I want to start very simple and just create an array of arrows across the canvas pointing to 90 degrees. This part I can accomplish very easily with nested for loop.

The second part is to create the attractor. I'm really a beginner when it comes to particle fields. I've had a look at the Traer physics library but I could really really really use a little guidance or a solid reference material to turn to when I'm baffled.

I've been hacking apart whatever I can find but I still can't get away from a mode of thinking where the vector field is going to displayed at a individual moment. I'm lost on how I would create a field where the attractor could be something like the mouse pointer.

Man ... I just had a flash in my head that there's already a proessing example I've seen somehwere that shows a screen of arrows following the cursor.

eeehhhh, that could be the reference I need! anyone remember? I'm gonna go searh.

found it on the alpha site. of course it's some more of Robert Hodgin's beautiful work, albeit early (2003 it looks like!!!) I guess it's fitting since I've been on flight404.com for at least a portion of every few hours. haha.

I'm still not finding a way to keep the field stationery. I want to visualize the forces instead of simulate the motion I guess? Just show the initial trajectory for each vector.

Thanks in advance, all suggestions welcome!
Re: Vector Fields And Dynamic Attractors
Reply #1 - Mar 9th, 2009, 2:06am
 
sounds interesting. did you get anywhere with this? I need references for something to portray gradient fields...
Re: Vector Fields And Dynamic Attractors
Reply #2 - Mar 12th, 2009, 2:24pm
 
Hi

I just put together the simplest form of "point to mouse" script I could think off.
Hope it can help you a little to adjust some of the larger flocking/Vector3D examples.

Code:

float deltaX;
float deltaY;
float radian;
float degree;
Arrow arrow;

void setup()
{
 size(300, 300);
 arrow = new Arrow();  
}

void draw()
{
  deltaX = mouseX - width/2;  //arrow.x
  deltaY = mouseY - height/2;   //arrow.y
  radian = atan2(deltaY, deltaX);
  //degree = radian * 180/PI; //not needed as rotation takes radians
  arrow.update(radian);
}


and this small fellow...not pretty I know..

Code:

class Arrow
{
 float rotation;
 
 Arrow()
 {

 }
 
 void update(float rotation)
 {
   background(2555);
   pushMatrix();
   translate(width/2, height/2);
   rotate(rotation);
   rect(0, 0, 50, 10);
   popMatrix();
 }
}



From here on I would say it is something like finding the distance from the mouse/attractor to the vector/arrow and calculate if the vector should react or not.
Something like toxi's Vector class or the new Vector class added to processing 1.0 could handle all those calculations for you.
Page Index Toggle Pages: 1