Dart DocumentationbotVector

Vector class

Class reperesenting a 2d vector.

Extends

Coordinate > Vector

Constructors

const Vector([num x = 0, num y = 0]) #

const Vector([num x = 0, num y = 0]) : super(x,y);

Fields

final num x #

inherited from Coordinate
final num x, y;

final num y #

inherited from Coordinate
final num x, y;

Methods

Vector operator *(num magnitude) #

Multiplies each dimensions by the provided magnitude and returns a new Vector.

Vector operator *(num magnitude) => this.scale(magnitude);

Vector operator +(Coordinate other) #

Adds a Coordinate and returns the result as new Vector.

Vector operator +(Coordinate other) => new Vector(x + other.x, y + other.y);

Vector operator -(Coordinate other) #

inherited from Coordinate

Subtract a Coordinate and returns the result as new Vector.

Vector operator -(Coordinate other) => difference(this, other);

bool operator ==(Coordinate other) #

inherited from Coordinate

The equality operator.

The default behavior for all Objects is to return true if and only if this and other are the same object.

If a subclass overrides the equality operator it should override the hashCode method as well to maintain consistency.

docs inherited from Object
bool operator ==(Coordinate other) {
  return other != null && x == other.x && y == other.y;
}

num cross(Vector other) #

Computes the cross product with the given Vector.

num cross(Vector other) => x * other.y - y * other.x;

num dot(Vector other) #

Computes the dot product with the given Vector.

num dot(Vector other) => x * other.x + y * other.y;

num getAngle(Vector other) #

Computes the angle between this and another Vector.

num getAngle (Vector other) => math.acos(dot(other));

num getDistance(Coordinate other) #

inherited from Coordinate

Computes the distance to another Coordinate.

num getDistance (Coordinate other) => (this - other).length;

int hashCode() #

inherited from Object

Get a hash code for this object.

All objects have hash codes. Hash codes are guaranteed to be the same for objects that are equal when compared using the equality operator ==. Other than that there are no guarantees about the hash codes. They will not be consistent between runs and there are no distribution guarantees.

If a subclass overrides hashCode it should override the equality operator as well to maintain consistency.

external int hashCode();

bool get isValid() #

inherited from Coordinate
bool get isValid => isValidNumber(x) && isValidNumber(y);

num get length() #

Computes the length of this Vector.

num get length => math.sqrt(x * x + y * y);

Vector get normal() #

Vector get normal => this.scale(1 / this.length);

noSuchMethod(String name, List args) #

inherited from Object

noSuchMethod is invoked when users invoke a non-existant method on an object. The name of the method and the arguments of the invocation are passed to noSuchMethod. If noSuchMethod returns a value, that value becomes the result of the original invocation.

The default behavior of noSuchMethod is to throw a noSuchMethodError.

external Dynamic noSuchMethod(String name, List args);

Vector rotate(num angle) #

Vector rotate(num angle) {
  var cos = math.cos(angle);
  var sin = math.sin(angle);
  var newX = this.x * cos - this.y * sin;
  var newY = this.y * cos + this.x * sin;
  return new Vector(newX, newY);
}

Vector rotateAroundPoint(Coordinate axisPoint, num angle) #

Vector rotateAroundPoint(Coordinate axisPoint, num angle) {
  return (this - axisPoint).rotate(angle) + axisPoint;
}

Type get runtimeType() #

inherited from Object

A representation of the runtime type of the object.

external Type get runtimeType;

Vector scale(num magnitude) #

Multiplies each dimensions by the provided magnitude and returns a new Vector.

Vector scale(num magnitude) => new Vector(x * magnitude, y * magnitude);

toJson() #

inherited from Coordinate
Dynamic toJson() => { 'x' : x, 'y' : y };

Size toSize() #

inherited from Coordinate
Size toSize() => new Size(x, y);

String toString() #

inherited from Coordinate

Returns a string representation of this object.

docs inherited from Object
String toString() => '{x:${x}, y:${y}}';

Vector toVector() #

inherited from Coordinate
Vector toVector() => new Vector(x, y);