[SOLVED] Draw line lazarus / 39-Graphics ---------------------------------------------------------------------- pcurtis · 2021-04-27 10:53 How can I draw a line from the center of a circle to the edge of the circle at a predefined angle? ---------------------------------------------------------------------- alpine · 2021-04-27 11:49 What is the problem? How to draw a line or what are the start, end coords of the line? What do you know about the circle? ---------------------------------------------------------------------- pcurtis · 2021-04-27 11:54 The start point is the center of any circle of any radius. ---------------------------------------------------------------------- winni · 2021-04-27 11:55 Schools out forever .... Anyway: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses .....;math; const deg2rad = pi/180;var Center, P : TPoint;angle,sinus,cosinus, radius : single;....angle := 123;radius := 100;Center := Point(150,150);sincos(angle*deg2rad,sinus,cosinus);P := Point(round(radius*cosinus)+Center.x, round(radius*sinus)+Center.y);canvas.Line(center,P);  Angle starts in Lazarus in East! Winni ---------------------------------------------------------------------- alpine · 2021-04-27 11:56 Quote from: pcurtis on April 27, 2021, 01:54:15 pmThe start point is the center of any circle of any radius. Correct! But that is an answer to different question. ---------------------------------------------------------------------- pcurtis · 2021-04-27 12:33 @winni - thanks ---------------------------------------------------------------------- alpine · 2021-04-27 13:22 @winni, you're the man. You can guess whats the OP's actual question is. BTW, the angle can be degs, rads, or x/y the circle can be center+radius, bounding box, line segment, It depends on the task ---------------------------------------------------------------------- flowCRANE · 2021-05-02 22:31 @y.ivanov: See this gif for how the sin and cos functions are used for such calculations — https://upload.wikimedia.org/wikipedia/commons/3/3b/Circle_cos_sin.gif All you need to do is have the coordinates of the starting point (this is the center of the circle), the length of the line and the angle at which to paint. The angle must be expressed in radians, so if you have it in degrees, use the DegToRad and RadToDeg functions — details can be found in the documentation. So, having a start point, the end point calculation looks like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i DestX := SourceX + Cos(Angle) * Radius;DestY := SourceY + Sin(Angle) * Radius; This gives you the coordinates of two points that you can use to draw the line, for example with Canvas.Line. ---------------------------------------------------------------------- alpine · 2021-05-02 23:30 @furious programming I appreciate a lot your concern and explanation, My wrong, I just overestimated the original question a little bit. FYI, I have strong math background and wanted to give simpler answer to OP.  It is not always necessary to use trigonometric functions to calculate simple tasks involving circles. But you probably know that For example, in an interactive program, instead of angle in degrees, you may have a slope given by Δx, Δy (mouse movement) which is almost an equivalent to angle in radians. Then you can use even the integer math. ---------------------------------------------------------------------- flowCRANE · 2021-05-03 23:26 I thought you were the OP, I pinged the wrong person. Apologize. Quote from: y.ivanov on May 03, 2021, 01:30:24 amFYI, I have strong math background and wanted to give simpler answer to OP. The simplest answer is just to use Sin and Cos, because it is actually simple and widely used. QuoteIt is not always necessary to use trigonometric functions to calculate simple tasks involving circles. Yes, if you are writing code for a processor that does not support floating point arithmetic. Otherwise, such weirdness does not make sense and instead of making it easier and faster to solve a simple task, it only complicates it. But you probably know that. ---------------------------------------------------------------------- alpine · 2021-05-03 23:49 Quote from: furious programming on May 04, 2021, 01:26:43 amI thought you were the OP, I pinged the wrong person. Apologize. Apologies accepted. Pity, the complication is one of the programming sins in which I'm involved