Autor Beitrag
Wolle92
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: So 13.01.08 11:05 
Hallo,
ich hab ein kleines Problem...
Ich habe einen bestimmten Prozentsatz, diesen möchte ich in einem Kreis darstellen...
Nur funktioniert das nicht so ganz... Wenn ich 50 Prozent angebe, ist nur ca. 1/8 des Kreises rot, wobei es ja eigentlich die Hälfte sein müsste...
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
prozent := 50;
  Image1.Canvas.Brush.Color := clGreen;
  Image1.Canvas.Pen.Color := clGreen;
  Image1.Canvas.Ellipse(0,0,100,100);
  winkel := prozent / 100 * 360;
  x := Trunc(50 * cos(winkel) + 50);
  y := Trunc(50 * sin(winkel) + 50);
  Image1.Canvas.Brush.Color := clRed;
  Image1.Canvas.Pen.Color := clRed;
  Image1.Canvas.Pie(0,0,100,100,50,0,x,y);

_________________
1405006117752879898543142606244511569936384000000000.
cuejo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 142

Win XP
Delphi 7 Personal und 2005 PE
BeitragVerfasst: So 13.01.08 11:15 
Die trigonometrischen Funktionen arbeiten mit Radiant als Einheit. Daran wird es wahrscheinlich liegen.

_________________
Computer sind dumm, aber fleißig. Deshalb arbeite ich so gerne damit.
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: So 13.01.08 11:48 
und das heißt jetzt das ich was ändern muss?

_________________
1405006117752879898543142606244511569936384000000000.
cuejo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 142

Win XP
Delphi 7 Personal und 2005 PE
BeitragVerfasst: So 13.01.08 11:53 
Den Winkel. Der Vollkreis bei Grad ist 360. Also wovon Du ausgegangen bist. Du musst aber 2*pi als Vollkreis nehmen. Lies Dir mal den Wikipedia-Artikel durch, da steht auch wie man das umrechnet.

_________________
Computer sind dumm, aber fleißig. Deshalb arbeite ich so gerne damit.
nagel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 708

Win7, Ubuntu 10.10

BeitragVerfasst: So 13.01.08 13:32 
Also entweder du benutzt zur Umrechnung die Funktion DegToRad (unit math), oder du machst es folgendermaßen:

winkel/180*pi
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: So 13.01.08 13:43 
Also muss ich nicht winkel := prozent / 100 * 360;, sondern [delphi]winkel := DegTpRad(prozent / 100 * 360);[/dephi] schreiben? Das geht auch nicht, kommt auch was anderes bei raus...

_________________
1405006117752879898543142606244511569936384000000000.
nagel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 708

Win7, Ubuntu 10.10

BeitragVerfasst: So 13.01.08 14:42 
Also, ich hab mir jetzt deinen Code nochmal angeschaut, und meiner Meinung nach müssten die beiden Koordinaten x und y folgenermaßen aussehen:

ausblenden Delphi-Quelltext
1:
2:
x :=  50 * sin(winkel) + 50;
y := -50 * cos(winkel) + 50;


Ist ungetestet, probiers mal aus (Winkelumrechnung natürlich trotzdem nicht vergessen).
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: So 13.01.08 18:18 
Mittlerweile sieht mein Code so aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.Button1Click(Sender: TObject);
var winkel, prozent: Real;
    x, y: Integer;
begin
  prozent := 25;
  Image1.Canvas.Brush.Color := clGreen;
  Image1.Canvas.Pen.Color := clGreen;
  Image1.Canvas.Ellipse(0,0,100,100);
  winkel := Math.DegToRad(prozent / 100 * 360);
  x := Trunc(50 * cos(winkel) + 50);
  y := Trunc(-50 * sin(winkel) + 50);
  Image1.Canvas.Brush.Color := clRed;
  Image1.Canvas.Pen.Color := clRed;
  Image1.Canvas.Pie(0,0,100,100,50,0,x,y);
