Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Point{
- private double _radius;
- private double _alpha;
- private final double DEFAULT_VAL=0;
- public Point(double x,double y){
- if(y<DEFAULT_VAL){
- _alpha=0;}
- double alpha=Math.atan(y/x);
- _alpha=Math.round(alpha*10000)/(double)10000;
- double radius=Math.sqrt(Math.pow(x,2)+Math.pow(y,2));
- _radius=Math.round(radius*10000)/(double)10000;
- }
- public Point(Point other){
- _radius=other._radius;
- _alpha=other._alpha;
- }
- public double getX(){
- double p=Math.cos(_alpha)*_radius;
- return Math.round(p*10000)/(double)10000;
- }
- public double getY(){
- double p=Math.sin(_alpha)*_radius;
- return Math.round(p*10000)/(double)10000;
- }
- public void setX(double num){
- double y=getY();
- if(num>DEFAULT_VAL && y>DEFAULT_VAL){
- //double radius=getRadius(num,getY());
- _radius=getRadius(num,y);
- //double alpha=getAlpha(num,getY());
- _alpha=getAlpha(num,y);
- }
- }
- public void setY(double num){
- double x=getX();
- if(num>DEFAULT_VAL){
- //double radius=getRadius(getX(),num);
- _radius=getRadius(x,num);
- //double alpha=getAlpha(getX(),num);
- _alpha=getAlpha(x,num);}
- }
- public String toString(){
- return "("+_radius+","+_alpha+")";
- }
- public boolean equals(Point other){
- return this.getY()==other.getY() && this.getX()==other.getX();
- }
- public boolean isAbove(Point other){
- return(this.getY()>other.getY());
- }
- public boolean isUnder(Point other){
- return other.isAbove(this);
- }
- public boolean isLeft(Point other){
- return (this.getX()<other.getX());
- }
- public boolean isRight(Point other){
- return other.isLeft(this);
- }
- public double distance(Point p){
- double d;
- d=Math.sqrt(Math.pow((p.getX() -this.getX()), 2)+Math.pow((p.getY()-this.getY()), 2));
- return Math.round(d*10000)/(double)10000;
- }
- public void move(double dX,double dY){
- if((getX()+dX)>=DEFAULT_VAL && (getY()+dY)>=DEFAULT_VAL){
- setX(getX()+dX);
- setY(getY()+dY);}
- }
- private double getRadius(double x,double y){
- _radius=Math.sqrt(Math.pow(x,2)+Math.pow(y,2));
- return Math.round(_radius*10000)/(double)10000;}
- private double getAlpha(double x,double y){
- if(getY()==DEFAULT_VAL){
- _alpha=Math.PI/2;
- return Math.round(_alpha*10000)/(double)10000;}
- _alpha=Math.atan(y/x);
- return Math.round(_alpha*10000)/(double)10000;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement