Library for drawing a path lazarus / 39-Graphics ---------------------------------------------------------------------- gidesa · 2025-07-07 10:43 Hello, I have a path described as a sequence of (angle difference, distance) couples, generated by a wheel encoder. The angle difference is relative to previous orientation. The distance is the one travelled in direction obtained as: previous angle + angle difference. Is there some simple FPC (or Delphi) library to draw that path on a canvas, for example a TImage? ---------------------------------------------------------------------- H₂SO₄ · 2025-07-07 11:26 You could use  TCanvas.Polyline(const Points: array of TPoint); You'll have to convert your data to an array of points, though - and that could be problematic, because your data points consist of differences. If you want to find the angle of the  N th line, you'll have to add up the preceding  N - 1  angle differences; in other words, you need to numerically integrate them, and this process is extremely sensitive to errors (especially when using floating-point numbers). You can try, of course, but don't be surprised when the drawn path rapidly diverges from the actual path when more data points are added. ---------------------------------------------------------------------- 440bx · 2025-07-07 11:37 It sounds like, if it weren't for the fact that angles are stated in differences from the previous tuple, you'd have an array of polar coordinates. Following Khrys' idea, I would first convert that array into Cartesian coordinates (x,y) instead of (angle difference, distance).  Note that I'd first calculate the angle by keeping an accumulator to avoid too much error accumulation.  Once you've got Cartesian coordinates, as Khrys suggested a Polyline will draw your array very quickly. HTH. ---------------------------------------------------------------------- marcov · 2025-07-07 11:53 The royal way is to upload it to OpenGL and let a shader do the calculation in the geometry shader. ---------------------------------------------------------------------- gues1 · 2025-07-07 11:58 Skia ? ---------------------------------------------------------------------- gidesa · 2025-07-07 13:31 Thank to all. @Khrys I am aware that this type of calculation diverge quickly. Your suggestion of polyline is good. @440bx yes, they are in essence cumulative polar coordinates, using an accumulator is very valuable. Using very rich, and complex, libraries as OpenGL or Skia is a bit too much, in my opinion, for a simple 2D diagram/drawing. ---------------------------------------------------------------------- marcov · 2025-07-07 14:46 Quote from: gidesa on July 07, 2025, 03:31:50 pmUsing very rich, and complex, libraries as OpenGL or Skia is a bit too much, in my opinion, for a simple 2D diagram/drawing. Depends on border conditions. Opengl often scales better if your element count (number of paths/lines/circles whatever) is high, and if you need to zoom in and out. Zooming can be handled in opengl without reuploading data, making it very fast.    These are the reasons why I created a simple opengl 2D canvas to draw over images. ---------------------------------------------------------------------- wp · 2025-07-07 15:53 Quote from: gidesa on July 07, 2025, 12:43:03 pmI have a path described as a sequence of (angle difference, distance) couples, generated by a wheel encoder. The angle difference is relative to previous orientation. The distance is the one travelled in direction obtained as: previous angle + angle difference. Is there some simple FPC (or Delphi) library to draw that path on a canvas, for example a TImage? Reminds me of the good-old turtle graphics. Find a simple implementation in the attachment: Create the turtle with its starting position and looking angle and the canvas for drawing, and then make it move by a given distance in a given angle (as seen from the turtle). The sample project contains some restriction of the angle difference - just for fun. ---------------------------------------------------------------------- gidesa · 2025-07-07 17:42 Quote from: marcov on July 07, 2025, 04:46:32 pmDepends on border conditions. Opengl often scales better if your element count (number of paths/lines/circles whatever) is high, and if you need to zoom in and out. Zooming can be handled in opengl without reuploading data, making it very fast.    These are the reasons why I created a simple opengl 2D canvas to draw over images. Ah, ok. In my case I have onlu two hundred of data, and no need for zoom. ---------------------------------------------------------------------- gidesa · 2025-07-07 17:43 Quote from: wp on July 07, 2025, 05:53:06 pmReminds me of the good-old turtle graphics. Find a simple implementation in the attachment: Create the turtle with its starting position and looking angle and the canvas for drawing, and then make it move by a given distance in a given angle (as seen from the turtle). The sample project contains some restriction of the angle difference - just for fun. Yes, just the old good Logo language!  Thank you for the example.