Oliver 发表于 2022-7-6 12:03:20

帮助:使用此lisp进行修改

我需要你的帮助来修改这个lisp一个lisp信用证先生“麦克李”,而不是坐标,我想通过绘制“纬度和经度”
 
附件:
测验txt文件
BDimp。LSP

Lee Mac 发表于 2022-7-6 12:07:07

这是对原文的改写(但仍然是笛卡尔式的):
 
(defun c:bdimp (/ StrBrk mk_pt mk_txt FILE LST NL PT)
(vl-load-com)

(defun StrBrk (str chrc / pos lst)
   (while (setq pos (vl-string-position chrc str))
   (setq lst (cons (substr str 1 pos) lst)
         str (substr str (+ pos 4)))) ;;Mod
   (reverse (cons str lst)))

(defun mk_pt (p) (entmake (list '(0 . "POINT") '(8 . "COORD") (cons 10 p))))
   
(defun mk_txt(pt val)
   (entmake (list (cons 0 "TEXT")
                  (cons 8 "POINT NUMBER")
                  (cons 10 pt)
                  (cons 40 1.6)
                  (cons 1val))))
   
(if (setq file (getfiled "Select Text File" (if *load$file* *load$file* "") "txt" 16))
   (progn
   (setq *load$file* file file (open file "r"))
   
   (while (setq nl (read-line file))
       (setq lst (cons (StrBrk nl 32) lst))) (close file)
   
   (foreach line lst      
       (mk_pt (setq pt (mapcar 'distof (list (cadr line) (caddr line) "0"))))
       (mk_txt pt (car line)))))
   
(princ))

Oliver 发表于 2022-7-6 12:11:56

我搞错了李先生
“错误DXF组:(10 nil nil 0.0)”

Lee Mac 发表于 2022-7-6 12:16:33

 
我确实说过上面是笛卡尔的。我猜你用经度/纬度试过了。

Lee Mac 发表于 2022-7-6 12:19:56

我从未将经度转换为纬度,因此这对我来说是一个学习练习,但我在这段代码中的方法是:
[列表]
[*]将Deg Min Sec转换为弧度
[*]使用球面极,将弧度转换为笛卡尔(使用地球半径)。
[*]绘制结果。
[/列表]

;; Plotting Longitude/Latitude~Lee McDonnell (Lee Mac)~12.12.2009

(defun c:bdimp (/ rad StrBrk mk_pt mk_txt get_radians get_cartesian FILE LST NL PT)
(vl-load-com)

(setq rad 6378.1) ;; Radius of Earth (km)

(defun StrBrk (str chrc shift / pos lst)
   (while (setq pos (vl-string-position chrc str))
   (setq lst (cons (substr str 1 pos) lst)
         str (substr str (+ pos shift 2)))) ;;Mod
   (reverse (cons str lst)))

(defun mk_pt (p) (entmake (list '(0 . "POINT") '(8 . "COORD") (cons 10 p))))
   
(defun mk_txt(pt val)
   (entmake (list (cons 0 "TEXT")
                  (cons 8 "POINT NUMBER")
                  (cons 10 pt)
                  (cons 40 1.6)
                  (cons 1val))))

(defun get_radians (deg mins secs)
   (* pi (/ (+ deg (/ mins 60.) (/ secs 3600.)) 180.)))

(defun get_cartesian (r theta phi)
   (mapcar (function (lambda (x) (if (equal x 0. 1e- 0. x)))
   (list (* r (cos theta) (cos phi))
         (* r (cos theta) (sin phi))
         (* r (sin theta)))))
   
(if (setq file (getfiled "Select Text File" (if *load$file* *load$file* "") "txt" 16))
   (progn
   (setq *load$file* file file (open file "r"))
   
   (while (setq nl (read-line file))
       (setq lst (cons (StrBrk nl 32 2) lst))) (close file)
   
   (foreach line lst
       (mk_pt (setq pt
                (apply 'get_cartesian
                  (cons rad
                  (mapcar
                      (function
                        (lambda (x)
                        (apply 'get_radians (mapcar 'distof (StrBrk x 45 0))))) (cdr line))))))
       (mk_txt pt (car line)))))
   
(princ))


 
如果有人能验证我的方法,以便我进一步了解,我将不胜感激

Oliver 发表于 2022-7-6 12:21:49

我想我搞砸了李先生,怎么做这个,我也试过这个样本。。。
 
1   123-44-10   8-03-43
2   123-44-12   8-03-41
3   123-44-06   8-03-37
4   123-44-04   8-03-39
5   123-44-03   8-03-34
6   123-44-01   8-03-37
 
基于我的文件。
 

Lee Mac 发表于 2022-7-6 12:27:57

我最新的代码帖子应该使用经度/纬度,假设使用3空间分隔符。

Oliver 发表于 2022-7-6 12:30:36

这是李先生的作品。。但是有一个错误,纬度和经度是不同的。。
 
http://img69.imageshack.us/img69/4230/snap38.jpg

Lee Mac 发表于 2022-7-6 12:33:19

是的,它可以是任何数量的东西-半径,例如我的方法。

Oliver 发表于 2022-7-6 12:35:13

好吧,等一下,李先生,明天快1:30了。。谢谢你。
页: [1] 2
查看完整版本: 帮助:使用此lisp进行修改