问题在于平方根只对正数有意义;至少在一种情况下,论点是否定的。
-
- ;draw real distances from GPS coordinates
- ;load points from csv files
- (Defun C:gpx ( / Xcoord Ycoord dataL Rpt csv_name ofil rd-pos n Pi1 P1 cntr P2n ang ED lat1 lat2 Dlat Dlong a c RD ent entdata)
- ;*******************load files***************
- (setq dataL '());define an empty list
- (setq Rpt '());define an empty list for points
- (setq csv_name "");define an empty name for file
- (setq csv_name (getfiled "Select Point List .csv file" "" "csv" 2));get the file name
- (setq ofil (open CSV_name "r")); define "ofile" as open the file
- (while (setq rd-pos (read-line ofil));read each line from file
- (setq Xcoord (substr rd-pos 1 (vl-string-position (ascii ",") rd-pos)))
- (setq Ycoord (substr rd-pos (+ (vl-string-position (ascii ",") rd-pos) 2) (- (strlen rd-pos) (vl-string-position (ascii ",") rd-pos) 1)))
- (setq dataL (cons (list (read Xcoord) (read Ycoord)) dataL));add each row to list
- );close while
- (close ofil);close file
- (setq dataL (reverse dataL));put list in right order
- (setq n (length dataL));get the number of points
- (setq Pi1 (nth 0 dataL));get initial GPS point
- (setq P1 '(0 0));set initial Real point to "0,0"
- (setq xi1 (car Pi1));get initial x from first point
- (setq yi1 (cadr Pi1));get initial y from first point
- (setq Rpt (cons P1 Rpt));add P1 on list as 0,0
- (setq cntr 1)
- (while (<= cntr n)
- (setq P2n (nth cntr dataL));choose second GPS point by cntr
- (setq Pxn (car P2n));get x from second point
- (setq Pyn (cadr P2n));get y from second point
- (setq ang (angle Pi1 P2n));get angle between points
- (setq ang (* 180.0 (/ ang pi)));convert angles from radians to degrees
- ;calculate real distance
- (setq ED 6371000);earth diameter in metres
- (setq lat1 (abs(* pi (/ xi1 180.0))));lat in rad
- (setq lat2 (abs(* pi (/ Pxn 180.0))))
- (setq Dlat (abs (* pi(/ (- Pxn xi1) 180.0))));abs added
- (setq Dlong (abs (* pi(/ (- Pyn yi1) 180.0))));abs added
- (setq a (+ (expt (sin (/ 2 Dlat)) 2) (* (* (cos lat1) (cos lat2)) (expt (sin (/ 2 Dlong)) 2))))
- (setq c (* 2 (atan (sqrt a) (sqrt (- 1 a)))));calculate earth angle
- (setq RD (* ED c));calculate real distance between GPs Points
- (setq RD (* RD 1000));convert distance from metres to mm
- (setq P2 (polar P1 ang RD));calculate Real P2 by distance and angle
- (setq Rpt (cons P2 Rpt));add next point to the list
- ;reset counter
- (setq cntr (+ 1 cntr))
- );close while loop
- (setq Rpt (reverse RPT));put the list in the right order
- (command ".line" Rpt "");draw a line as real distance between GPS points
- );close lisp
你应该再次验证你的公式-我无法检查它们,因为我不知道它们来自哪里。
(至少第一个)故障制造者数据对是: |