C # method for calculating the direction of vehicle driving _c# Tutorial

Source: Internet
Author: User
Tags abs

In this paper, we analyze the method of C # Calculation of vehicle driving direction. Share to everyone for your reference, specific as follows:

1. Scene: A known 2 GPS coordinates point A (N1,E1), B (e) In the course of the vehicle's journey, calculates the direction it travels.

2. Analysis: As shown in the above figure, know two points A, B, you can assume a C point, so that three points to form a right-angled triangle. It is now known that the A,b,c three points of the GPS coordinates can easily find three corners of the a,b,c. According to the cosine set cosb= (A2+C2-B2)/2AC, you can find the COSB value.

3.c# implementation code.

<summary>///Compute Two-point GPS coordinates distance///</summary>///<param name= "N1" > 1th latitude coordinates </param>///< Param name= "E1" > 1th longitude coordinates </param>///<param name= "n2" > 2nd latitude coordinates </param>///<param name= "E2" > 2nd Longitude coordinates </param>///<returns></returns> public static double Distance (double n1, double E1,
  Double N2, double E2) {double jl_jd = 102834.74258026089786013677476285;
  Double jl_wd = 111712.69150641055729984301412873;
  Double b = Math.Abs ((e1-e2) * JL_JD);
  Double A = Math.Abs ((n1-n2) * jl_wd);
Return Math.sqrt ((A * a + b * b)); ///<summary>///The two GPS points that are known to drive the car, the direction of the car///</summary>///<param name= "N1" > The first GPS point latitude </param >///<param name= "E1" > First GPS point longitude </param>///<param name= "N2" > second GPS point latitude </param>///< param name= "E2" > second GPS point longitude </param>///<returns></returns> public static double Getbusdirection ( Double n1,double e1, double N2, double E2) {double E3= 0;
  Double n3 = 0;
  E3 = e1 + 0.005;
  n3 = N1;
  Double A = 0;
  Double b = 0;
  Double c = 0;
  A = Distance (E1, N1, E3, N3);
  b = Distance (E3, N3, E2, N2);
  c = Distance (e1, N1, E2, N2);
  Double COSB = 0;
  if ((A * c)!= 0) {COSB = (A * a + c * C-b * b)/(2 * A * c);
  Double B = Math.acos (COSB) * 180/MATH.PI;
  if (n2<n1) {b=180+ (180-b);
return B;

 }

Read more about C # Interested readers can view the site topics: "C # string Operation Tips Summary", "C # array Operation tips Summary", "C # XML file Operation Tips Summary", "C # Common control usage Tutorial", "C # Programming Thread Usage Skills summary", "C # Summary of Operation Excel skills, summary of WinForm control usage, C # tutorial on data structure and algorithms, and Introduction to C # object-oriented programming

I hope this article will help you with C # programming.

Related Article

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.