package org.kne.cloud.network.klalb.ui;


public class Vector2 {
	public double x,y;

	public Vector2(double x, double y) {
		super();
		this.x = x;
		this.y = y;
	}
	
	
	
	public Vector2 Set(double x, double y) {
		this.x = x;
		this.y = y;
		return this;
	}
	
	public Vector2 normalize()//ʹ����Ϊ1����Ϊ��λ����
	{
		double l=Math.sqrt(x*x+y*y);
		return l==0?new Vector2(0,0): new Vector2(x / l, y / l);
	}
	public Vector2 normalizeold()//ʹ����Ϊ1����Ϊ��λ����
	{
		double l=Math.sqrt(x*x+y*y);
		if(l==0){
			x=y=0;
		}else{
			this.x = x / l;
			this.y = y / l;
			}
		return this;
	}
	public Vector2 add(Vector2 vec)//��
	{
		
		return new Vector2(this.x + vec.x,this.y + vec.y);
	}
	public Vector2 subtract(Vector2 vec)//��
	{
		return new Vector2(this.x - vec.x,this.y - vec.y);
	}
	public Vector2 multi(double m)//��������
	{
		return new Vector2(this.x*m, this.y*m);
	}
	public double dot(Vector2 vec)//�������
	{
		return vec.x*x + vec.y*y ;
	}
	public Vector2 opposite(){//�෴
		return new Vector2(-x, -y);
	}
	public Vector2 signs() {//��������
		return new Vector2(signs(x),signs(y));
	}
	
	public static int signs(double z2) {
		return z2>0?1:(z2<0?-1:0);
	}
	
	
	
	public Vector2 rotate(Vector2 degree){
		
		double sita=sita()+degree.sita();
		double l=Length();
		return new Vector2(l*Math.cos(sita), l*Math.sin(sita));
	}
	public Vector2 rotate(float degree){
		
		double sita=sita()+degree;
		double l=Length();
		return new Vector2(l*Math.cos(sita), l*Math.sin(sita));
	}
	public float sita() {
		double sita;
		if(x<0){
		sita=Math.atan(y/x)-180;
		}else if(x>0){
			sita=Math.atan(y/x);
		}else{
			sita=y>=0?90:90-180;
		}
		return (float) sita;
	}
	public double Length() {
		
		return  Math.sqrt(x*x+y*y);
	}
	@Override
	public String toString() {
		return "Vector2 [x="+x+", y="+y+"]";
	}
	
}
