Solved

How to fill an arc?

Posted on 2000-04-06
13
580 Views
Last Modified: 2010-04-04
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.

0
Comment
Question by:ivobauer
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2692380
hi ivo

use chord instead of arc

meikl
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 2692390
Have you thought about using a Polygon?
0
 
LVL 2

Expert Comment

by:mullet_attack
ID: 2692432
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
 
LVL 2

Author Comment

by:ivobauer
ID: 2692670
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
 
LVL 4

Expert Comment

by:delphi3
ID: 2695589
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
 
LVL 2

Expert Comment

by:mullet_attack
ID: 2695746
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 4

Expert Comment

by:delphi3
ID: 2697353
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
 
LVL 2

Author Comment

by:ivobauer
ID: 2699305
To mullet_attack: can you post some code smaple to demonstrate implementation of step 1?
0
 
LVL 2

Accepted Solution

by:
mullet_attack earned 50 total points
ID: 2700295
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
 
LVL 2

Author Comment

by:ivobauer
ID: 2703514
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
 
LVL 2

Author Comment

by:ivobauer
ID: 2703730
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
 
LVL 2

Expert Comment

by:mullet_attack
ID: 2706710
Glad I could help ! 50 points is what was offered, and that's fine, thanks.
0
 
LVL 2

Author Comment

by:ivobauer
ID: 2711449
Posting points to your account mullet_attack. Thanks.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now