ofVec2f average

how do i use the vector average function.

i know this line is wrong ofVec2f pointAverage = points.average(points,points.getPoint.size());
but i have no idea how to properly call average.

i could cycle through the points myself, but thought it would be nice to use ofVec2f average.


vector<ofVec2f> points;  
void testApp::update(){  
void testApp::draw(){  
	for(int i=0; i<points.size(); i++){  
		ofCircle(points[i], 1);  
	ofSetColor(255, 0, 0);  
	ofVec2f pointAverage = points.average(points,points.getPoint.size());  
	ofCircle(pointAverage, 1);  

you can get the average of a vector by dividing the sum of the points by the size

ofVec2f total(0,0);  
for(int i = 0; i < points.size(); i++){  
    total += points[i];  
ofVec2f average = total / points.size();  

this is useful for finding the centroid of a bunch of points. and works in 3d just the same!

thanks for the reply.

i was hoping to use the vec2f average function to get a sort of moving average.
meaning while accumulating more points i can check always against the current average.

so in your example, while total increases i am also able to know what the current average is.