Delphi Triangle - Canvas

Asked

Viewed 390 times

3

I want to draw a triangle in Delphi through the Canvas.

This pointer will serve as a pointer to a Gauge (Speedometer) as in this example:

inserir a descrição da imagem aqui

I use the TPoint() to define where the pointer will point. I know the starting point, but my difficulty is in rotating the triangle to the correct angle.

2 answers

3

To rotate try to:

Here I will create a triangle in the form itself:

Form1.Canvas.Polygon([Point(20, 10), Point(10, 50), Point(80, 30)]);

Keep changing the Point and seeing the results, will need a good Mathematical Logic to achieve the result with greater perfections, note that you need to manipulate 6 variables to have full control!

  • I appreciate the initiative, but what I needed was mathematical logic. I already posted it in the topic answer. Thanks.

2


I found out!

Follow the mathematical logic:

  x01 := Round(x0 * (1 - Cos(Angle)));
  y01 := Round((R.Bottom - 1) * (1 - Sin(Angle)));
  x02 := Round( x0 + radiusS * Cos(2 * pi / 3 + Angle) );
  y02 := Round( y0 + radiusS * Sin(2 * pi / 3 + Angle) );
  x03 := Round( x0 + radiusS * Cos(4 * pi / 3 + Angle) );
  y03 := Round( y0 + radiusS * Sin(4 * pi / 3 + Angle) );
  Polygon([Point(x01,y01),Point(x02,y02),Point(x03,y03)]);

Caption:

  • x01 and y01: Are the points of the base of the triangle, that is, of the smallest line triangle;
  • x0 and R.Bottom: It is the starting point of the triangle, the starting point to the smallest line of the triangle.
  • X02, y02, x03 and y03: Are the points of the two longest lines of the triangle, which will form the final angle of the triangle;
  • Angle: Angle at which the triangle should be pointing;
  • Radiuss: Size of the larger lines, which will form the angle of the triangle;

PS: All variables must be of type Double.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.