清家当产求图形(坐标)旋转算法! ( 积分: 174 )

  • 主题发起人 主题发起人 由由(love)
  • 开始时间 开始时间

由由(love)

Unregistered / Unconfirmed
GUEST, unregistred user!
在TImages的画布上画图形,有矩形、直线、多边形、圆,圆角矩形,点,求各种图形以图形中心点旋转任一角度的算法。
其中矩形、点、直线相对比较简单一些,可以通过旋转坐标来完成,给出具体计算公式即可;但圆和圆角矩形如何实现呢,最好可以有写好的函数可用,多谢了!!!
 
在TImages的画布上画图形,有矩形、直线、多边形、圆,圆角矩形,点,求各种图形以图形中心点旋转任一角度的算法。
其中矩形、点、直线相对比较简单一些,可以通过旋转坐标来完成,给出具体计算公式即可;但圆和圆角矩形如何实现呢,最好可以有写好的函数可用,多谢了!!!
 
简单的方法 使用1stclass控件 它的image组件把图片旋转任意角度
 
图形中心点
和圆角矩形如何实现呢

圆就不用转了吧?
 
function RotateBitmap(Bitmap: TBitmap; Angle: Double; Color: TColor): TBitmap;
const
MaxPixelCount = 32768;
type
PRGBTripleArray = ^TRGBTripleArray;
TRGBTripleArray = array[0..MaxPixelCount] of TRGBTriple;
var
CosTheta: Extended;
SinTheta: Extended;
xSrc, ySrc: Integer;
xDst, yDst: Integer;
xODst, yODst: Integer;
xOSrc, yOSrc: Integer;
xPrime, yPrime: Integer;
srcRow, dstRow: PRGBTripleArray;
begin

Result := TBitmap.Create;
// result := mf(bitmap);
SinCos(Angle * Pi / 180, SinTheta, CosTheta);
if (SinTheta * CosTheta) < 0 then
begin
Result.Width := Round(Abs(Bitmap.Width * CosTheta - Bitmap.Height * SinTheta));
Result.Height := Round(Abs(Bitmap.Width * SinTheta - Bitmap.Height * CosTheta));
end
else
begin
Result.Width := Round(Abs(Bitmap.Width * CosTheta + Bitmap.Height * SinTheta));
Result.Height := Round(Abs(Bitmap.Width * SinTheta + Bitmap.Height * CosTheta));
end;
with Result.Canvas do
begin
Brush.Color := Color;
Brush.Style := bsSolid;
FillRect(ClipRect);
end;
Result.PixelFormat := pf24bit;
Bitmap.PixelFormat := pf24bit;
xODst := Result.Width div 2;
yODst := Result.Height div 2;
xOSrc := Bitmap.Width div 2;
yOSrc := Bitmap.Height div 2;
for ySrc := Max(Bitmap.Height, Result.Height) - 1 downto 0 do
begin
yPrime := ySrc - yODst;
for xSrc := Max(Bitmap.Width, Result.Width) - 1 downto 0 do
begin
xPrime := xSrc - xODst;
xDst := Round(xPrime * CosTheta - yPrime * SinTheta) + xOSrc;
yDst := Round(xPrime * SinTheta + yPrime * CosTheta) + yOSrc;
if (yDst >= 0) and (yDst < Bitmap.Height) and
(xDst >= 0) and (xDst < Bitmap.Width) and
(ySrc >= 0) and (ySrc < Result.Height) and (xSrc >= 0) and (xSrc < Result.Width) then
begin srcRow := Bitmap.ScanLine[yDst]; dstRow := Result.Scanline[ySrc];
dstRow[xSrc] := srcRow[xDst];
end;
end;
end;
end;
 
我可能没有说清楚,我不是需要整个位图的旋转,这样如果图形中有文字,那样会不好看的,你们只要告诉我在坐标系中的某个点以坐标元点为中心旋转任意角度后新点坐标的计算公式后,其它的就比较容易了,只是一个计算公式就行了!
 
把一个点绕原点旋转α角度后,新的坐标位置与原坐标位置的
关系是:
X=x?cosα-y?sinα
Y=x?sinα+y?cosα
 
ModifyWorldTransform and SetWorldTransform 2个api
 
delphibbs_Lee的公式正确吗?
 
绝对没问题。
 
我试过,我用90度试了一下,你的公式计算出的结果感觉像130度的结果!
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部