How to fill an arc?

I've got a problem which can sound stupid to someone. I have drawn an arc by calling TCanvas.Arc method, which looks like half-of-ellipse. It is vertically oriented. Now I need to fill a portion of inner space ocupated by arc with some color. If the arc would be bounded by some line I will use FloodFill method, but unfortunately it isn't. Any ideas dear experts?

Sincerely, Ivo.

LVL 2
Who is Participating?

Commented:
Try this.

Hope it helps,
Mark.

procedure TForm1.Button1Click(Sender: TObject);
var
ArcWidth, ArcHeight : integer;
ArcCentreX : integer;
WaterLevel : extended;
xlevel : integer;
a, b : extended;
begin
ArcWidth := 300;
ArcHeight := 100;
ArcCentreX := ArcWidth div 2;
WaterLevel := 27; // distance from the BOTTOM of the Arc
// water level can vary from 0 to ArcHeight div 2
with canvas do
begin
arc(0,0,ArcWidth,ArcHeight,0,ArcHeight div 2,ArcWidth,ArcHeight div 2);
moveto(0,round(ArcHeight - WaterLevel));
lineto(ArcWidth, round(ArcHeight - WaterLevel));  //draw a line at the water level

a := ArcWidth div 2;
b := ArcHeight div 2;
// calculate the x distance from the center of the Arc
xlevel := round((a/b) * sqrt(sqr(b) - sqr(ArcHeight - WaterLevel - b)));

pen.color := clred; // draw a red line at the water level
moveto(ArcCentreX - (xLevel), round(ArcHeight - WaterLevel));
LineTo(ArcCentreX + (xLevel), round(ArcHeight - WaterLevel));
// the ends of the red line are your intersection points !
end;
end;
0

Commented:
hi ivo

meikl
0

Commented:
Have you thought about using a Polygon?
0

Commented:
If your arc is say black on a white background, and you want to fill it red, then draw the bounding line in red, and use floodfill with a FloodStyle of fsSurface       (of course X and Y are the co-ords of a white pixel in the area you want to color.

if the internal area of the arc you want to color is multicoloured and you can't use fSurface, why can't you draw the arc and bounding line in the same colour, use floodfill with fsBorder, and then redraw the bounding line with the same color as the fill?

Mark
0

Author Commented:
Let me explain my problem a little: I have to simulate a tank filled with water and display the level of the water. Tank looks like a rectangle but but instead of straight lines at the top and the bottom there are little arcs. When water level reaches approx. the middle of tank height - I simply connect both vertical lines by new line and perform floodfill. But when water level is so low - it reaches the lower arc - then I am unable to find where the arc ends...
I can't use Chord method because I don't need to fill whole arc every time but only a portion of it.
0

Commented:
Ivo.
I can't use Chord method because I don't need to fill whole arc every time but only a  portion of it.

What is the it?
Can you help me visualize the shape?

From what you describe, I see the shape as a cylinder with both ends that are in a cone shaped or semicircular spheres or a curve  defined by some algebra statement.

And you are viewing the shape from a side position so that you see  the shape of the cylinder as a rectangle and the cones viewed as triangles or semicircles or symetric arcs?

And one final question: you need to demonstrate a filling of the tank by water  and demonstrate the position of the fill given any or all quantities, is that what this situation is and do it accurately as in a simulation of varible inputs?

Delphi3

0

Commented:
I guess from your description that the lower arc is not a semi-circle. When the water level is above the intersection of the lower arc and the vertical sides, you simply draw a horizontal line between the two verticals and then floodfill.

I understand the problem to be when the water level is below the intersection of the two sides and the the lower arc. In this case, your water level line intersects the arc only, and it is these two points you are having trouble finding. (chord only uses the endpoints of the arc)

If I'm right about the problem, then you could do it two ways.

1. Use maths to find the intersection of the arc (circle) and the line, then draw a line between these two points.

2. Brute force method. Determine the y co-ord of the top of the water level. Use a loop to go left and right (x), checking pixels for the color of the arc. Once you find the arc color, draw a line between these two points in the color of the water, then floodfill it.

Mark
0

Commented:
Ivo,
A crumb of  help with  the  math that you might need to get at this problem/solution  can be found at:

http://forum.swarthmore.edu/dr.math/faq/formulas/faq.sphere.html

Do any of those shapes look like something that can use to solve  the problem?

Delphi3
0

Author Commented:
To mullet_attack: can you post some code smaple to demonstrate implementation of step 1?
0

Author Commented:
mullet_attack: Good work. That's what I really looked for! I decided to give you the points. Is it enough 50 pts for you? I want only one thing before posting the points - please explain me how did you derived that formula for detemination of xlevel.

Many thanks, Ivo.
0

Author Commented:
Don't explain anything - it was really apparent - simple transformation of basic equation of ellipse and substituting y-coord by difference of b and waterlevel. Thanks. Only get know about the points. See you. Ivo
0

Commented:
Glad I could help ! 50 points is what was offered, and that's fine, thanks.
0

Author Commented:
Posting points to your account mullet_attack. Thanks.
0