Converting Delphi Angles between Degrees, Radians and X/Y
Scott Hollows - 14/Sep/2016
	
	
		
			
	
			
			Scott Hollows - 14/Sep/2016
[SHOWTOGROUPS=4,20]
If you need to convert angles in Delphi between degrees (0 – 360), radians and X/Y coordinates you have come to the right place. Ill show you how to do it in just one line of code, two if you count the USES entry
	
	
	
		
		
		
			
		
		
	
	
		
	
Download
Для просмотра ссылки Войдиили  Зарегистрируйся the full source code and demo project in Delphi 10.1 (Berlin) format.
These will most likely work in many earlier versions of Delphi
Some of the angle conversions are easy
To convert Radian to Degrees use Delphi’s built in RadToDeg function in the System.Math unit
To convert Degrees to Radian use Delphi’s built in DegToRad function in the System.Math unit
Some are more difficult. Use my routines for those
This is an overview of my conversion routines in the AngleConvertU.pas unit, plus the built in Delphi conversions routines
	
	
	
		
		
		
		
	
	
		
	
Boring Behind The Scenes Bits
The Radian to X / Y routines are based on SIN and COS functions.
	
	
	
		
The SIN and COS functions are radian based, not degree based. That might confuse you at first if you are used to 360 Degrees, but remember you can easily convert Radian to Degrees (see above for example)
Zero Angle At The Bottom – weoh thats craaazy !
Delphi’s co-ordinate system has the top left pixel at (0,0) and the Y axis increases in value as it stretches down to the bottom of the screen. That is the reverse of how we normally use angles where the Y axis decreases towards the bottom. As a result, my conversion routines use 0 degrees at the bottom like this. If that doesn’t float your goat, you have access to my source code so you can rewrite tje code or add a wrapper to my functions.
	
	
	
		
		
		
		
	
	
		
	
Done !
Its that simple. Just use my unit or the built in Delphi function.
Its just one line of code to call each angle conversion routines
	
	
	
		
Download
Для просмотра ссылки Войдиили  Зарегистрируйся the source code and demo project in Delphi 10.1 (Berlin) format.
It should open in earlier versions of Delphi, although with some complaints
[/SHOWTOGROUPS]
		If you need to convert angles in Delphi between degrees (0 – 360), radians and X/Y coordinates you have come to the right place. Ill show you how to do it in just one line of code, two if you count the USES entry
	Download
Для просмотра ссылки Войди
These will most likely work in many earlier versions of Delphi
Some of the angle conversions are easy
To convert Radian to Degrees use Delphi’s built in RadToDeg function in the System.Math unit
To convert Degrees to Radian use Delphi’s built in DegToRad function in the System.Math unit
Some are more difficult. Use my routines for those
This is an overview of my conversion routines in the AngleConvertU.pas unit, plus the built in Delphi conversions routines
	Boring Behind The Scenes Bits
The Radian to X / Y routines are based on SIN and COS functions.
		Код:
	
	x := sin (myRadian); 
y := cos (myRadian);
	The SIN and COS functions are radian based, not degree based. That might confuse you at first if you are used to 360 Degrees, but remember you can easily convert Radian to Degrees (see above for example)
Zero Angle At The Bottom – weoh thats craaazy !
Delphi’s co-ordinate system has the top left pixel at (0,0) and the Y axis increases in value as it stretches down to the bottom of the screen. That is the reverse of how we normally use angles where the Y axis decreases towards the bottom. As a result, my conversion routines use 0 degrees at the bottom like this. If that doesn’t float your goat, you have access to my source code so you can rewrite tje code or add a wrapper to my functions.
	Done !
Its that simple. Just use my unit or the built in Delphi function.
Its just one line of code to call each angle conversion routines
		Код:
	
	var
  vRadian : single;
begin
  vRadian := zzXYtoDegreeReal(X, Y);
end;
	Download
Для просмотра ссылки Войди
It should open in earlier versions of Delphi, although with some complaints
[/SHOWTOGROUPS]