java 坐标原点_定义一个描述平面坐标系统中点及其操作的类Point.(Java)

这篇博客介绍了一个Java类Point,用于表示平面坐标系统中的点。类包含坐标获取、点平移、判断两点是否相等、确定点所在象限以及计算两点间距离的方法。示例代码展示了如何使用该类进行操作。
摘要由CSDN通过智能技术生成

public class Point {

private double x;

private double y;

public Point(double x, double y){

this.x = x;

this.y = y;

}

public double getX() {

return x;

}

public double getY() {

return y;

}

public void shiftPoint(double w, double h){

x += w;

y += y;

}

public boolean pointEquals(Point point){

if(point.x == x && point.y == y)

return true;

return false;

}

public void whatQuadrant(){

int a = 1;

if( x < 0 && y > 0)

a = 2;

else if(x < 0 && y < 0)

a = 3;

else if(x > 0 && y < 0 )

a = 4;

if( x == 0 && y == 0 )

System.out.println(点(+x+,+y+)在原点);

else if(x == 0 && y !=0 )

System.out.println(点(+x+,+y+)在Y轴);

else if( y == 0 && x != 0 )

System.out.println(点(+x+,+y+)在X轴);

else

System.out.println(点(+x+,+y+)在第+a+象限);

}

public double findDistance(Point p){

BigDecimal b = new BigDecimal(Double.toString(Math.sqrt(Math.pow(x - p.x, 2) + Math.pow(y - p.y, 2))));

return b.setScale(2, BigDecimal.ROUND_CEILING).doubleValue();

}

public String toString(){

return (+x+,+y+);

}

public static void main(String [] args){

Point p =new Point(3,2);

System.out.println(x=+p.getX()+y=+p.getY());

p.pointEquals(new Point(3,2));

p.shiftPoint(5,6);

System.out.println(x=+p.getX()+y=+p.getY());

p.whatQuadrant();

System.out.println(p.findDistance(new Point(0,0)));

System.out.println(p.toString());

}

}

再问: public double findDistance(Point p){ double m=x-p.x; double n=y-p.y; return Math.sqrt(m*m+n*n); }这个简单点你的我不懂

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值