What are these GPS data mean, and how to correctly convert them into decimal degrees? - gps

I have a set of household GPS coordinates data, and the format in excel sheet looks like the following (edited for confidential reason):
ID GPSN GPSS GPSE GPSW
1 211234 -9 890123 -9
2 211255 -9 890155 -9
...
My questions are: what kind of GPS coordinates this is (looks like UTM data)? How do I accurately convert them into decimal degrees that only containing a longitude and a latitude (or X, Y data)? Do I need some kind of zoning information to do this correctly? Thanks

I doubt that a GPS receiver would put out UTM coordinates. It looks to me like latitude and longitude in degrees/minutes/seconds (DDMMSS). If so, then one way to do it is the following, in simple Python. The Convert Coordinate Notation tool in ArcGIS might be useful, but you'll have to reformat the data first, probably using Python.
import csv
import sys
# A function that takes 211234, treats it as 21°12'34",
# and returns 21.209444.
def convertToDegrees(DMS):
dms = DMS
dms = int(dms)
seconds = dms % 100
if 60 <= seconds:
print "More than 60 seconds! " + str(DMS) + " is not degrees/minutes/seconds!"
dms /= 100
minutes = dms % 100
if 60 <= minutes:
print "More than 60 minutes! " + str(DMS) + " is not degrees/minutes/seconds!"
dms -= minutes
degrees = dms / 100
degrees += (minutes / 60.0)
degrees += (seconds / (60.0 * 60.0))
if 180 < degrees or -180 > degrees:
print "In " + str(DMS) + ", degrees is outside [-180, 180]: " + str(degrees)
return degrees
# Input and output files from command line parameters
inFilename = sys.argv[1]
outFilename = sys.argv[2]
readFirstRow = False
with open(inFilename, "rb") as inFile:
reader = csv.reader(inFile)
with open(outFilename, "wb") as outFile:
writer = csv.writer(outFile)
# Loop through the rows
for row in reader:
if (not readFirstRow):
# Write the header row only once
writer.writerow(["ID", "latitude", "longitude"])
readFirstRow = True
else:
# Convert this row to latitude and longitude
latitude = 0
longitude = 0
if "-9" != row[1]:
latitude = convertToDegrees(row[1])
if "-9" != row[2]:
latitude = -1 * convertToDegrees(row[2])
if "-9" != row[3]:
longitude = convertToDegrees(row[3])
if "-9" != row[4]:
longitude = -1 * convertToDegrees(row[4])
writer.writerow([row[0], latitude, longitude])
To make sure you get it right, you'll want to confirm that the GPS was putting out latitude and longitude and find out which datum it used (probably WGS 1984).

Related

haversine_distance on data from dataframe rows and an input location

I want to write a function that takes in a float input of the latitude and longitude as tuple. Then applies a function that calculates the distance between that location and the location of a city in data frame with columns for latitude and longitude.
I wrote the first function for finding the distance between two points.
I wrote another function that takes in a tuple input then calculates the distance between it and every column in the dataframe. Then inserts a new column of the distances in the datfarame.
I tried running the celss but I keep getting this error: cannot convert series to float.
What am I doing wrong in the distance calculation?
Note: I cannot import anything other than pandas or math.
import math
def haversine_distance( loc1 , loc2 ):
lat1, lon1 = loc1
lat2, lon2 = loc2
radius = 6371
dlat = math.radians(lat2-lat1)
dlon = math.radians(lon2-lon1)
a = (math.sin(dlat / 2) * math.sin(dlat / 2) +
math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) *
math.sin(dlon / 2) * math.sin(dlon / 2))
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
d = radius * c
return d
def quake_distance_from_loc_dataframe(loc):
df=QUAKE_DF
loc1=list(loc)
dist=[]
loc2= [df['latitude'], df['longitude']]
distance= haversine_distance(loc1 , loc2)
dist.append(distance)
df2=df.insert(loc=3, column='distance_from_loc', value=dist)
return df2.sort_values(by='distance_from_loc', ascending=True)
lat = float(input("enter latitude "))
lon= float(input("enter longitude "))
loc= (lat, lon)
distances=quake_distance_from_loc_dataframe(loc)
print(distances)

how to get the length scale, length unit, energy scale and energy unit from a EELS map data by DM script

