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:
float ratio = (float)app::getWindowWidth()/app::getWindowHeight();
gl::pushMatrices();
gl::translate(m_Pos*ratio);
gl::scale(m_size*ratio,m_size*ratio);
gl::color(ci::Color(1,1,1));
gl::drawLine(Vec2f(20,0),Vec2f(80,0));
gl::drawLine(Vec2f(80,0),Vec2f(100,20));
gl::drawLine(Vec2f(100,20),Vec2f(100,50));
gl::drawLine(Vec2f(100,50),Vec2f(60,100));
gl::drawLine(Vec2f(60,100),Vec2f(40,100));
gl::drawLine(Vec2f(40,100),Vec2f(50,70));
gl::drawLine(Vec2f(50,70),Vec2f(25,90));
gl::drawLine(Vec2f(25,90),Vec2f(0,70));
gl::drawLine(Vec2f(0,70),Vec2f(20,40));
gl::drawLine(Vec2f(20,40),Vec2f(0,20));
gl::drawLine(Vec2f(0,20),Vec2f(20,0));
gl::popMatrices();
gl::pushMatrices();
float radius = getRadius();
Vec2f center = Vec2f(m_Pos.x+50, m_Pos.y+50);
gl::drawStrokedCircle(center*ratio, 10);
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;
}