为了账号安全,请及时绑定邮箱和手机立即绑定

Point2D Double 不存储双精度

Point2D Double 不存储双精度

森林海 2021-09-29 13:23:16
所以我正在研究一个三角形类,我想使用 Point2D.Double 来存储高精度的点。import java.awt.geom.Point2D.Double;public class Triangle {private Double pointOne = new Double();private Double pointTwo = new Double();private Double pointThree = new Double();private final float PERCISION = 0.009f;public Triangle(double x1, double y1, double x2, double y2, double x3, double y3){    pointOne.x = x1;    pointOne.y = y1;    pointOne.setLocation(x2, y2);    pointOne.setLocation(x3, y3);}public Double getPointOne() {    return pointOne;}public Double getPointTwo() {    return pointTwo;}public Double getPointThree() {    return pointThree;}但是,当我在 main 中测试它并输入下面的代码时,它会打印出坐标,但精度非常低。我尝试使用浮点数,但它总是以相同的结果结束。    Triangle tri = new Triangle( 0.0000, 0.0000, 2.0008, 0.0000, 0.0000, 2.0000);    System.out.println("Point 1 coordinates: (" + tri.getPointOne().getX() + ", " + tri.getPointOne().getY() + ")");    System.out.println("Point 2 coordinates: (" + tri.getPointTwo().getX() + ", " + tri.getPointTwo().getY() + ")");    System.out.println("Point 3 coordinates: (" + tri.getPointThree().getX() + ", " + tri.getPointThree().getY() + ")");这是它打印出来的内容,以备不时之需。点 1 坐标:(0.0, 2.0)点 2 坐标:(0.0, 0.0)点 3 坐标:(0.0, 0.0)理想情况下,这就是我希望它打印出来的内容。点 1 坐标:(0.0000, 2.0008)点 2 坐标:(0.0000, 0.0000)点 3 坐标:(0.0000, 0.0000)
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 220 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信