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 & HelpSyntax Questions › a moving object that record its trails
Page Index Toggle Pages: 1
a moving object that record its trails (Read 724 times)
a moving object that record its trails
May 27th, 2009, 12:21am
 
Hello, in a program i have some agents that moves randomly in the 2d , im using perlin noise to drive the movement of my agents. My question is : how can i make that each agent can record the history of its positions( x, y)  or its trails ?

which is the best way of doing this?


thanks

P.
Re: a moving object that record its trails
Reply #1 - May 27th, 2009, 2:00am
 
I would create an ArrayList of PVector: on each move, create a new PVector with the new x and y coordinates, and add() it to the list.
Re: a moving object that record its trails
Reply #2 - May 27th, 2009, 4:14am
 
Hi PhiLho , one thing : i want to store in the array all the positions of my agents,  if each agent is going to be drawed 30 times in a second. This means that each time a draw agent function is called a new position is added to my array list. this is going to be very slow, since each second 30  new positions are added to my arraylist. my program crashes after less than a minute. how can i fix something like this?


thanks

P.
Re: a moving object that record its trails
Reply #3 - May 27th, 2009, 5:56am
 
I've had to deal with a similar problem in an entirely different environment recently.  If it doesn't degrade accuracy too much you could just store the position every second...  that would reduce the amount of data being stored, but obviously would only keep things running a bit longer (well I guess about 30 times longer) - you'd eventually still run into the same problem.

Otherwise you could follow the same approach suggested for a drawing program recently - draw the trace onto an image.  Obviously the issue then would be that you no longer have the information as accessible data... Guess it depends on your needs.
Re: a moving object that record its trails
Reply #4 - May 27th, 2009, 8:30am
 
What blindfish said...
You can sample at a given interval, store value only if different enough of previous one (would need a timestamp too, probably), etc.
You can also allocate more memory to your sketch... by default it is quite low. See in Preference.
Re: a moving object that record its trails
Reply #5 - May 27th, 2009, 10:05am
 
whats a timestamp?
Re: a moving object that record its trails
Reply #6 - May 27th, 2009, 10:59am
 
timestamp = wikipedia reference

You could generate one using the date methods (see related under day()) unless there's a simpler way in Processing (or probably Java)

A simpler, albeit more crude, way to reduce the rate of data storage would be to have a counter variable, increment it each frame and when it hits 30 (for example) store a point and reset it to 0.  Then at 30 fps you'll get a record approximately each second.  Not sure whether this would cause performance issues though - my use-case was aimed to reduce the amount of data rather than reduce performance issues...
Re: a moving object that record its trails
Reply #7 - May 27th, 2009, 2:06pm
 
An int's maximum value is 2147483647

2147483647 / 30fps = 71582788.233
71582788.233 / 60 sec = 1193046.470
1193046.470 / 60 min = 19884.107
19884.107 / 24 hrs = 828.504
828.504 / 365 days = 2.269

So if you just used a regular int to count the amount of frames that have passed, your program can constantly run for over 2 years.

Frame counting is possibly the simplest method of stamping a time on an event.

The only way you're going to preserve memory is in two ways.

* draw to a PGraphics the current progress for the whole image
* periodically dump all array information into files. I would recommend learning how to convert the data into bytes rather than strings, because you're going to run out of disk space rather rapidly.

You problem afterwards is decoding the files, but you can also save out the PGraphics as well.

I did something similar a long time ago, albeit just recording x positions to data files:

http://www.robotacid.com/PBeta/boxdemo.html
Re: a moving object that record its trails
Reply #8 - May 30th, 2009, 8:26am
 
ok, how about if i record the points each 1 second and i would like to create an interpolation between points? for example 5 points between each 2 points that is being recorded. how can i do that?


thanks

P.
Re: a moving object that record its trails
Reply #9 - May 30th, 2009, 8:58am
 
Interpolation is easy with the lerp() function. You do it in real time when you need to draw the line.
Although come to think of it, I don't see the point of interpolation here, if it is linear.
Page Index Toggle Pages: 1