Calculate the angle between two points

First I have two point. For example (120.231234,23.123142) (120.231222,23.123145) and I want calculate the angle between two points.
How do I rewrite from the program?

#include <NewSoftSerial.h>            // Add to library folder
#include <TinyGPS.h>                  // Add to library folder

TinyGPS gps;
NewSoftSerial nss(6, 255);            // Yellow wire to pin 6

void setup() {
  Serial.begin(115200);
  nss.begin(4800);
  Serial.println("Reading GPS");
}

void loop() {
  bool newdata = false;
  unsigned long start = millis();
  while (millis() - start < 5000) {  // Update every 5 seconds
    if (feedgps())
      newdata = true;
  }
  if (newdata) {
    gpsdump(gps);
  }
}

// Get and process GPS data
void gpsdump(TinyGPS &gps) {
  float flat, flon, x,y,lat2,long2;
  unsigned long age;
  gps.f_get_position(&flat, &flon, &age);
  x=flat,y=flon;
  Serial.print(x-5, 4); Serial.print(", "); 
  Serial.println(y-4, 4);
  float course_to (float x, float y, float lat2, float long2);
  lat2=20,long2=123;
  {
    float dlon = radians(long2-x);
  x = radians(x);
  lat2 = radians(lat2);
  float a1 = sin(dlon) * cos(lat2);
  float a2 = sin(x) * cos(lat2) * cos(dlon);
  a2 = cos(x) * sin(lat2) - a2;
  a2 = atan2(a1, a2);
  if (a2 < 0.0)
  {
    a2 += TWO_PI;
  }
}

// Feed data as it becomes available 
bool feedgps(){
  while (nss.available()) {
    if (gps.encode(nss.read()))
      return true;
  }
  return false;
}

The angle between two points is always 180 degrees, isn't it?

Yep. You need three points to define two lines, so you can measure the angle between the lines.

Another argument is I at (120.231234,23.123142).
I wnat go to next point (120.231222,23.123145).
So how could I change the program to calculate.

So how could I change the program to calculate.

To calculate what?

You need some frame of reference. If the two points define a line, and you want to turn to head towards the 2nd point, you have to know which way you are facing. That direction, and your current position, define a line. If you are at one of those two points, and the other one defines where you want to go, then they define a second line, and you can compute the angle between the two lines, and determine what you need to do to get from one point to the other point.

I think I know how to do it.
thanks your answer.

s55666:
I think I know how to do it.
thanks your answer.

This is what make me really sick.... if you know then post how?...

Khalid:

s55666:
I think I know how to do it.
thanks your answer.

This is what make me really sick.... if you know then post how?...

  1. It might be that he had to completely restructure his code, so he would have had to explain his entire code
  2. English probably isn't his first language

Would you write several paragraphs in a foreign language to explain something that you got 3 sentences of help with?

And 3) His solution might not be relevant to the thread at all