Flash CS3 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript classes > Point (flash.geom.Point) > polar (Point.polar method) | |||
Converts a pair of polar coordinates to a Cartesian point coordinate.
Availability: ActionScript 1.0; Flash Player 8
len:Number - The length coordinate of the polar pair.
angle:Number - The angle, in radians, of the polar pair.
Point - The Cartesian point.
The following example creates a Point object cartesianPoint from the value of angleInRadians and a line length of 5. The angleInRadians value equal to Math.atan(3/4) is used because of the characteristics of right triangles with sides that have ratios of 3:4:5.
import flash.geom.Point; var len:Number = 5; var angleInRadians:Number = Math.atan(3/4); var cartesianPoint:Point = Point.polar(len, angleInRadians); trace(cartesianPoint.toString()); // (x=4, y=3)
When computers work with transcendental numbers such as pi, some round-off error occurs because floating-point arithmetic has only finite precision. When you use Math.PI, consider using the Math.round() function, as shown in the following example.
import flash.geom.Point; var len:Number = 10; var angleInRadians:Number = Math.PI; var cartesianPoint:Point = Point.polar(len, angleInRadians); trace(cartesianPoint.toString()); // should be (x=-10, y=0), but is (x=-10, y=1.22460635382238e-15) trace(Math.round(cartesianPoint.y)); // 0
length (Point.length property), round (Math.round method)
Flash CS3