We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello! I'm trying to figure out a way to put route lat lon coordinates (200 rows) from datasource1 inside a 'mover' class where the other variables (speed, age, type etc.) come from datasource2. The datasource2 has 10,000 movers (i.e. 10,000 rows of data), each of which needs to follow the route (200 lat lon pairs from datasource1).
My question is: Does anyone know if it is possible to include an ArrayList PVector (the lat lon coordinate pairs) inside a class of movers that has other attributes such as speed? Or can anyone suggest alternative approaches? I haven't found any examples of similar projects.
I have drawn the route as continuous spline curve (curveVertex) and was planning to create the movers as curvePoints, but not so sure anymore. Any constructive ideas most welcome!
Answers
I am not sure I fully understood your need (tired after a long day of work), but to answer your subject: yes, you can put an array list of PVectors in a class. No problem.
Thanks @PhiLho for confirming that it should be possible. I haven't got it working and have not found examples, so wasn't sure if it was even possible. Are you aware of any examples that shows how to make an ArrayList of Objects that contain an ArrayList of PVectors, and then how to access/iterate through the PVector values?
Here's a where I am at the moment:
You can do
run.coords.add(somePVector);
for example.Or make loadRoute to return the list of coords, which will be declared locally to the function, not globally. Then you can do
run.coords = loadRoute();
in loadMovers().Thanks! I'll give it a go this weekend.
Thanks @PhiLho I managed to put the ArrayList of PVectors inside an ArrayList of Mover objects. However, I have not yet figured out how to iterate through the ArrayList of PVectors inside the objects (pls see the void drawMovers in the code below). I keep getting IndexOutOfBoundsException notification, I guess because the ArrayList of PVectors size is 200, whereas the ArrayList of Movers is 10,000. Should it be another for loop straight after Mover currentMover = (Mover) movers.get(i)? Or something else? Thanks for all your help so far, it has helped me progress with this piece of work.
Here's my current code:
I guess you need to read about variable scopes: :-B
http://forum.processing.org/two/discussion/10276/why-can-t-i-access-my-variables-from-void-draw-in-void-mousepressed#Comment_39761
Thanks @GoToLoop. I've read about variable scopes as you suggested, but have still not been able to figure out the answer to my problem.
Could you specify what you think I should do, so that the ArrayList of PVectors inside each Mover object gets iterated through properly? Each Mover (10,000 of them in the ArrayList of Movers) has to follow the same route (the ArrayList of 200 PVectors). I've slightly edited the code above to show my current thinking (pls see the drawMovers), but am still getting the same IndexOutOfBoundsException notification.