SOLVED: See my answer.
I'm trying to find a point that is interior to an arc so when a floodfill occurs it does not accidentally fill an area outside the arc. As long as the absolute value of the distance between the two angles: start and end; are less than PI this works (There are a couple extreme edge cases where the drawn lines are so close that the point picked is part of those lines, but that's for a different day...).
The problem I'm having is when the absolute value of the distance between the start and end angles is greater than PI the flood occurs on the exterior of the arc instead of the interior. One example of many is: if the arc starts at 0 and ends at 3PI/2 the absolute value of the distance is 3PI/2, the flood occurs between the angles as if the absolute value distance were PI/2 and floods the entire screen except the pac-man-shaped arc.
EDIT:
To avoid confusion, here is the definition of an arc according to allegro (and trigonometry in general):
void arc(BITMAP *bmp, int x, y, fixed ang1, ang2, int r, int color);
Draws a circular arc [minus the initial/terminal sides or center point] with centre [sic] x, y and radius r, in an anticlockwise [sic] direction starting from the angle a1 and ending when it reaches a2....Zero is to the right of the centre [sic] point, and larger values rotate anticlockwise [sic] from there.
Square brackets are my notation.
I've already taken care of converting from allegro's (stupid) use of fixed integers
to the proper radian
values.
END EDIT
void Arc::Draw(BITMAP* dest, int color, bool filled, bool showCenter, bool showSides) {
if(showSides || filled) {
Line initial(GetX(), GetY(), GetZ(), GetStartPoint().GetX(), GetStartPoint().GetY(), GetZ(), false);
initial.SetColor(color);
Line terminal(GetX(), GetY(), GetZ(), GetEndPoint().GetX(), GetEndPoint().GetY(), GetZ(), false);
terminal.SetColor(color);
initial.Draw(dest, initial.GetColor(), false);
terminal.Draw(dest, terminal.GetColor(), false);
} else if(showCenter) {
putpixel(dest, GetX(), GetY(), color);
}
//Draw arc first to prevent flood overflow.
arc(dest, GetX(), GetY(), AngleConverter::RadianToFixed(_startAngle), AngleConverter::RadianToFixed(_endAngle), _radius, color);
if(filled) {
double distance = std::fabs(this->_endAngle - this->_startAngle);
if(distance < a2de::A2DE_PI) {
Line displace(GetStartPoint(), GetEndPoint(), false);
Point displacePoint(displace.GetCenter());
floodfill(dest, displacePoint.GetX(), displacePoint.GetY(), color);
} else if(distance > a2de::A2DE_PI) {
Line displace(GetStartPoint(), GetEndPoint(), false);
Vector2D center_of_displacement(displace.GetCenter());
Vector2D center_point(this->_center);
Vector2D direction_of_center(center_of_displacement - center_point);
double angle = std::atan2(direction_of_center.GetY(), direction_of_center.GetX());
Vector2D flood_point = center_point - direction_of_center;
flood_point += angle;
double x = flood_point.GetX() > 0.0 ? std::ceilf(flood_point.GetX()) : std::floorf(flood_point.GetX());
double y = flood_point.GetY() > 0.0 ? std::ceilf(flood_point.GetY()) : std::floorf(flood_point.GetY());
floodfill(dest, x, y, color);
} else {
if(_startAngle == 0.0 || _endAngle == a2de::A2DE_2PI) {
floodfill(dest, GetX(), GetY() - 1, color);
} else if(_endAngle == 0.0 || _startAngle == a2de::A2DE_PI) {
floodfill(dest, GetX(), GetY() + 1, color);
}
}
}
}
SOLVED:
1) Calculate Center of Arc:
double e = GetEndAngle();
double s = GetStartAngle();
double d = e - s;
double arc_center_x = 0.0;
double arc_center_y = 0.0;
double offset = 0.0;
if(d < 0.0) {
offset = PI;
}
arc_center_x = (GetPosition().GetX() + std::cos(((s + e) / 2.0) + offset) * GetRadius());
arc_center_y = (GetPosition().GetY() + -std::sin(((s + e) / 2.0) + offset) * GetRadius());
_center = Vector2D(x, y);
2) Calculate Line from that center to the position of the sector:
Line l(arc_center_x, arc_center_y, p_x, p_y);
3) Get the mid-point of that line which is always interior to the angles of the sector:
double x = l.GetCenter().GetX();
double y = l.GetCenter().GetY();