开发者

GPS in Processing

开发者 https://www.devze.com 2023-04-13 02:11 出处:网络
I doing a small program using Processing, and it\'s开发者_如何学Python basically a map of Europe and a question will ask where a certain capital is in Europe. For example, if the question is where Mil

I doing a small program using Processing, and it's开发者_如何学Python basically a map of Europe and a question will ask where a certain capital is in Europe. For example, if the question is where Milan is and the person clicks on Madrid I want to use a GPS to calculate the distance between Milan and Madrid. So hopefully the output would be "You have clicked on the wrong city. You are xxx miles away from Milan".

How do I code for this?


You definitely don't need a GPS for that, in fact a GPS won't even do what you want. All you need is the coordinates of the capitals for which you will ask the location. Presumably you can get this as latitude and longitude, although since you're displaying them on the screen, perhaps you will just get their x/y coordinates from whatever image/display you are using.

Lets assume you have an x and y for a city, and a click on the screen. The distance between two points on a plane is probably something you learned in high school geometry. The equation is available on Wikipedia.

If for some reason, you need to calculate the distance between two points of latitude/longitude, that's a little more complicated, and probably not worth it, but it's doable -- in fact, the question has been asked on SO.

That should be enough to get you started. If not, you should probably flesh your question out with some details.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号