I want to get length scale, length unit, energy scale, and energy unit from an EELS map data by DM script
source.ImageGetDimensionCalibration(0, sOrig, sScale, sUnit, 0)
source.ImageGetDimensionCalibration(2, eOrig, eScale, eUnit, 0)
The above codes did not work, it always make the energy unit with 1eV
For example, an EELS data with dispersion 0.9 ev/pixel, or 0.5 ev/pixel, and the energy range from 0 to 400, and the EELS map is 10nm x8nm, I need to get all this information with DM script.
Now the bug of my code is it always count the disepersion is 1 ev/pixel
Any suggestions, thanks
The following script will hopefully clear up any questions:
void PrintCalibrations(image source)
{
number nDim = source.ImageGetNumDimensions()
result("\n '[" + source.ImageGetLabel() +"]:"+ source.ImageGetName() +"' calibrations:")
result("\n Data has " + nDim + " dimensions.")
for( number d=0; d<nDim; d++ )
{
string unit_dim
number scale_dim, origin_dim
source.ImageGetDimensionCalibration(d, origin_dim, scale_dim, unit_dim, 0)
result("\n\t Dimension #"+d+": scale = " + scale_dim + " \t origin = " + origin_dim + " \t [" + unit_dim + "]" )
}
}
// Pick your data by image letter!
Image SIdata_3D := B
Image PickerSpectrum_1D := A
Image elementalMap_2D := D
ClearResults()
PickerSpectrum_1D.PrintCalibrations()
elementalMap_2D.PrintCalibrations()
SIdata_3D.PrintCalibrations()
Applied to a test data set:

List all X coordinates by given a Y coordinate in a line profiles by DM scripting

For a line profile (curve), I want to reach that list all X coordinates that corresponding a Y coordinate by given this Y coordinate. And I could get the minimum and maximum values of these x coordinates. Here supposed I want to list all the X coordinates corresponding y=8, is this correct or any other better way? Thx
Number minx, maxx
Image front=:getfrontimage()
GetSize( front, xsize, ysize )
for (i=0; i<xsize; i++)
{
x= getpixel(front, i, 8)
minx=min(x)
maxx=max(x)
}
You script becomes wrong when you use the min and max, because you can not get a minimum/maximum of a single value (or rather, it is always that value). What you want to do is likely:
image spec := RealImage("Test",4,100)
spec = trunc(Random()*10)
number v = 8
ClearResults()
number nCh = spec.ImageGetDimensionSize(0)
for( number i=0; i<nCh; i++)
{
if( v == sum(spec[i,0]) )
Result("\n Value "+ v +" # " + i )
}
(The sum() is needed here a a trick to convert an image-expression to a single value.)
However, going pixel-by-pixel in script can be slow. Whenever possible, try to code with image-expressions, because they are much faster (for big images).
I therefore often utilize a trick: I threshold an image for the value I search for, and then iterate over that mask as long as it is not all-zero. The max(img,x,y) command will return the first maximum if there are multiple, so I get an ordered list.
image spec := RealImage("Test",4,100)
spec = trunc(Random()*10)
spec.ShowImage()
number v = 8
image mask = (spec==v)?1:0
ClearResults()
while( 0<sum(mask) )
{
number x,y
max(mask,x,y)
Result("\n Value " + v +" # " + x )
mask[x,0]=0
}
Edit: Answering the question of the comment below.
This is how one gets the ZLP maximum (position and value) from a line-profile in calibrated values.
Precursor: DM contains all data as simple arrays and values (real or integer). These are the real data and unrelated to any calibrations. You see these values if you toggle the "calibration" checkbox off in the Image Status palette:
These are the values all script commands etc. will use, i.e. positions are always indices (starting from 0) and values are the raw numeric values stored.
These images or spectra are calibrated by defining an origin and scale (and unit) for each dimensional axis as well as the intensity (=value). These triplets of values can be found in the image display info of data:
Only when the "Show calibrated values" checkbox is checked, is the data displayed in calibrated values. However, the real values remain unchanged. Just the scale/origin values are used to convert the numbers.
If you want to use a script to use calibrated values, then you have to perform the same conversions in you script yourself.
Here is the example:
image spectrum := GetFrontImage()
number xScale = spectrum.ImageGetDimensionScale(0) // 0 for X dimension
number xOrigin = spectrum.ImageGetDimensionOrigin(0)
string xUnit = spectrum.ImageGetDimensionUnitString(0)
number iScale = spectrum.ImageGetIntensityScale()
number iOrigin = spectrum.ImageGetIntensityOrigin()
string iUnit = spectrum.ImageGetIntensityUnitString()
string info = "\n"
info += "Image ["+spectrum.ImageGetLabel()+"]:"
info += "\n\t Dimension calibration: nCh * " + xScale + " + " + xOrigin + " [" + xUnit + "]"
info += "\n\t Intensity calibration: (value - " + iOrigin + ") * " + iScale +" [" + iUnit + "]"
Result(info)
// Find ZLP maximum (uncalibrated values)
number maxP_ch, dummy, maxV_raw
maxV_raw = max(spectrum,maxP_ch,dummy)
info = "\n"
info += "\n\t The maximum position is at channel index: " + maxP_ch
info += "\n\t The maximum Value at maximum position is: " + maxV_raw
Result(info)
number maxP_cal = xOrigin + xScale * maxP_ch
number maxV_cal = (maxV_raw - iOrigin) * iScale
info = "\n"
info += "\n\t The maximum position is at : " + maxP_cal
info += "\n\t The maximum Value is : " + maxV_cal
Result(info)
Note the different calibration formulas between dimensional calibration and intensity calibration!

