# function returning ofPoint, how to return x, y

Just wondering if there is any more elegant (less variables) way of doing this, maybe without output variable, using “this” or something like that.
Thanks

``````

ofPoint r2xy (float a, float m) {
ofPoint output;
output.x = m * cos(PI*a/180.0);
output.y = m * sin(PI*a/180.0);
return output;
}

``````

you can do:

``````
ofPoint r2xy (float a, float m) {
return ofPoint ( m * cos(PI*a/180.0), m * sin(PI*a/180.0) );
}

``````

but you syntax is actually clearer and the compiler will optimize it to be the same as this so it’s not really needed if you are worried about performance

what arturo said,

but after looking at it for a sec i realized you’re just doing polar to cartesian conversion, and i’m kind of surprised this isn’t in the core. it should be a method of ofVec2f maybe.

Thanks Arturo & Kyle
Yeah I’m changing my polar to cartesian to ofPoint, maybe using ofPoint as parameters too… or ofVec2f

``````

ofPoint p2c (ofPoint ar) { // radial, polar to cartesian, angle, radius
return ofPoint ( ar.y * cos(PI*ar.x/180.0), ar.y * sin(PI*ar.x/180.0) );
}

``````

something that can make things faster if you’re calling this function a lot is changing it like:

``````
ofPoint p2c (const ofPoint & ar) { // radial, polar to cartesian, angle, radius
return ofPoint ( ar.y * cos(PI*ar.x/180.0), ar.y * sin(PI*ar.x/180.0) );
}

``````

that way you avoid a copy each time you call it.

Thanks Arturo!