Rotate a 2D Point

Previous  Top  Next

    
 

 

 

Code:

const

PIDiv180 = 0.017453292519943295769236907684886;

 

procedure Rotate(RotAng: Double; x, y: Double; var Nx, Ny: Double);

var

SinVal: Double;

CosVal: Double;

begin

RotAng := RotAng * PIDiv180;

SinVal := Sin(RotAng);

CosVal := Cos(RotAng);

Nx := x * CosVal - y * SinVal;

Ny := y * CosVal + x * SinVal;

end;

 

©Drkb::04110

Взято с сайта http://www.swissdelphicenter.ch/en/tipsindex.php

 


Rotate a 2D Point around another 2D Point

Code:

const

PIDiv180 = 0.017453292519943295769236907684886;

 

procedure Rotate(RotAng: Double; x, y, ox, oy: Double; var Nx, Ny: Double);

begin

Rotate(RotAng, x - ox, y - oy, Nx, Ny);

Nx := Nx + ox;

Ny := Ny + oy;

end;

 

 

 

procedure Rotate(RotAng: Double; x, y: Double; var Nx, Ny: Double);

var

SinVal: Double;

CosVal: Double;

begin

RotAng := RotAng * PIDiv180;

SinVal := Sin(RotAng);

CosVal := Cos(RotAng);

Nx := x * CosVal - y * SinVal;

Ny := y * CosVal + x * SinVal;

end;

 

 

©Drkb::04111

Взято с сайта http://www.swissdelphicenter.ch/en/tipsindex.php