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:
The sin() function takes an angle (in radians), and returns the sine of the angle (in radians):
The cos() function takes an angle (in radians), and returns the cosine of the angle (in radians):
The tan() function takes an angle (in radians), and returns the tangent of the angle (in radians):
The asin() function takes a number between -1 and 1, and then returns the arcsine of that number.
The acos() function takes a number between -1 and 1, and then returns the arccosine of that number.
The atn() function takes a number, and then returns the arctangent of that number.
To convert degrees to radians, multiply degrees by pi/180.
<cfoutput>Radians = #myDegreesVar * pi()/180#</cfoutput>
Radians = 0.00872664625997
To convert radians to degrees, multiply radians by 180/pi.
<cfoutput>Degrees = #myRadiansVar * 180/pi()#</cfoutput>
Degrees = 28.6478897565
This question was written by Jeremy Petersen.
It was last updated on January 24, 2006 at 4:44:12 PM EST.
CFML Referenced
Cos()
Sin()
ASin()
<cfoutput>
Tan()
ACos()
Atn()
Pi()
Categories
Comments
Comment made by Rick Osborne on January 24, 2006 at 4:01 PM
You may also want to show how you can convert from Degrees to Radians and back.
Comment made by Jeremy Petersen on January 24, 2006 at 4:44 PM
Done.
Comment made by Rob Brooks-Bilson on January 24, 2006 at 5:35 PM
Don't forget that there are almost two dozen additional trig functions that are not native to ColdFusion over at cflib.org:
http://www.cflib.org/library.cfm?ID=6