UVA 11817 tunnelling The Earth--Spherical distance formula

Source: Internet
Author: User
Tags acos

Test instructions: Give the latitude and longitude of two points, find the difference between the spherical distance and the straight distance of two points.

Solution: We calculate the spherical distance first, then we can calculate the straight distance according to the spherical distance.

Spherical distance formula: r*acos (sin (W1) *sin (W2) +cos (W1) *cos (W2) *cos (j1-j2)); (W1,W2 is the latitude value of two points, j1,j2 is the longitude value of two points)

The derivation process is not written, can be found on the Internet very clear derivation process.

Then calculate the spherical distance, is actually an arc, according to the length of the arc to find the chord length:

Code:

#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>#definePi ACOs (-1.0)using namespacestd;intMain () {intT,n,i; DoubleX1,x2,y1,y2; DoubleR =6371009; scanf ("%d",&t);  while(t--) {scanf ("%LF%LF",&x1,&y1); scanf ("%LF%LF",&x2,&y2); X1= x1*pi/180.0; Y1= y1*pi/180.0; X2= x2*pi/180.0; Y2= y2*pi/180.0; Doubleans = r*acos (sin (x1) *sin (x2) +cos (x1) *cos (x2) *cos (y1-y2)); printf ("%.0f\n", ans-2*r*sin (ans/(2*R)); }    return 0;}
View Code

UVA 11817 tunnelling The Earth--Spherical distance formula

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.