Angle between 2 lines with each line represented by set of lat/lon pairs

I'm really new to GIS and i'm interested in finding angle between 2 lines. Each line is represented by start location(lat/lon) and end location(lat/lon).

Could some one point to an algorithm or any sample code(in any language), I can port that in to my desired language?

I tried searching in different forums but all i found was distance between 2 points and distance between a point and line, but not one to find the angle.

GeoTools provides a `GeodeticCalculator` for this sort of calculation, so something like this should solve your problem:

``````DefaultGeographicCRS crs = DefaultGeographicCRS.WGS84;
GeodeticCalculator calc = new GeodeticCalculator(crs);
GeometryFactory gf = new GeometryFactory();
Point point1 = gf.createPoint(new Coordinate(0,0));//GenerateRandomData.createRandomPoint();
calc.setStartingGeographicPoint(point1.getX(), point1.getY());

Point point2 =gf.createPoint(new Coordinate(10,10));// GenerateRandomData.createRandomPoint();
calc.setDestinationGeographicPoint(point2.getX(), point2.getY());

double azimuth1 = calc.getAzimuth();
System.out.println("Azimuth1 "+point1+", "+point2+" is "+ azimuth1);

Point point3 = gf.createPoint(new Coordinate(10,-10));//GenerateRandomData.createRandomPoint();
calc.setDestinationGeographicPoint(point3.getX(), point3.getY());

double azimuth2 = calc.getAzimuth();
System.out.println("Azimuth1 "+point1+", "+point3+" is "+ azimuth2);

System.out.println("Angle is "+(azimuth2-azimuth1));
``````