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));

}

}

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值