Home > Blockchain >  Why the line doesn't draw? Delphi
Why the line doesn't draw? Delphi

Time:07-12

So, I drew polar coordinate system and wrote an algorithm to find where is the each line of degrees should be.

It looks like it:

1

But It shoud look like this:

2

But for some reason it doesnt draw a line at 30 degress, and I'm pretty sure it will not draw on others either. I think there is problem with my algorithm itself, probably it gives out wrong coordinates, but I can't figure out why it's wrong and how to fix it.

Here is the algorithm:

  var CheckPoint, gr30, gr60, gr90, gr120, gr150, gr180, gr210, gr240,  gr270, gr300, gr330, gr360 :TPoint;
  CheckPoint := Polar.Canvas.PenPos;
  
  for i := 1 to MaxY.Y do
  begin
  
  CheckPoint.Y := CheckPoint.Y   i; 
  case (CheckPoint.Y - CheckPoint.X) div (CheckPoint.X - P.Y) of
    180 div 6 : gr30 := CheckPoint;
    180 div 3 : gr60 := CheckPoint;
    180 div 2 : gr90 := CheckPoint;
    (180*2) div 3 : gr120 := CheckPoint; 
    (180*5) div 6 : gr150 := CheckPoint;
    180 : gr180 := CheckPoint;
    (180*7) div 6 : gr210 := CheckPoint;
    (180*4) div 3 : gr240 := CheckPoint;
    (180*3) div 2 : gr270 := CheckPoint;
    (180*5) div 3 : gr300 := CheckPoint;
    (180*11) div 6 : gr330 := CheckPoint;
  end;
  end;

  with Polar.Canvas do
  begin
    Brush.Style := bsSolid;
    Pen.Width := 3;
    MoveTo(P.X, P.Y);
    LineTo(gr30.X, gr30.Y);
  end;

MaxY.Y is

MaxY.Y := -ClientHeight;

and P is Zeroes of Axis

P := ClientRect.CenterPoint;

I will post a whole code if it requires; Help me please x_x

CodePudding user response:

To draw lines from center P with angles 30*i degrees, it is enough to make the next code:

for i := 0 to 11 do begin
   Polar.Canvas.MoveTo(P.X, P.Y);
   Polar.Canvas.LineTo(P.X   Round(R*Cos(i*2*Pi/12)), P.Y - Round(R*Sin(i*2*Pi/12)));
end;

BTW, logic of your code is too strange. Do you realize that CheckPoint.Y (starting from zero) will have values 1,2,3,6,10,15,21,28... (so-called triangle numbers)?

  • Related