Recent

Author Topic: GraphMath unit / LineEndPoint  (Read 694 times)

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 350
GraphMath unit / LineEndPoint
« on: February 02, 2025, 02:53:25 pm »
Is this expected, or  ?

Quote
{------------------------------------------------------------------------------
  Method:   LineEndPoint
  Params:   StartPoint, Angle, Length
  Returns:  TPoint

  Use LineEndPoint to get the End-Point of a line of ANY given Length at
  any given angle with any given Start-Point.
It is primarily for use in
  other routines such as RadialPoint. The angle is in 1/16th of a degree.
  For example, a full circle equals 5760 (16*360).  Zero degrees is at the
  3'o clock position.

------------------------------------------------------------------------------}



1.Test LineEndPoint.
See image 1
From center, find end point at 0 degrees, and 100 distance. Find end points from there under +/-90 angle,distance 100,  connect, --> draw tangent.
2. let me see tangent  for all 360 degrees, step 10
see image 2

Code: Pascal  [Select][+][-]
  1. // some not needed declarations, delete them
  2.   var
  3.    arr: TFloatPointArray;
  4.    t,t1,t2: TfloatPoint;
  5.    str:string;
  6.    toCanvasCenterX,toCanvasCenterY: integer;
  7.    alpha: integer;
  8. begin
  9.  
  10.   //arr := getLineEndPointsMC(FloatPoint(0,0),degtorad(0),200);
  11.  
  12.   str := '';
  13.  
  14.  
  15.   toCanvasCenterX := round(PaintBox1.width/2);
  16.   toCanvasCenterY := round(PaintBox1.Height/2);
  17.  
  18.   PaintBox1.Canvas.Brush.Color := clWhite;
  19.   PaintBox1.Canvas.EllipseC(0+ toCanvasCenterX,toCanvasCenterY - 0,100,100);
  20.  
  21.   alpha := 0;
  22.   while  alpha < 360 do
  23.   begin
  24.  
  25.  
  26.   t := LineEndPoint(FloatPoint(0,0),alpha*16,100);
  27.  
  28.   PaintBox1.Canvas.Pen.Color := clBlack;
  29.   PaintBox1.Canvas.Line(round(FloatPoint(0,0).x+ toCanvasCenterX),round(toCanvasCenterY -FloatPoint(0,0).Y),round(t.x+ toCanvasCenterX),round(toCanvasCenterY -t.y));
  30.  
  31.   PaintBox1.Canvas.Pen.Color := clRed;
  32.   PaintBox1.Canvas.Ellipse(Rect(Round(t.X-2+ toCanvasCenterX),
  33.                                       Round(toCanvasCenterY - t.Y-2),
  34.                                       Round(t.X+2+ toCanvasCenterX),
  35.                                       Round(toCanvasCenterY - t.Y+2)));
  36.  
  37.   t1 := LineEndPoint(t,(alpha+90)*16,100);
  38.   PaintBox1.Canvas.Pen.Color := clBlue;
  39.   PaintBox1.Canvas.Ellipse(Rect(Round(t1.X-2+ toCanvasCenterX),
  40.                                       Round(toCanvasCenterY - t1.Y-2),
  41.                                       Round(t1.X+2+ toCanvasCenterX),
  42.                                       Round(toCanvasCenterY - t1.Y+2)));
  43.  
  44.   t2 := LineEndPoint(t,(alpha-90)*16,100);
  45.   PaintBox1.Canvas.Pen.Color := clBlue;
  46.   PaintBox1.Canvas.Ellipse(Rect(Round(t2.X-2+ toCanvasCenterX),
  47.                                       Round(toCanvasCenterY - t2.Y-2),
  48.                                       Round(t2.X+2+ toCanvasCenterX),
  49.                                       Round(toCanvasCenterY - t2.Y+2)));
  50.  
  51.   PaintBox1.Canvas.Line(round(t1.x+ toCanvasCenterX),round(toCanvasCenterY -t1.Y),round(t2.x+    toCanvasCenterX),round(toCanvasCenterY -t2.y));
  52.  
  53.   alpha := alpha +10;
  54.  
  55.   end;
  56. end;
  57.  

« Last Edit: February 02, 2025, 02:57:04 pm by BubikolRamios »
lazarus 3.2-fpc-3.2.2-win32/win64

tetrastes

  • Hero Member
  • *****
  • Posts: 637
Re: GraphMath unit / LineEndPoint
« Reply #1 on: February 02, 2025, 08:29:13 pm »
Code: Pascal  [Select][+][-]
  1.   //t1 := LineEndPoint(t,(alpha+90)*16,100);
  2.   a2 := alpha + 90;
  3.   if a2 > 359 then a2 := a2 - 360;
  4.   t1 := LineEndPoint(t,a2*16,100);
  5.  

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 350
Re: GraphMath unit / LineEndPoint
« Reply #2 on: February 02, 2025, 08:39:07 pm »
Code: Pascal  [Select][+][-]
  1.  if a2 > 359 then a2 := a2 - 360;
probably this should be handled inside LineEndPoint, right ?

extracted, and all I did removed '16', and now returns FloatPoint insead of Point

Code: Pascal  [Select][+][-]
  1. var
  2.   sinAngle, cosAngle: Extended;
  3. begin
  4.   if angleDegrees > 360 then
  5.     angleDegrees := Frac(angleDegrees / 360) * 360;
  6.  
  7.   if angleDegrees < 0 then
  8.     angleDegrees := 360 - abs(angleDegrees);
  9.  
  10.   SinCos(DegToRad(angleDegrees), sinAngle, cosAngle);
  11.   Result.Y := StartPoint.Y - Round(Length*sinAngle);
  12.   Result.X := StartPoint.X + Round(Length*cosAngle);
  13. end;    
  14.  

and all works OK, one can do

Code: Pascal  [Select][+][-]
  1. while  alpha < num greater than 360 do

and it works.
« Last Edit: February 02, 2025, 08:42:43 pm by BubikolRamios »
lazarus 3.2-fpc-3.2.2-win32/win64

tetrastes

  • Hero Member
  • *****
  • Posts: 637
Re: GraphMath unit / LineEndPoint
« Reply #3 on: February 02, 2025, 08:57:16 pm »
Yes, you are right. There is error in graphmath.pp:
Code: Pascal  [Select][+][-]
  1.   if Angle > 360*16 then
  2.     Angle := Frac(Angle / 360*16) * 360*16;
  3.  

must be
Code: Pascal  [Select][+][-]
  1.   if Angle > 360*16 then
  2.     Angle := Frac(Angle / (360*16)) * 360*16;
  3.  

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 350
Re: GraphMath unit / LineEndPoint
« Reply #4 on: February 02, 2025, 09:02:31 pm »
Have no clue where to file bug report ... I hope you will do it.
lazarus 3.2-fpc-3.2.2-win32/win64

tetrastes

  • Hero Member
  • *****
  • Posts: 637

wp

  • Hero Member
  • *****
  • Posts: 12702
Re: GraphMath unit / LineEndPoint
« Reply #6 on: February 03, 2025, 12:31:10 pm »
Bug fixed along with the same one in PolyBezierArcPoints. Fix back-ported to Fixes_4 and Fixed_3 (i.e. fix will be in Laz 4.0 and 3.10 (if that will ever be released)).

 

TinyPortal © 2005-2018