polar (Point.polar method)

public static polar(len:Number, angle:Number) : Point

Converts a pair of polar coordinates to a Cartesian point coordinate.

Availability: ActionScript 1.0; Flash Player 8

Parameters

len:Number - The length coordinate of the polar pair.

angle:Number - The angle, in radians, of the polar pair.

Returns

Point - The Cartesian point.

Example

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

See also

length (Point.length property), round (Math.round method)


Flash CS3


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00002060.html