Created
July 24, 2015 04:18
-
-
Save mathur/e27f255dec5ae853ca0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.rmathur.app.models; | |
public class Vector { | |
public double xComponent, yComponent; | |
public Vector() { | |
this.xComponent = 0; | |
this.yComponent = 0; | |
} | |
public Vector (double x, double y) { | |
this.xComponent = x; | |
this.yComponent = y; | |
} | |
public double getLength (){ | |
return Math.sqrt(Math.pow(this.xComponent, 2) + Math.pow(this.yComponent, 2)); | |
} | |
public double dotProduct(double x, double y) { | |
return (this.xComponent * x) + (this.yComponent * y); | |
} | |
public void scaleVector(double scalar) { | |
this.xComponent = this.xComponent * scalar; | |
this.yComponent = this.yComponent * scalar; | |
} | |
public void makeUnitVector() { | |
double length = this.getLength(); | |
this.xComponent = this.xComponent / length; | |
this.yComponent = this.yComponent / length; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment