#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# Find 5 Largest Values In A Linked List in Processing/Java

edited December 2013

Hello Community,

So I got this code that is getting x,y positions from a motion sensor tracking a hand. The app draws a circle in the middle of the screen and then I have a function that will detect if the hand is outside of the circle. While the hand is outside of the circle, I have a function that checks the distance of the hand from the center of the circle. I'm attempting to store the distance data while the hand is outside of the circle into a linked list.

I need to get the top 5 largest values for each time the hand is outside the circle and also length of time.

Here my code thus far; I've left out a bunch of the code for setting up the motion sensor just for simplicity so this is semi pseudocode. In any case, my main issue is getting the values I need from the list. I have the circle class included as well. I do the outside of the circle calculation and how far outside of calculation inside of my circle class.

Please let me know if this makes sense! The motion sensor is reading in data at 200 fps so efficiency is factor here. On top of that, I am only expecting the hand to be outside of the circle for a few seconds at a time back and forth.

``````    import java.util.*;

public void setup()
{
size(800, 300);
HandPosition = new PVector(0, 0); //This is getting x,y values from motion sensor
aCircle = new Circle(); //my class just draws a circle to center of screen
aCircle.draw();
}

public void draw()
{

if (aCircle.isOut(HandPosition)) /* detects if movement is outside of circle. Would it make more sense for this to be a while loop? I also need to start a timer as soon as this happens but that shouldn't be hard */
{
values.add(aCircle.GetDistance(HandPosition));  //gets how far the hand is from center of circle and adds it to linked list. Allegedly at least, I think this will work.
/*So I need to get the 5 largest value from inside of my linked list here.
I also need to start a timer*/
}
}

class Circle {

PVector mCenter;

Circle()
{
// initialize the center position vector
mCenter = new PVector(0,0);
mCenter.set((width/2),(height/2));
}

boolean isOut(PVector Position) //detects if hand position is outside of circle
{
}

float GetDistance(PVector Position) //detects how far the hand is from the center of circle
{
return mCenter.dist(Position);
}

void draw() {
}

}
``````

I'm new to Processing as well so don't hold back if any of this works.

Tagged: