Android Open Source - feather-reveal Vector2 D






From Project

Back to project page feather-reveal.

License

The source code is released under:

MIT License

If you think the Android project feather-reveal listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.test3;
//from w  w w.jav  a  2 s.  com
public class Vector2D {

  private float x;
  private float y;

  public Vector2D() {
  }

  public Vector2D(Vector2D v) {
    this.x = v.x;
    this.y = v.y;
  }

  public Vector2D(float x, float y) {
    this.x = x;
    this.y = y;
  }

  public float getX() {
    return x;
  }

  public float getY() {
    return y;
  }

  public float getLength() {
    return (float)Math.sqrt(x * x + y * y);
  }

  public Vector2D set(Vector2D other) {
    x = other.getX();
    y = other.getY();
    return this;
  }

  public Vector2D set(float x, float y) {
    this.x = x;
    this.y = y;
    return this;
  }

  public Vector2D add(Vector2D value) {
    this.x += value.getX();
    this.y += value.getY();
    return this;
  }

  public static Vector2D subtract(Vector2D lhs, Vector2D rhs) {
    return new Vector2D(lhs.x - rhs.x, lhs.y - rhs.y);
  }

  public static float getDistance(Vector2D lhs, Vector2D rhs) {
    Vector2D delta = Vector2D.subtract(lhs, rhs);
    return delta.getLength();
  }

  public static float getSignedAngleBetween(Vector2D a, Vector2D b) {
    Vector2D na = getNormalized(a);
    Vector2D nb = getNormalized(b);

    return (float)(Math.atan2(nb.y, nb.x) - Math.atan2(na.y, na.x));
  }

  public static Vector2D getNormalized(Vector2D v) {
    float l = v.getLength();
    if (l == 0)
      return new Vector2D();
    else
      return new Vector2D(v.x / l, v.y / l);

  }

  @Override
  public String toString() {
    return String.format("(%.4f, %.4f)", x, y);
  }
}




Java Source Code List

com.example.test3.FeatherRevealView.java
com.example.test3.MainActivity.java
com.example.test3.TouchManager.java
com.example.test3.Vector2D.java