Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rotate TPathData (vector path)?

I have TPathData arrow and draw directly on Canvas. How to rotate TPathData? I know about rotating Tpath but I draw directly on Canvas (lines and arrows). I tried to rotate Tpath and the get Data string - but it is the same as before.

like image 903
alitrun Avatar asked Jan 25 '23 12:01

alitrun


2 Answers

Instead of rotating the TPathData, why not set the TCanvas matrix before drawing the path? This is probably more efficient because the GPU takes care of the rotation, and also more numerically stable since you won't lose any precision in your path data points if you're rotating many times.

msave := Image1.Bitmap.Canvas.Matrix;
Image1.Bitmap.Canvas.SetMatrix(TMatrix.CreateRotation(DegToRad(90)));
Image1.Bitmap.Canvas.DrawPath(PathData, 1);
Image1.Bitmap.Canvas.SetMatrix(msave); // Restore canvas matrix
like image 24
XylemFlow Avatar answered Jan 29 '23 14:01

XylemFlow


You have to create a rotation matrix and then apply it.

M := TMatrix.CreateRotation(DegToRad(90));  
PathData.ApplyMatrix(M);
like image 185
fpiette Avatar answered Jan 29 '23 14:01

fpiette