"Get 100 meters out from" Haversin Formula

I'm interested in working with coordinates, and I was wondering, how is it possible to get the distance between two points (coordinates) in meters. After a long search I found the Haversine Formula, and the Objective-C implementation of it here.
It's the following (I modified it a little bit for myself):
- (CGFloat)directMetersFromCoordinate:(CLLocation *)from toCoordinate:(CLLocation *)to {
static const double DEG_TO_RAD = 0.017453292519943295769236907684886;
static const double EARTH_RADIUS_IN_METERS = 6372797.560856;
double latitudeArc = (from.coordinate.latitude - to.coordinate.latitude) * DEG_TO_RAD;
double longitudeArc = (from.coordinate.longitude - to.coordinate.longitude) * DEG_TO_RAD;
double latitudeH = sin(latitudeArc * 0.5);
latitudeH *= latitudeH;
double lontitudeH = sin(longitudeArc * 0.5);
lontitudeH *= lontitudeH;
double tmp = cos(from.coordinate.latitude*DEG_TO_RAD) * cos(to.coordinate.latitude*DEG_TO_RAD);
return EARTH_RADIUS_IN_METERS * 2.0 * asin(sqrt(latitudeH + tmp*lontitudeH)); }
My question is:
How is it possible to get 100 meters distance (for latitude and for longitude) for the current location?
This formula is too complicated for me, I don't understand it, so I can't "code it back" to get the result what I want.
I need only the actual location (Paris, Tokyo, London, New York, whatever), and a (float) number for latitude and a (float) number for longitude, which (float) number represents 100 meters distance from the actual location.
If you open this page, here you can "calculate out" the 100 meters distance between two points ("actual" and the one 100 meters away).
For example:
Point1: 47.0, 19.0
Point2: 47.0, 19.0013190
---That's 0.1000 km (100 m) distance.
Point1: 47.0, 19.0
Point2: 47.0008995, 19.0
---is also 0.1000 km (100 m) distance.
Here you can see, that at that coordinate (latitude 47.0 and longitude 19.0) 100 meters distance is 0.0008995 (latitude) and 0.0013190 (longitude).
And I want to get these data with the help of the Haversine Formula, just don't know, how.
Could you help me to figure it out?
Thanks!
UPDATE:
Thank you for the answers, right now I don't have time to try them out, but as I understood, I didn't explain exactly what I want.
Maybe this is a better example, how I want to use these "100 meters":
So, right now I'm at the coordinate "lat x" and "lon y". There is another point (let's say a hotel) at another given coordinate, "lat a" and "lon b".
My question is: how can I calculate out, if this hotel is (less than) 100 meters from me? So it doesn't matter, if it's only 5 meters or 99 meters, both of them are less (or equal) than 100 meters far from me.
With the code what I provided, I can calculate this out, that's what that formula is for.
But let's say, I have a million of other coordinates (hotel locations) that I want to work with. And I need only a list of them, what are (less than) 100 meters away from me. So yes, that's a circle around me with a radius of 100 meters, and I need the results within that.
It would take much more time and resource to take all the coordinates of these "million" hotels and calculate the distance one by one, that's why I thought it would be much easier to calculate out, how much 100 meters are in latitude and longitude (changes the value as we are on different locations, that' why I can't use simply the ones what I calculated out in the example above).
So if I would know how much 100 meters are in latitude and longitude for example at London's coordinate (if I'm there), I could simply get the list of the hotels what are (less than) 100 meters far from me, by a simple dividing:
if
((hotelLocation.coordinate.latitude <= (myLocation.coordinate.latitude + "100metersInLatitude")) || (hotelLocation.coordinate.latitude >= (myLocation.coordinate.latitude - "100metersInLatitude")))
&&
((hotelLocation.coordinate.longitude <= (myLocation.coordinate.longitude + "100metersInLongitude")) || (hotelLocation.coordinate.longitude >= (myLocation.coordinate.longitude - "100metersInLongitude")))
{
NSLog(#"Be Happy :-) !");
}
I just need these "100metersInLatitude" and "100metersInLongitude", calculated always from "myLocation".
Whoa, I hope, somebody will understand what I just wrote down, because it's not easy for me, neither... :-)))
Assuming you have a point with latitude and longitude, and you want to find another point that is a distance d on a bearing b, when the distance is small (you said "100 meters" which is very small on the surface of the earth) then you can do a simple approximation - treating the earth's surface locally as "flat". Here is a simple C program that implements this (using the numbers you had above). I updated it to include the "accurate" formulation as well - it's just a few more calculations, but it is accurate at all distances (and not just the short ones). The equation I used came from the link you referenced - subheading "Destination point given distance and bearing from start point"
updated - I moved the accurate calculation into a separate function, and added a loop to compute the new point for all integer bearings from 0 to 359, printing out every 30th. This give you the "circle" I talked about in my initial comment.
#include <stdio.h>
#include <math.h>
double radians(double x) {
return acos(0.0) * x / 90.0;
}
void calcNewPosition(double lat, double lon, double bearing, double d, double *newLat, double *newLon) {
double lat1, lon1, br, pi;
double Re = 6371000;
// convert everything to radians first:
lat1 = radians(lat);
lon1 = radians(lon);
br = radians(bearing);
pi = 2 * acos(0.0);
double lat2, lon2;
lat2 = asin( sin(lat1) * cos(d/Re) +
cos( lat1 ) * sin( d / Re ) * cos(br ) );
lon2 = lon1 + atan2(sin(br) * sin( d / Re ) * cos( lat1 ), \
cos( d / Re ) - sin(lat1 ) * sin( lat2 ) );
*newLat = 180. * lat2 / pi;
*newLon = 180. * lon2 / pi;
}
int main(void) {
double lon = 47., lat=19.;
double newLongitude, newLatitude;
double dx, dy, dLong, dLat;
double Re = 6371000, d = 100, bearing = 0.0;
double pi;
double lat1, lon1, br;
// convert everything to radians first:
lat1 = radians(lat);
lon1 = radians(lon);
br = radians(bearing);
pi = 2 * acos(0.0);
// approximate calculation - using equirectangular approximation
// and noting that distance between meridians (lines of longitude)
// get closer at higher latitudes, with cos(latitude).
dx = d * sin(br); // distance in E-W direction
dy = d * cos(br); // distance in N-S direction
dLat = 360 * dy / (2.0 * pi * Re); // convert N-S to degrees latitude
dLong = 360 * dx / (2.0 * pi * Re * cos(lat1)); // convert E-W to degrees longitude
newLatitude = lat + dLat;
newLongitude = lon + dLong;
printf("simple forumula: the new position is %.8lf lon, %.8lf lat\n", newLongitude, newLatitude);
// more accurate formula: based on http://www.movable-type.co.uk/scripts/latlong.html
double lat2, lon2;
calcNewPosition(lat, lon, bearing, d, &lat2, &lon2);
printf("more accurate: the new position is %.8lf lon, %.8lf lat\n", lon2, lat2);
// now loop over all bearings and compute the "circle of points":
int iBearing;
double lonArray[360], latArray[360];
for(iBearing = 0; iBearing < 360; iBearing++) {
calcNewPosition(lat, lon, (double)iBearing, d, &latArray[iBearing], &lonArray[iBearing]);
if (iBearing % 30 == 0) printf("bearing %03d: new lat = %.8lf, new lon = %.8lf\n", iBearing, latArray[iBearing], lonArray[iBearing]);
}
return 0;
}
The output of this is
simple forumula: the new position is 47.00000000 lon, 19.00089932 lat
more accurate: the new position is 47.00000000 lon, 19.00089932 lat
bearing 000: new lat = 19.00089932, new lon = 47.00000000
bearing 030: new lat = 19.00077883, new lon = 47.00047557
bearing 060: new lat = 19.00044966, new lon = 47.00082371
bearing 090: new lat = 19.00000000, new lon = 47.00095114
bearing 120: new lat = 18.99955034, new lon = 47.00082371
bearing 150: new lat = 18.99922116, new lon = 47.00047557
bearing 180: new lat = 18.99910068, new lon = 47.00000000
bearing 210: new lat = 18.99922116, new lon = 46.99952443
bearing 240: new lat = 18.99955034, new lon = 46.99917629
bearing 270: new lat = 19.00000000, new lon = 46.99904886
bearing 300: new lat = 19.00044966, new lon = 46.99917629
bearing 330: new lat = 19.00077883, new lon = 46.99952443
As you can see, it is accurate to within a fraction of a meter (your code gave 19.0008995 - it is actually possible that your result was "wrong" in the last digit as these two methods agree to 8 significant digits even though they use different equations).
The question isn't really answerable if the OP wants a location a distance (100 meters) from the current location without a desired bearing being provided, there being an infinite number of points in a circle around the point.
So, this answer may or may not be what the OP wants, it is a way with CLLocation to calculate the distance between two points.
Create two CLLocation point and use the method Have you looked at theCLLocationmethod- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location`.
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:)latitude1 longitude:longitude1];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:)latitude2 longitude:longitude2];
double distance = [location1 distanceFromLocation:location2];
The radius of the earth at equator = 6,371 km. The equator is divided into 360 degrees of longitude, so each degree at the equator represents approximately 111.32 km. Moving away from the equator towards a pole this distance decreases to zero at the pole.To calculate the distance at different latitudes multiply it by the cosine of the latitude
3 decimal places,0.001 degrees aproximates to
111.32 meters at equator
96.41meters at 30 degrees N/S
78.71 meters at 45 degrees N/S
55.66 meters at 60 degrees N/S
28.82 meters at 75 degrees N/S
For for small distances (100 meters) Pythagoras’ theorem can be used on an equirectangular projection to calculate distance. This is less complicated than Haversine or Spherical Law of Cosines.
var R = 6371; // km
lat/lng in radians
In pseudo code as I don't know Objective-C
var x = (lng2-lng1) * cos((lat1+lat2)/2);
var y = (lat2-lat1);
var d = sqrt(x*x + y*y) * R;

Minimum distance between a point and a line in latitude, longitude

I have a line with two points in latitude and longitude
A: 3.222895, 101.719751
B: 3.227511, 101.724318
and 1 point
C: 3.224972, 101.722932
How can I calculate minimum distance between point C and a line consists of point A and B?
It will be convenient if you can provide the calculation and objective-c code too. The distance is around 89 meters (using ruler in Google Earth).
Thanks to mimi and this great article http://www.movable-type.co.uk/scripts/latlong.html but they don't give the whole picture. Here is a detail one. All this points are collected using Google Earth using Placemark to mark the locations. Make sure lat/long are set to decimal degrees in Preferences.
lat A = 3.222895
lon A = 101.719751
lat B = 3.222895
lon B = 101.719751
lat C = 3.224972
lon C = 101.722932
Earth radius, R = 6371
1. First you have to find the bearing from A to C and A to B.
Bearing formula
bearingAC = atan2( sin(Δλ)*cos(φ₂), cos(φ₁)*sin(φ₂) − sin(φ₁)*cos(φ₂)*cos(Δλ) )
bearingAB = atan2( sin(Δλ)*cos(φ₂), cos(φ₁)*sin(φ₂) − sin(φ₁)*cos(φ₂)*cos(Δλ) )
φ is latitude, λ is longitude, R is earth radius
2. Find A to C distance using spherical law of cosines
distanceAC = acos( sin(φ₁)*sin(φ₂) + cos(φ₁)*cos(φ₂)*cos(Δλ) )*R
3. Find cross-track distance
distance = asin(sin(distanceAC/ R) * sin(bearingAC − bearing AB)) * R
Objective-C code
double lat1 = 3.227511;
double lon1 = 101.724318;
double lat2 = 3.222895;
double lon2 = 101.719751;
double lat3 = 3.224972;
double lon3 = 101.722932;
double y = sin(lon3 - lon1) * cos(lat3);
double x = cos(lat1) * sin(lat3) - sin(lat1) * cos(lat3) * cos(lat3 - lat1);
double bearing1 = radiansToDegrees(atan2(y, x));
bearing1 = 360 - ((bearing1 + 360) % 360);
double y2 = sin(lon2 - lon1) * cos(lat2);
double x2 = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lat2 - lat1);
double bearing2 = radiansToDegrees(atan2(y2, x2));
bearing2 = 360 - ((bearing2 + 360) % 360);
double lat1Rads = degreesToRadians(lat1);
double lat3Rads = degreesToRadians(lat3);
double dLon = degreesToRadians(lon3 - lon1);
double distanceAC = acos(sin(lat1Rads) * sin(lat3Rads)+cos(lat1Rads)*cos(lat3Rads)*cos(dLon)) * 6371;
double min_distance = fabs(asin(sin(distanceAC/6371)*sin(degreesToRadians(bearing1)-degreesToRadians(bearing2))) * 6371);
NSLog(#"bearing 1: %g", bearing1);
NSLog(#"bearing 2: %g", bearing2);
NSLog(#"distance AC: %g", distanceAC);
NSLog(#"min distance: %g", min_distance);
Actually there's a library for this. You can find it here https://github.com/100grams/CoreLocationUtils
Calculate bearing for each: C to A , and C to B:
var y = Math.sin(dLon) * Math.cos(lat2);
var x = Math.cos(lat1)*Math.sin(lat2) -
Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
var brng = Math.atan2(y, x).toDeg();
dLon= lon2-lon1;
Calculate cross-track distance:
var dXt = Math.asin(Math.sin(distance_CB/R)*Math.sin(bearing_CA-bearing_CB)) * R;
R is the radius of earth, dXt is the minimum distance you wanted to calculate.
Code to carry out this calculation is posted at here.
This implements an accurate solution in terms of ellipsoidal geodesics.
For the basic geodesic calculations, you can use
GeographicLib or the port of these algorithms to C which are included in version 4.9.0 of PROJ.4. This C interface is documented here.
Here's the result of compiling and running intercept.cpp:
$ echo 3.222895 101.719751 3.227511 101.724318 3.224972 101.722932 | ./intercept
Initial guess 3.225203 101.7220345
Increment 0.0003349040566247297 0.0003313413822354505
Increment -4.440892098500626e-16 0
Increment 0 0
...
Final result 3.225537904056624 101.7223658413822
Azimuth to A1 -135.1593040635131
Azimuth to A2 44.84069593652217
Azimuth to B1 134.8406959363608
Distance to line is 88.743m:
$ echo 3.224972 101.722932 3.225537904056624 101.7223658413822 | GeodSolve -i
-45.15927221 -45.15930407 88.743
See post here:
https://stackoverflow.com/a/33343505/4083623
For distance up to a few thousands meters I would simplify the issue from sphere to plane.
Then, the issue is pretty simply as a easy triangle calculation can be used:
We have points A and B and look for a distance X to line AB. Then:
Location a;
Location b;
Location x;
double ax = a.distanceTo(x);
double alfa = (Math.abs(a.bearingTo(b) - a.bearingTo(x))) / 180
* Math.PI;
double distance = Math.sin(alfa) * ax;
If you know how to calculate the distance of two points, get the distances between each two points, you get AB, AC, and BC. You want to know the closest distance between point C and line AB.
First get the value of P
P=(AB+BC+AC)/2
Using P, you need to get S
S=SQRT((P(P-AC)(P-AB)(P-AC))
SQRT means square root. Then you get what you want by
2*S/AB