Triangle Delphi - Canvas

3

I want to draw a triangle in Delphi with Canvas .

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

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

    
asked by anonymous 01.07.2016 / 16:26

2 answers

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)]);

Legend:

  • x01 and y01: These are the points of the base of the triangle, that is, the smallest line of the 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: These are the points of the two major triangle, which will form the final angle of it;
  • Angle: Angle in 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.

    
12.07.2016 / 21:20
3

To Rotate try:

Here I am going to create a triangle in the form itself:

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

You change the Point and seeing the results, you will need a good Mathematical Logic to achieve the result with more perfection, you need to manipulate 6 variables to have total control!

    
05.07.2016 / 15:07