Eiffel Media API
Overview Cluster Class Classes Index      Previous Next      Top Features

em.utility

Class EM_DIRECTION_2D


Direct ancestors

DOUBLE_MATH

Creation

Features

Invariants

indexing

description

Normalized 2D vector, used for directions. uses the coefficients to save the direction
Please note, that on the screen, y is negative, and therefore the angles
start from the right (0 radian), go down (pi/2 radian), left (pi radian)
and finally top (3*pi/2 radian)

date

$Date: 2005/10/23 10:36:32 $

revision

$Revision: 1.7 $

class

EM_DIRECTION_2D

inherit

DOUBLE_MATH
MATH_CONST

create

make

-- creation procedure

make_from_coefficients (x_coeff, y_coeff: DOUBLE)

-- creates a direction from both given coefficients

make_from_direction (dir: EM_DIRECTION_2D)

-- takes a direction and creates the same direction

ensure
direction_set: x = dir.x and y = dir.y
make_from_angle (an_angle: DOUBLE)

-- takes an angle and creates a direction from the given angle

feature -- Access

angle: DOUBLE

-- returns the angle (in radian), computed by x and y coefficients of the direction
-- WARNING: do not use, if not absolutely necessary, because of computation.
-- the variables x and y have direct access, and must not be computed again from the angle

arc_cosine (v: DOUBLE): DOUBLE

-- Trigonometric arccosine of radian v
-- in the range [0, pi]

-- (From DOUBLE_MATH)

arc_sine (v: DOUBLE): DOUBLE

-- Trigonometric arcsine of radian v
-- in the range [-pi/2, +pi/2]

-- (From DOUBLE_MATH)

arc_tangent (v: DOUBLE): DOUBLE

-- Trigonometric arctangent of radian v
-- in the range [-pi/2, +pi/2]

-- (From DOUBLE_MATH)

ceiling (v: DOUBLE): DOUBLE

-- Least integral greater than or equal to v

-- (From DOUBLE_MATH)

cosine (v: DOUBLE): DOUBLE

-- Trigonometric cosine of radian v approximated
-- in the range [-pi/4, +pi/4]

-- (From DOUBLE_MATH)

dabs (v: DOUBLE): DOUBLE

-- Absolute of v

-- (From DOUBLE_MATH)

exp (x: DOUBLE): DOUBLE

-- Exponential of v.

-- (From DOUBLE_MATH)

floor (v: DOUBLE): DOUBLE

-- Greatest integral less than or equal to v

-- (From DOUBLE_MATH)

log (v: DOUBLE): DOUBLE

-- Natural logarithm of v

-- (From DOUBLE_MATH)

log10 (v: DOUBLE): DOUBLE

-- Base 10 logarithm of v

-- (From DOUBLE_MATH)

log_2 (v: DOUBLE): DOUBLE

-- Base 2 logarithm of v

-- (From DOUBLE_MATH)

sine (v: DOUBLE): DOUBLE

-- Trigonometric sine of radian v approximated
-- in range [-pi/4, +pi/4]

-- (From DOUBLE_MATH)

sqrt (v: DOUBLE): DOUBLE

-- Square root of v

-- (From DOUBLE_MATH)

tangent (v: DOUBLE): DOUBLE

-- Trigonometric tangent of radian v approximated
-- in range [-pi/4, +pi/4]

-- (From DOUBLE_MATH)

x: DOUBLE

-- Vertical coefficient

y: DOUBLE

-- Horizontal coefficient

feature -- Element change

add (other: EM_DIRECTION_2D)

-- adds a direction to current

require
direction_void: other /= void
set_angle (angle_in_radian: DOUBLE)

-- sets the angle to a certain value (the attribute is given in radian)

ensure
x_set: x = cosine (angle_in_radian)
y_set: y = sine (angle_in_radian)
set_direction (x_coeff: DOUBLE; y_coeff: DOUBLE)

-- sets the direction with x and y coefficients (this normalizes the coefficients automatically)

feature -- Creation

make

-- creation procedure

make_from_angle (an_angle: DOUBLE)

-- takes an angle and creates a direction from the given angle

make_from_coefficients (x_coeff, y_coeff: DOUBLE)

-- creates a direction from both given coefficients

make_from_direction (dir: EM_DIRECTION_2D)

-- takes a direction and creates the same direction

ensure
direction_set: x = dir.x and y = dir.y

feature -- Computation

infix "+" (other: EM_DIRECTION_2D): EM_DIRECTION_2D

-- Sum with other (commutative).

to_vector: EM_VECTOR_2D

-- returns the equivalend EM_VECTOR_2D

feature -- Output

out: STRING

-- Textual representation

-- (From ANY)

feature -- Constants

eps: DOUBLE

invariant

is_normalized: (x*x + y*y) > 1 - eps and x*x+y*y < 1 + eps
angle_in_range: angle >= 0 and angle <= 2*pi

-- From ANY
reflexive_equality: standard_is_equal (Current)
reflexive_conformance: conforms_to (Current)

end