How do I perform trigonometric calculations?
ColdFusion provides functions for all of the common trigonometric calculations.
The pi() function returns the mathematical constant Pi, accurate up to 15 digits:
<cfset testVar = pi()>
<cfoutput>#testVar#</cfoutput>
3.14159265359
The sin() function takes an angle (in radians), and returns the sine of the angle (in radians):
<cfset testVar = sin(100)>
<cfoutput>#testVar#</cfoutput>
-0.50636564111
The cos() function takes an angle (in radians), and returns the cosine of the angle (in radians):
<cfset testVar = cos(100)>
<cfoutput>#testVar#</cfoutput>
0.862318872288
The tan() function takes an angle (in radians), and returns the tangent of the angle (in radians):
<cfset testVar = tan(100)>
<cfoutput>#testVar#</cfoutput
-0.587213915157
The asin() function takes a number between -1 and 1, and then returns the arcsine of that number.
<cfset testVar = asin(1)>
<cfoutput>#testVar#</cfoutput>
1.57079632679
The acos() function takes a number between -1 and 1, and then returns the arccosine of that number.
<cfset testVar = acos(1)>
<cfoutput>#testVar#</cfoutput>
0
The atn() function takes a number, and then returns the arctangent of that number.
<cfset testVar = atn(1)>
<cfoutput>#testVar#</cfoutput>
0.785398163397
To convert degrees to radians, multiply degrees by pi/180.
<cfset myDegreesVar = .5>
<cfoutput>Radians = #myDegreesVar * pi()/180#</cfoutput>
Radians = 0.00872664625997
To convert radians to degrees, multiply radians by 180/pi.
<cfset myRadiansVar = .5>
<cfoutput>Degrees = #myRadiansVar * 180/pi()#</cfoutput>
Degrees = 28.6478897565
This question was written by Jeremy Petersen
It was last updated on January 24, 2006.