I have drawn an asteroid object manually , and would like to get its center/radius by a specific equation. I think I can get them by calculated and hard-coded values.
The code to draw the asteroid:
void Asteroid::Draw()
{
float ratio = app::getWindowWidth()/app::getWindowHeight();
gl::pushMatrices();
gl::translate(m_Pos*ratio);
gl::scale(3.5*ratio,3.5*ratio,3.5*ratio);
gl::color(ci::Color(1,1,1));
gl::drawLine(Vec2f(-15,0),Vec2f(-10,-5));
gl::drawLine(Vec2f(-10,-5),Vec2f(-5,-5));
gl::drawLine(Vec2f(-5,-5),Vec2f(-5,-8));
gl::drawLine(Vec2f(-5,-8),Vec2f(5,-8));
gl::drawLine(Vec2f(5,-8),Vec2f(5,-5));
gl::drawLine(Vec2f(5,-5),Vec2f(10,-5));
gl::drawLine(Vec2f(10,-5),Vec2f(15,0));
gl::drawLine(Vec2f(15,0),Vec2f(10,5));
gl::drawLine(Vec2f(10,5),Vec2f(-10,5));
gl::drawLine(Vec2f(-10,5),Vec2f(-10,5));
gl::drawLine(Vec2f(-15,0),Vec2f(-10,5));
gl::popMatrices();
}
According to the answer I have written that code to calculate the radius, is it correct or not ?
cinder::Vec2f Asteroid::getCenter()
{
return ci::Vec2f(m_Pos.x, m_Pos.y);
}
double Asteroid::getRadius()
{
ci::Vec2f _vec = (getCenter()- Vec2f(15,5));
return _vec.length()*0.3f;
}