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
, consider
Math.PI
using the
function, as shown in the following example.
Math.round()
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)
subtract (Point.subtract method)
public subtract(v:Point) : Point
Subtracts the coordinates of another point from the coordinates of this point to create a new
point.
Availability: ActionScript 1.0; Flash Player 8
Parameters
- The point to be subtracted.
v:flash.geom.Point
Returns
- The new point.
flash.geom.Point
Example
The following example creates
by subtracting
from
.
point_3
point_2
point_1
import flash.geom.Point;
var point_1:Point = new Point(4, 8);
var point_2:Point = new Point(1, 2);
var resultPoint:Point = point_1.subtract(point_2);
trace(resultPoint.toString()); // (x=3, y=6)
toString (Point.toString method)
public toString() : String
Returns a string that contains the values of the x and y coordinates. It has the form (x, y), so a
Point at 23,17 would report "(x=23, y=17)".
Availability: ActionScript 1.0; Flash Player 8
Point (flash.geom.Point)
1017
Need help?
Do you have a question about the FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE and is the answer not in the manual?