Package rope.vector

Class vec2

All Implemented Interfaces:
R_Constants

public class vec2 extends vec
  • Constructor Details

    • vec2

      public vec2()
    • vec2

      public vec2(float v)
    • vec2

      public vec2(float x, float y)
    • vec2

      public vec2(vec v)
    • vec2

      public vec2(ivec v)
    • vec2

      public vec2(float[] source)
    • vec2

      public vec2(int[] source)
  • Method Details

    • set

      public vec2 set(float x, float y)
      Parameters:
      x -
      y -
      Returns:
      this
    • set

      public vec2 set(float v)
    • set

      public vec2 set(vec v)
    • set

      public vec2 set(ivec v)
    • set

      public vec2 set(float[] source)
    • set

      public vec2 set(int[] source)
    • set_to

      public vec2 set_to(int index, float arg)
    • inv

      public vec2 inv()
      Returns:
      inverse all argument
    • x

      public vec2 x(float x)
    • add_x

      public vec2 add_x(float x)
    • sub_x

      public vec2 sub_x(float x)
    • mult_x

      public vec2 mult_x(float x)
    • div_x

      public vec2 div_x(float x)
    • y

      public vec2 y(float y)
    • add_y

      public vec2 add_y(float y)
    • sub_y

      public vec2 sub_y(float y)
    • mult_y

      public vec2 mult_y(float y)
    • div_y

      public vec2 div_y(float y)
    • s

      public vec2 s(float x)
    • t

      public vec2 t(float y)
    • u

      public vec2 u(float x)
    • v

      public vec2 v(float y)
    • mult

      public vec2 mult(float mx, float my)
      multiply Vector by different float value
      Parameters:
      mx -
      my -
      Returns:
      this vec2 mult by the arguments
    • mult

      public vec2 mult(float m)
    • mult

      public vec2 mult(vec v)
    • mult

      public vec2 mult(ivec v)
    • div

      public vec2 div(float dx, float dy)
      divide Vector by a float value
      Parameters:
      dx -
      dy -
      Returns:
      this vec2 divide by the argument
    • div

      public vec2 div(float d)
    • div

      public vec2 div(vec v)
    • div

      public vec2 div(ivec v)
    • add

      public vec2 add(float ax, float ay)
      add float value
      Parameters:
      ax - float
      ay - float
      Returns:
      this vec2 result of addition
    • add

      public vec2 add(float a)
    • add

      public vec2 add(vec v)
    • add

      public vec2 add(ivec v)
    • sub

      public vec2 sub(float sx, float sy)
      sub float value
      Parameters:
      sx - float
      sy - float
      Returns:
      this vec2 result of substration
    • sub

      public vec2 sub(float s)
    • sub

      public vec2 sub(vec v)
    • sub

      public vec2 sub(ivec v)
    • dot

      public float dot(vec v)
      Parameters:
      v - vec
      Returns:
      the dot product between this and the target vec
    • dot

      public float dot(float x, float y)
    • pow

      public vec2 pow(float pow)
      Parameters:
      pow -
      Returns:
      this vec2 by the power of argument.
    • pow

      public vec2 pow(float pow_x, float pow_y)
      return the power result of this vector
      Parameters:
      pow_x -
      pow_y -
      Returns:
    • normalize

      public vec2 normalize(vec2 target)
      Normalize vector
      Parameters:
      target -
      Returns:
    • normalize

      public vec2 normalize()
    • ortho

      public vec2 ortho(vec2 p)
      Parameters:
      point -
      Returns:
    • ortho

      public vec2 ortho(vec2 origin, vec2 point)
      return the orthogonal projection of the point of the vector or on the line.
      Parameters:
      origin -
      point - must be project on the vector or line.
      Returns:
    • map

      public vec2 map(float minIn, float maxIn, float minOut, float maxOut)
      Parameters:
      minIn -
      maxIn -
      minOut -
      maxOut -
      Returns:
      Vec2
    • map

      public vec2 map(vec2 minIn, vec2 maxIn, vec2 minOut, vec2 maxOut)
      Parameters:
      minIn -
      maxIn -
      minOut -
      maxOut -
      Returns:
    • jitter

      @Deprecated public vec2 jitter(int range)
      Deprecated.
      JITTER
      Parameters:
      range - int
      Returns:
      Vec2 altered with a random gaussian effect
    • jitter

      @Deprecated public vec2 jitter(vec2 range)
      Deprecated.
    • jitter

      @Deprecated public vec2 jitter(int range_x, int range_y)
      Deprecated.
      Parameters:
      range_x - int
      range_y - int
      Returns:
      Vec2 altered with a random gaussian effect
    • rand

      public vec2 rand(float max)
      random
      Parameters:
      max - float
      Returns:
      random value from 0 to float max for each argument
    • rand

      public vec2 rand(float min, float max)
      random
      Parameters:
      min - float
      max - float
      Returns:
      random value from float min to float max for each argument
    • rand

      public vec2 rand(vec2 min, vec2 max)
      random
      Parameters:
      min -
      max -
      Returns:
      random value from vec min to vec max for each argument
    • limit

      public vec2 limit(float max)
      Parameters:
      max -
      Returns:
    • constrain

      public vec2 constrain(float min, float max)
    • constrain

      public vec2 constrain(float max)
    • constrain

      public vec2 constrain(vec2 max)
    • constrain

      public vec2 constrain(vec2 min, vec2 max)
      Constrains a value to not exceed a maximum and minimum value.
      Parameters:
      min -
      max -
      Returns:
    • wave

      public vec2 wave(int timeline, float s)
      WAVE
      Parameters:
      timeline - int
      s - float speed for all vec arg
      Returns:
      vec2 cosinus of the value
    • wave

      public vec2 wave(int timeline, float sx, float sy)
      Parameters:
      timeline -
      sx -
      sy -
      Returns:
    • cos_wave

      public vec2 cos_wave(int timeline, float s)
      Parameters:
      timeline - int
      s - float speed for all vec arg
      Returns:
      vec2 cosinus of the value
    • cos_wave

      public vec2 cos_wave(int timeline, float sx, float sy)
      Parameters:
      timeline -
      sx -
      sy -
      Returns:
    • sin_wave

      public vec2 sin_wave(int timeline, float s)
      Parameters:
      timeline - int
      s - float speed for all vec arg
      Returns:
      vec2 sinus of the value
    • sin_wave

      public vec2 sin_wave(int timeline, float sx, float sy)
    • mod

      public vec2 mod(float mod_x, float mod_y)
      Parameters:
      mod_x -
      mod_y -
      Returns:
      return the modulo of each element in the same order
    • mod

      public vec2 mod(float mod)
    • mod

      public vec2 mod(vec2 mod)
    • sum

      public float sum()
      sum of all components
      Returns:
      float
    • average

      public float average()
      average of all componentsb
      Returns:
      float
    • dist

      public float dist(vec target)
      return distance of the vector or length
      Parameters:
      target -
      Returns:
      float
    • dir

      public vec2 dir()
      return normal cartesian angle coord
      Returns:
      vec2
    • dir

      public vec2 dir(float a_x, float a_y)
      return normal cartesian angle coord
      Parameters:
      a_x -
      a_y -
      Returns:
      vec2
    • dir

      public vec2 dir(vec2 origin)
      return normal cartesian angle coord
      Parameters:
      origin -
      Returns:
      vec2
    • tan

      public vec2 tan()
      return tangent of the vector direction
      Returns:
      vec2
    • tan

      public vec2 tan(float a_x, float a_y)
      return tangent of the vector direction
      Parameters:
      a_x -
      a_y -
      Returns:
      vec2
    • tan

      public vec2 tan(vec2 target)
      return tangent of the vector direction
      Parameters:
      target -
      Returns:
      vec2
    • angle

      public float angle()
      Calculate the angle of rotation for this vector (only 2D vectors)
      Returns:
      the float angle of rotation
    • angle

      public float angle(vec2 target)
      return heading angle
      Parameters:
      target -
      Returns:
      the float angle between this and the target vector
    • heading

      public float heading()
      Calculate the angle of rotation for this vector (only 2D vectors)
      Returns:
      the float angle of rotation
    • magSq

      public float magSq()
      return square of vec
      Returns:
      float
    • mag

      public float mag()
      return square root of magnitude or length of vec2
      Returns:
      float
    • mag

      public float mag(vec target)
      return mag between this vector and the target
      Parameters:
      target -
      Returns:
      float
    • equals

      public boolean equals(vec2 target)
      return true if the vector this is equals to vector target
      Parameters:
      target - Vec2
      Returns:
    • equals

      public boolean equals(float target)
      return true if the vector this is equals to float target
      Parameters:
      target - float
      Returns:
    • equals

      public boolean equals(float t_x, float t_y)
      * return true if the vector this is equals to float arguments
      Parameters:
      t_x - float
      t_y - float
      Returns:
    • compare

      public boolean compare(vec2 target, vec2 area)
      return true if the vector this and vector target are in the same vector area
      Parameters:
      target -
      area -
      Returns:
    • compare

      public boolean compare(vec2 target, float area)
      Parameters:
      target -
      area -
      Returns:
    • in_polygon

      public boolean in_polygon(vec[] points)
      https://forum.processing.org/one/topic/how-do-i-find-if-a-point-is-inside-a-complex-polygon.html http://paulbourke.net/geometry/ thks to Moggach and Paul Brook
      Parameters:
      points - array of point who define the polygon.
      Returns:
      true if the vec2 is in the polygon, false in the other case
    • in_segment

      public boolean in_segment(vec2 start, vec2 end, float range)
      https://forum.processing.org/two/discussion/90/point-and-line-intersection-detection refactoring from Quark Algorithm
      Parameters:
      start - first point of the segment
      end - last point of the segment
      range - the range of pixel around the line to detect if the point is in or out
      Returns:
    • copy

      public vec2 copy()
      copy() return all the component of vec
      Returns:
      Vec2
    • toString

      public String toString()
      Overrides:
      toString in class Object