move语句java_java 程序里 有几个地方不明白 1、angle 方法 前两个if 语句 2、movex 、movey 方法作用 3、rotate 方法...

方法部分:publicclassPoint{privatedoublexpose,ypose;publicPoint(){super();//TODOAuto-generatedconstructorstubthis.xpose=0;this.ypose=0;}publicPoint(doublexpose,doubleypos...

方法部分:

public class Point {

private double xpose,ypose;

public Point() {

super();

// TODO Auto-generated constructor stub

this.xpose=0;

this.ypose=0;

}

public Point(double xpose, double ypose) {

super();

this.xpose = xpose;

this.ypose = ypose;

}

@Override

public String toString() {

// TODO Auto-generated method stub

String s="(";

s=s+this.xpose+",";

s=s+this.ypose+")";

return s;

}

public double Length(Point P)

{

double s=Math.pow(this.xpose-P.xpose,2);

s=s+Math.pow(this.ypose-P.ypose,2);

return Math.sqrt(s);

}

public double Angle()

{

if(Math.abs(xpose)==0)

return Math.PI/2;

if(Math.abs(ypose)==0)

return 0;

return Math.atan(ypose/xpose);

}

public void moveX()

{

xpose++;

}

public void moveX(double deltax)

{

xpose+=deltax;

}

public void moveY()

{

ypose++;

}

public void moveY(double deltay)

{

ypose+=deltay;

}

public void Rotate(double theta)

{

double x=xpose*Math.cos(theta)-ypose*Math.sin(theta);

double y=xpose*Math.sin(theta)+ypose*Math.cos(theta);

xpose=x;

ypose=y;

}

}

测试调用部分

public class PointTester {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

Point P1=new Point(0,1);

Point P2=new Point(4,0);

System.out.println(P1);

System.out.println(P2);

System.out.println("length="+P1. Length (P2));

P1. Rotate (3.14159/2);

P2. Rotate (3.14159/2);

System.out.println(P1);

System.out.println(P1);

System.out.println("length="+P1. Length (P2));

}

}

展开


版权声明:本文为weixin_34966284原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。