end;

Bringt aber immer noch nicht das gewünschte Ergebnis...

_________________
1405006117752879898543142606244511569936384000000000.
nagel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 708

Win7, Ubuntu 10.10

BeitragVerfasst: So 13.01.08 18:25 
Probier's mal so wie ich oben geschrieben habe (sin und cos vertauschen).
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: So 13.01.08 18:55 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
var
  winkel, prozent: Real;
  x, y: Integer;
begin
  prozent := 25;
  Image1.Canvas.Brush.Color := clGreen;
  Image1.Canvas.Pen.Color := clGreen;
  Image1.Canvas.Ellipse(0, 0, 100, 100);
  winkel := DegToRad((prozent - 25) / 100 * 360);
  x := Trunc(50 * Cos(winkel) + 50);
  y := Trunc(50 * Sin(winkel) + 50);
  Image1.Canvas.Brush.Color := clRed;
  Image1.Canvas.Pen.Color := clRed;
  Image1.Canvas.Pie(0, 0, 100, 100, 50, 0, x, y);
end;

So gehts.
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: So 13.01.08 19:08 
Warum immer DegToRad? Kostet doch nur unnötig Zeit.

ausblenden Delphi-Quelltext
1:
winkel := (prozent - 25) / 100 * 2 * pi;					

bzw.
ausblenden Delphi-Quelltext
1:
winkel := (prozent - 25) / 50 * pi;					


ist meiner Meinung nach auch einfacher zu lesen...

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: So 13.01.08 19:15 
user profile iconChryzler hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
var
  winkel, prozent: Real;
  x, y: Integer;
begin
  prozent := 25;
  Image1.Canvas.Brush.Color := clGreen;
  Image1.Canvas.Pen.Color := clGreen;
  Image1.Canvas.Ellipse(0, 0, 100, 100);
  winkel := DegToRad((prozent - 25) / 100 * 360);
  x := Trunc(50 * Cos(winkel) + 50);
  y := Trunc(50 * Sin(winkel) + 50);
  Image1.Canvas.Brush.Color := clRed;
  Image1.Canvas.Pen.Color := clRed;
  Image1.Canvas.Pie(0, 0, 100, 100, 50, 0, x, y);
end;

So gehts.


So geht das auch nicht... das dadurch angezeigt diagramm ziegt 75 Prozent... und außerdem muss ja bei jeder Zahl funktionieren (von 0 bis 100)

_________________
1405006117752879898543142606244511569936384000000000.
nagel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 708

Win7, Ubuntu 10.10

BeitragVerfasst: So 13.01.08 19:36 
So, ich schreibs dir jetzt noch ein drittes Mal, vielleicht glaubst du's ja mal:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
begin
  prozent := 25;
  Image1.Canvas.Brush.Color := clGreen;
  Image1.Canvas.Pen.Color := clGreen;
  Image1.Canvas.Ellipse(0, 0, 100, 100);
  winkel := prozent / 50 * pi;
  x := Trunc(50 * sin(winkel) + 50);
  y := Trunc(-50 * cos(winkel) + 50);
  Image1.Canvas.Brush.Color := clRed;
  Image1.Canvas.Pen.Color := clRed;
  Image1.Canvas.Pie(0, 0, 100, 100, x, y, 50, 0);
end;


user profile iconMartoks Vereinfachung hab ich auch eingebaut, außerdem beim Pie die 3. und 4. Koordinaten vertauscht.
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: So 13.01.08 19:56 
user profile iconWolle92 hat folgendes geschrieben:
So geht das auch nicht... das dadurch angezeigt diagramm ziegt 75 Prozent... und außerdem muss ja bei jeder Zahl funktionieren (von 0 bis 100)

Also bei mir gings, ich habs getestet. Du musst immer 25 Prozent abziehen, da der Nullpunkt bei Polarkoordinaten ja nicht oben in der Mitte liegt, sondern rechts in der Mitte.