Class: Geom::Vector2d
- Inherits:
- 
      Object
      
        - Object
- Geom::Vector2d
 
Overview
The Vector2d class represents vectors in a 2 dimensional space.
There are numerous tutorials on 2D vectors available on the internet.
Instance Method Summary # collapse
- 
  
    
      #%(vector)  ⇒ Float 
    
    
  
  
  
  
  
  
  
  
  
    The #% method is used to compute the dot product between two vectors. 
- #*(vector) ⇒ Float
- #+(vector) ⇒ Geom::Vector2d
- #-(vector) ⇒ Geom::Vector2d
- #==(vector) ⇒ Boolean
- #[](index) ⇒ Float
- #[]=(index, value) ⇒ Float
- 
  
    
      #angle_between(vector)  ⇒ Float 
    
    
  
  
  
  
  
  
  
  
  
    The #angle_between method computes the angle in radians between the Vector2d and another Vector2d. 
- #clone ⇒ Geom::Vector2d
- #cross(vector) ⇒ Float
- 
  
    
      #dot(vector)  ⇒ Float 
    
    
  
  
  
  
  
  
  
  
  
    The #dot method is used to compute the dot product between two vectors. 
- 
  
    
      #initialize(*args)  ⇒ Object 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    The new method creates a new Vector2d. 
- #inspect ⇒ String
- #length ⇒ Length
- #length=(length) ⇒ Length
- 
  
    
      #normalize  ⇒ Geom::Vector2d 
    
    
  
  
  
  
  
  
  
  
  
    The #normalize method returns a Vector2d that is a unit vector of the Vector2d. 
- 
  
    
      #normalize!  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    The #normalize! method converts a Vector2d vector into a unit vector. 
- 
  
    
      #parallel?(vector)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    The #parallel? method determines if two Vector2ds are parallel within a tolerance. 
- 
  
    
      #perpendicular?(vector)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    The #perpendicular? method determines if two Vector2ds are perpendicular within a tolerance. 
- #reverse ⇒ Geom::Vector2d
- #reverse! ⇒ Object
- 
  
    
      #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!(*args) ⇒ Object
- #to_a ⇒ Array(Float, Float)
- #to_s ⇒ String
- 
  
    
      #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. 
- 
  
    
      #unit_vector?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    The #unit_vector? method returns whether the Vector2d is a unit vector. 
- #valid? ⇒ Boolean
- #x ⇒ Float
- #x=(x) ⇒ Float
- #y ⇒ Float
- #y=(y) ⇒ Float
Constructor Details
↑ #initialize ⇒ Geom::Vector2d #initialize(x, y) ⇒ Geom::Vector2d #initialize(vector) ⇒ Geom::Vector2d
The new method creates a new Geom::Vector2d.
Instance Method Details
↑ #%(vector) ⇒ Float
↑ #*(vector) ⇒ Float
The #* method returns the cross product between two Geom::Vector2d. This is an alias of the cross method.
↑ #+(vector) ⇒ Geom::Vector2d
The #+ method adds a Geom::Vector2d to this one.
↑ #-(vector) ⇒ Geom::Vector2d
The #- method subtracts a Geom::Vector2d from this one.
↑ #==(vector) ⇒ Boolean
The #== method returns whether two Geom::Vector2d are equal within tolerance.
↑ #[](index) ⇒ Float
The #[] method returns the value of the Geom::Vector2d at the specified index.
↑ #[]=(index, value) ⇒ Float
The #[]= method sets the x or y value of the Geom::Vector2d based on the specific index of the value.
↑ #angle_between(vector) ⇒ Float
The #angle_between method computes the angle in radians between the Geom::Vector2d and another Geom::Vector2d.
↑ #clone ⇒ Geom::Vector2d
The #clone method makes a copy of the Geom::Vector2d. This method is equivalent to vec2 = Geom::Vector2d.new(vec).
↑ #cross(vector) ⇒ Float
The #cross method returns the cross product between two Geom::Vector2ds.
The cross product, also called the vector product, is an operation on two vectors. The cross product of two vectors produces a third vector which is perpendicular to the plane in which the first two lie.
↑ #inspect ⇒ String
The #inspect method formats the Geom::Vector2d as a string.
↑ #length ⇒ Length
The #length method returns the length of the Geom::Vector2d.
↑ #length=(length) ⇒ Length
The #length= method sets the length of the Geom::Vector2d. The new length must not be 0.
↑ #normalize ⇒ Geom::Vector2d
The #normalize method returns a Geom::Vector2d that is a unit vector of the Geom::Vector2d.
↑ #normalize! ⇒ Object
The #normalize! method converts a Geom::Vector2d vector into a unit vector. Another way to do this is vector.length = 1.0
↑ #parallel?(vector) ⇒ Boolean
The #parallel? method determines if two Geom::Vector2ds are parallel within a tolerance. Two vectors are parallel if there exists a scalar multiple between them.
↑ #perpendicular?(vector) ⇒ Boolean
The #perpendicular? method determines if two Geom::Vector2ds are perpendicular within a tolerance. Two vectors are considered perpendicular if their dot product is zero.
↑ #reverse ⇒ Geom::Vector2d
The #reverse method returns a new Geom::Vector2d that is the reverse of the Geom::Vector2d, leaving the original unchanged.
↑ #reverse! ⇒ Object
The #reverse! method reverses the Geom::Vector2d in place.
↑ #same_direction?(vector) ⇒ Boolean
The #same_direction? method determines if the Geom::Vector2d is parallel to and in the same direction as another Geom::Vector2d within tolerance.
↑ #set!(vector) ⇒ Geom::Vector2d #set!(x, y) ⇒ Geom::Vector2d
The #set! method sets the values of the Geom::Vector2d.
↑ #to_a ⇒ Array(Float, Float)
The #to_a method retrieves the coordinates of the Geom::Vector2d in an Array.
↑ #to_s ⇒ String
The #to_s method returns a string representation of the Geom::Vector2d.
↑ #transform(transform) ⇒ Geom::Vector2d
The #transform method applies a transformation to a vector, returning a new vector. The original vector is unchanged by this method.
↑ #transform!(transform) ⇒ Geom::Vector2d
The #transform! method applies a transformation to a vector. The vector itself is modified.
↑ #unit_vector? ⇒ Boolean
The #unit_vector? method returns whether the Geom::Vector2d is a unit vector. This is equivalent to vector.length == 1.0
↑ #valid? ⇒ Boolean
The #valid? method verifies if a Geom::Vector2d is valid. A Geom::Vector2d is valid if its length is not zero.
↑ #x ⇒ Float
The #x method retrieves the x value of the Geom::Vector2d.
↑ #x=(x) ⇒ Float
The #x= method sets the x coordinate of the Geom::Vector2d.
↑ #y ⇒ Float
The #y method retrieves the y value of the Geom::Vector2d.
↑ #y=(y) ⇒ Float
The #y= method sets the y coordinate of the Geom::Vector2d.