# 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.

thx.

``````
vector<ofVec2f> points;

//--------------------------------------------------------------
void testApp::update(){

points.push_back(ofVec2f(mouseX,mouseY));

}

//--------------------------------------------------------------
void testApp::draw(){

ofSetColor(0);
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!