View comments | RSS feed

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

flash.geom.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)


Version 8

Comments


jk515 said on Sep 13, 2005 at 10:26 AM :
Availability: ActionScript 1.0; Flash Player 8;

i belive this is a typeo- should be Actionscript 2.0?
this aspect is repeated throughout the live docs?!
swartz1999 said on Nov 7, 2005 at 3:36 PM :
The language version listed (in the "Availability" section) states the minimum language requirement, which is ActionScript 1.0 in this case.

 

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

Current page: http://livedocs.adobe.com/flash/8/main/00002603.html