Class: Geom::Vector2d
Relationships | |
Inherits: | Object |
Overview
The Vector2d
class represents vectors in a 2 dimensional space.
There are numerous tutorials on 2D vectors available on the internet.
Class Method Summary
-
.new ⇒ Geom::Vector2d
constructor
The .new method creates a new
Vector2d
.
Instance Attribute Summary
-
#length ⇒ Length
rw
The #length method returns the length of the
Vector2d
. -
#length=(length) ⇒ Numeric
rw
The #length= method sets the length of the
Vector2d
. -
#unit_vector? ⇒ Boolean
readonly
The #unit_vector? method returns whether the
Vector2d
is a unit vector. -
#valid? ⇒ Boolean
readonly
The #valid? method verifies if a
Vector2d
is valid. -
#x ⇒ Numeric
rw
The #x method retrieves the x value of the
Vector2d
. -
#x=(x) ⇒ Numeric
rw
The #x= method sets the x coordinate of the
Vector2d
. -
#y ⇒ Numeric
rw
The #y method retrieves the y value of the
Vector2d
. -
#y=(y) ⇒ Numeric
rw
The #y= method sets the y coordinate of the
Vector2d
.
Instance Method Summary
-
#%(vector) ⇒ Object
The #% method returns the dot product between two
Vector2d
. -
#*(vector) ⇒ Geom::Vector2d
The #* method returns the cross product between two
Vector2d
. -
#+(vector) ⇒ Geom::Vector2d
The #+ method adds a
Vector2d
to this one. -
#-(vector) ⇒ Geom::Vector2d
The #- method subtracts a
Vector2d
from this one. -
#==(vector) ⇒ Boolean
The #== method returns whether two
Vector2d
are equal within tolerance. -
#[](index) ⇒ Numeric
The #[] method returns the value of the
Vector2d
at the specified index. -
#[]=(index, value) ⇒ Numeric
The #[]= method sets the x or y value of the
Vector2d
based on the specific index of the value. -
#angle_between(vector) ⇒ Numeric
The #angle_between method computes the angle in radians between the
Vector2d
and anotherVector2d
. -
#clone ⇒ Geom::Vector2d
The #clone method makes a copy of the
Vector2d
. -
#cross(vector) ⇒ Geom::Vector2d
The #* method returns the cross product between two
Vector2d
. -
#dot(vector) ⇒ Object
The #% method returns the dot product between two
Vector2d
. -
#inspect ⇒ String
The #inspect method formats the
Vector2d
as a string. -
#normalize ⇒ Geom::Vector2d
The #normalize method returns a
Vector2d
that is a unit vector of theVector2d
. -
#normalize!
The #normalize! method converts a
Vector2d
vector into a unit vector. -
#parallel?(vector) ⇒ Boolean
The #parallel? method determines if the
Vector2d
is parallel to anotherVector2d
to within tolerance. -
#perpendicular?(vector) ⇒ Boolean
The #perpendicular? method determines if the
Vector2d
is perpendicular to anotherVector2d
to within tolerance. -
#reverse ⇒ Geom::Vector2d
The #reverse method returns a new
Vector2d
that is the reverse of theVector2d
, leaving the original unchanged. -
#reverse!
The #reverse! method reverses the
Vector2d
in place. -
#same_direction?(vector) ⇒ Boolean
The #same_direction? method determines if the
Vector2d
is parallel to and in the same direction as anotherVector2d
within tolerance. -
#set!(vector) ⇒ Geom::Vector2d
The #set! method sets the values of the
Vector2d
. - #to_a ⇒ Array(Numeric, Numeric)
-
#to_s ⇒ String
The #to_s method returns a string representation of the
Vector2d
. -
#transform(transform) ⇒ Geom::Vector2d
The #transform method applies a transformation to a vector, returning a new vector.
-
#transform!(transform) ⇒ Geom::Vector2d
The #transform! method applies a transformation to a vector.
Constructor Details
.new ⇒ Vector2d
.new(x, y) ⇒ Vector2d
.new(vector) ⇒ Vector2d
Vector2d
.new(x, y) ⇒ Vector2d
.new(vector) ⇒ Vector2d
The .new
method creates a new Vector2d
.
Instance Attribute Details
#length ⇒ Length (rw)
The #length
method returns the length of the Vector2d
.
#length=(length) ⇒ Numeric (rw)
The #length=
method sets the length of the Vector2d
. The new length must not be 0.
#unit_vector? ⇒ Boolean
(readonly)
The #unit_vector?
method returns whether the Vector2d
is a unit vector. This is equivalent to vector.length == 1.0
#valid? ⇒ Boolean
(readonly)
The #valid?
method verifies if a Vector2d
is valid. A Vector2d
is valid if its length is not zero.
#x ⇒ Numeric (rw)
The #x
method retrieves the x value of the Vector2d
.
#x=(x) ⇒ Numeric (rw)
The #x=
method sets the x coordinate of the Vector2d
.
#y ⇒ Numeric (rw)
The #y
method retrieves the y value of the Vector2d
.
#y=(y) ⇒ Numeric (rw)
The #y=
method sets the y coordinate of the Vector2d
.
Instance Method Details
#%(vector) ⇒ Object
The #%
method returns the dot product between two Vector2d
. This is an alias of the dot method.
#*(vector) ⇒ Vector2d
The #*
method returns the cross product between two Vector2d
. This is an alias of the cross method.
#+(vector) ⇒ Vector2d
The #+
method adds a Vector2d
to this one.
#-(vector) ⇒ Vector2d
The #-
method subtracts a Vector2d
from this one.
#==(vector) ⇒ Boolean
The #==
method returns whether two Vector2d
are equal within tolerance.
#[](index) ⇒ Numeric
The #[]
method returns the value of the Vector2d
at the specified index.
#[]=(index, value) ⇒ Numeric
The #[]=
method sets the x or y value of the Vector2d
based on the specific index of the value.
#angle_between(vector) ⇒ Numeric
The #angle_between
method computes the angle in radians between the Vector2d
and another Vector2d
.
#clone ⇒ Vector2d
The #clone
method makes a copy of the Vector2d
. This method is equivalent to vec2 = Vector2d
.new(vec).
#cross(vector) ⇒ Vector2d
The #* method returns the cross product between two Vector2d
. This is an alias of the cross method.
#dot(vector) ⇒ Object
The #% method returns the dot product between two Vector2d
. This is an alias of the dot method.
#inspect ⇒ String
The #inspect
method formats the Vector2d
as a string.
#normalize ⇒ Vector2d
The #normalize
method returns a Vector2d
that is a unit vector of the Vector2d
.
#normalize!
The #normalize!
method converts a Vector2d
vector into a unit vector. Another way to do this is vector.length = 1
#parallel?(vector) ⇒ Boolean
The #parallel?
method determines if the Vector2d
is parallel to another Vector2d
to within tolerance.
#perpendicular?(vector) ⇒ Boolean
The #perpendicular?
method determines if the Vector2d
is perpendicular to another Vector2d
to within tolerance.
#reverse ⇒ Vector2d
The #reverse
method returns a new Vector2d
that is the reverse of the Vector2d
, leaving the original unchanged.
#reverse!
The #reverse!
method reverses the Vector2d
in place.
#same_direction?(vector) ⇒ Boolean
The #same_direction?
method determines if the Vector2d
is parallel to and in the same direction as another Vector2d
within tolerance.
#set!(vector) ⇒ Vector2d
#set!(x, y) ⇒ Vector2d
Vector2d
#set!(x, y) ⇒ Vector2d
The #set!
method sets the values of the Vector2d
.
#to_a ⇒ Array(Numeric, Numeric)
The #to_a
method retrieves the coordinates of the Vector2d
in an ::Array
.
#to_s ⇒ String
The #to_s
method returns a string representation of the Vector2d
.
#transform(transform) ⇒ Vector2d
The #transform
method applies a transformation to a vector, returning a new vector. The original vector is unchanged by this method.
#transform!(transform) ⇒ Vector2d
The #transform!
method applies a transformation to a vector. The vector itself is modified.