java 坐标_java – 存储X和Y坐标

您好我是这个网站的新手,需要帮助我正在努力的程序.我遇到的问题是我似乎无法存储字符串和两个整数(作为坐标).我查看了其他代码,但没有看到值的存储方式.下面是我一直在使用的代码.代码似乎没问题,但在尝试存储值时,我不能将乘法整数.谢谢你的时间

import java.util.HashMap;

public class map {

class Coords {

int x;

int y;

public boolean equals(Object o) {

Coords c = (Coords) o;

return c.x == x && c.y == y;

}

public Coords(int x, int y) {

super();

this.x = x;

this.y = y;

}

public int hashCode() {

return new Integer(x + "0" + y);

}

}

public static void main(String args[]) {

HashMap map = new HashMap();

map.put(new coords(65, 72), "Dan");

}

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现在起点坐标和终点坐标之间生成多个坐标点,可以采用以下方法: 1. 根据起点坐标和终点坐标,计算出两点之间的距离和方向角。 2. 根据需要生成的坐标点数量,将两点之间的距离平均分成若干段,计算出每一段的长度和方向角。 3. 根据起点坐标、每一段的长度和方向角,依次计算出每个坐标点的经纬度。 4. 将生成的坐标存储在一个数组中,可以用这些坐标点来绘制轨迹或者进行其他操作。 以下是一个简单的示例代码: ```java public static List<Point> generatePoints(Point start, Point end, int count) { List<Point> points = new ArrayList<>(); double distance = getDistance(start, end); double direction = getDirection(start, end); double segmentLength = distance / count; points.add(start); for (int i = 1; i < count; i++) { double segmentDirection = direction + Math.PI * (i - 0.5) / count; double latitude = start.getLatitude() + segmentLength * Math.cos(segmentDirection) / 111319.9; double longitude = start.getLongitude() + segmentLength * Math.sin(segmentDirection) / (111319.9 * Math.cos(start.getLatitude() * Math.PI / 180)); points.add(new Point(latitude, longitude)); } points.add(end); return points; } private static double getDistance(Point start, Point end) { double lat1 = start.getLatitude(); double lng1 = start.getLongitude(); double lat2 = end.getLatitude(); double lng2 = end.getLongitude(); double radLat1 = Math.toRadians(lat1); double radLat2 = Math.toRadians(lat2); double a = radLat1 - radLat2; double b = Math.toRadians(lng1) - Math.toRadians(lng2); double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2))); s = s * 6378137; s = Math.round(s * 10000) / 10000; return s; } private static double getDirection(Point start, Point end) { double lat1 = start.getLatitude(); double lng1 = start.getLongitude(); double lat2 = end.getLatitude(); double lng2 = end.getLongitude(); double x = Math.sin(Math.toRadians(lng2 - lng1)) * Math.cos(Math.toRadians(lat2)); double y = Math.cos(Math.toRadians(lat1)) * Math.sin(Math.toRadians(lat2)) - Math.sin(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.cos(Math.toRadians(lng2 - lng1)); double direction = Math.atan2(x, y); return direction; } ``` 在以上示例代码中,我们定义了一个`generatePoints`方法,该方法接收起点坐标、终点坐标和需要生成的坐标点数量,返回生成的坐标点数组。我们还定义了两个辅助方法,用于计算两点之间的距离和方向角。你可以根据自己的需求修改这些方法,并在自己的项目中使用它们来生成坐标点。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值