Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Point;
- public class Direction {
- private final double x;
- private final double y;
- public Direction(double x,double y){
- this.x=x;
- this.y=y;
- }
- public Direction(Point point1,Point point2){
- this.x=point1.getX() - point2.getX();
- this.y=point2.getY() - point2.getY();
- }
- double getX(){
- return x;
- }
- double getY(){
- return y;
- }
- Direction sub(Direction direction){
- double tempX=this.x-direction.getX();
- double tempY=this.y-direction.getY();
- Direction subresult=new Direction(tempX,tempY);
- return subresult;
- }
- Direction add(Direction direction){
- double tempX=this.x+direction.getX();
- double tempY=this.y+direction.getY();
- Direction addresult=new Direction(tempX,tempY);
- return addresult;
- }
- Direction mul(double factor){
- double tempX=this.x*factor;
- double tempY=this.y*factor;
- Direction multiply=new Direction(tempX,tempY);
- return multiply;
- }
- Direction normalized(){
- double norm=Math.sqrt(Math.pow(x,2)+Math.pow(y,2));
- double tempX= this.x/norm;
- double tempY= this.y/norm;
- Direction normalized= new Direction (tempX,tempY);
- return normalized;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement