乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 59|回复: 19

[编程交流] lisp多段线

[复制链接]

4

主题

8

帖子

4

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-5 20:21:42 | 显示全部楼层 |阅读模式
大家好,
 
我对论坛和lisp编程都很陌生。我已经写了一个小的lisp程序,将帮助我的OHTL线的设计。我想要实现的是一条抛物线。已知x坐标-相距0.5m,但必须计算y坐标。我要找的是一个可以将顶点添加到多段线的脚本(X坐标已知,Y是为每个循环计算的)。乘积应该是具有顶点的多段线。它应该是这样的:
212145wds1dz7k7zw1jhmh.jpg
回复

使用道具 举报

63

主题

242

帖子

181

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
319
发表于 2022-7-5 20:25:52 | 显示全部楼层
抛物线必须有常数,所以必须有常数
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 20:31:03 | 显示全部楼层
 
欢迎来到Cadtutor
 
抛物线试验。lsp V1.2:对称选项:t/nil
V1.1:将子函数包装在C中:测试
 
  1. (defun c:test (/ user p [b]symmetric[/b] [color="red"]*equation*[/color]) ; localize if no user prompt *OPTIONAL
  2. ;due to the sub-function is global variable, so prefix [color="red"]hp:[/color] is just making it unique name to avoid conflict
  3. (defun [b]hp:graph[/b]        (str i dist pt / X lst)
  4. ;;;  hanhphuc 25.12.2014 merry Xmas
  5. (or cal (arxload "geomcal"))
  6. (if (and str i dist pt)
  7.    (progn (setq X 0.0 ) ;_ end of setq
  8.    (repeat (1+ (abs (fix (/ dist i))))
  9.      (setq lst (cons (list (+ (car pt) X) (+ (cadr pt) (cal str))) lst)
  10.            X   (+ X i)
  11.            ) ;_ end of setq
  12.      ) ;_ end of repeat
  13.    (entmakex (vl-list* '(0 . "LWPOLYLINE")
  14.                        '(100 . "AcDbEntity")
  15.                        '(100 . "AcDbPolyline")
  16.                        '(70 . 0)
  17.                        (cons 90 (length lst))
  18.                        (mapcar ''((x) (cons 10 (trans x 1 0))) lst)
  19.                        ) ;_ end of vl-list*
  20.              ) ;_ end of entmakex
  21.    ) ;_ end of progn
  22.    ) ;_ end of if
  23. (princ)
  24. ) ;_ end of defun
  25. [b][color="red"](setq symmetric [color="blue"]t[/color])[/color][/b] ; [color="blue"]<--- t / nil : user setting v1.2[/color]
  26. (or *equation* (setq *equation* [color="red"]"[b]X^2[/b]"[/color])) ;[color="blue"]<-- default example[/color]
  27. [color="red"]
  28. ;*[u]OPTIONAL: un-commented after this paragraph which prompt for user input[/u]
  29. ;(setq        user           (getstring (strcat "\nKey your equation, Y= " *equation* " ? "))
  30. ;        *equation* (if (= user "")
  31. ;                     *equation*
  32. ;                     user
  33. ;                     ) ;_ end of if
  34. ;        ) ;_ end of setq[/color]
  35. (if (setq p (getpoint "\nPick point.. "))
  36. (foreach x '([color="red"][b]0.5 -0.5[/b][/color])     ;[color="blue"] <-- increment[/color]
  37.    ([b]hp:graph[/b]
  38. [b][color="red"] (if symmetric [color="gray"]; v1.2[/color]
  39. (if (minusp x)
  40.         ((lambda(str)(last
  41.           (mapcar ''((a b) (setq str (vl-string-translate a b str))) '("+" "-" "?") '("?" "+" "-"))
  42.           ) ;_ end of last
  43.           ) *equation* )
  44.         *equation*
  45.         ) ;_ end of if
  46. *equation*)[/color][/b]
  47.       x  
  48.       [color="red"][b]50.0[/b][/color]            ;[color="blue"] <-- Distance[/color]
  49.       p)
  50.      )
  51.    ) ;_ end of if
  52. (princ)
  53. ) ;_ end of defun
回复

使用道具 举报

4

主题

8

帖子

4

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-5 20:31:52 | 显示全部楼层
版本检查
 
  1. ;example: if you have a constant =0.1 , just add in the default
  2. (defun c:test (/ user p [color="red"]*equation*[/color]) ; localize if no user prompt
  3. ...
  4. ...
  5. ...
  6. (or *equation* (setq *equation* "[b]X^2[/b][color="red"]*0.1[/color]")) ; add constant *0.1
  7. ...
  8. ...
回复

使用道具 举报

GP_

8

主题

248

帖子

245

银币

初来乍到

Rank: 1

铜币
42
发表于 2022-7-5 20:36:20 | 显示全部楼层
韩,非常感谢!
这很好用。我已经编辑了脚本并添加了来自之前计算的常数。
 
有没有办法将抛物线放置在屏幕上的起点(例如最左上角的点)处。还有一件事,两端并不总是相等的,你能为抛物线增加额外的条件,从某个垂直坐标开始,到另一个水平结束吗?
老实说,我不知道如何做到这一点。
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 20:38:19 | 显示全部楼层
试试这个
  1. (vl-load-com)
  2. (if ((lambda (vrsn)
  3. (cond
  4.         ((vl-string-search "R17.2" vrsn) (setq appstr "6.0")) ;09
  5.         ((vl-string-search "R18.0" vrsn) (setq appstr "7.0")) ;10
  6.         ((vl-string-search "R18.1" vrsn) (setq appstr "8.0")) ;11
  7.         ((vl-string-search "R18.2" vrsn) (setq appstr "9.0")) ;12 ?
  8.         ((vl-string-search "R19.0" vrsn) (setq appstr "10.0")) ;13
  9.         ((alert "This version of C3D not supported!"))
  10.        )
  11. )
  12.       (vlax-product-key)
  13.      )
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 20:43:32 | 显示全部楼层
感谢ymg3和GP_添加此信息
回复

使用道具 举报

4

主题

8

帖子

4

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-5 20:45:09 | 显示全部楼层
回复

使用道具 举报

63

主题

242

帖子

181

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
319
发表于 2022-7-5 20:47:19 | 显示全部楼层
try this

[code];writen by eng motee malazi,syria,latakia,date:10/2013(defun c:test (/) (setq p1(getpoint"\n pick top first head")) (setq p1d(getpoint"\n pick bottom first head")) (setq p2(getpoint"\n pick top second head")) (setq p2d(getpoint"\n pick bottom second head")) (setq H1(-(cadr p1)(cadr p1d))) (setq H2(-(cadr p2)(cadr p2d))) (setq hm(min H1 H2)) (setq y3(min H1 H2)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;(if(null y3)   (setq y3 y3)) (setq hmnew(getreal(strcat"\n enter height of lowest point in parabola" "(""
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 20:50:49 | 显示全部楼层
you are welcome
 
im not really good in math,
if i recall, i think linear equations Y=mX+c ? where c meets at the Y axis?
ie can be measured from origin.
 
You need to be good in math to solve the equations
example: we plot Y=X^2 , ie X=sqrt(Y)
 
assume you have the Y=X^2 graph plotted,
solve the equation then put in arx function (cal "sqrt(Y)")
 
> invoke (c:test2)
> pick origin lowest
> input height
 

[code](defun c:test2 ( /  p h X Y)(if (and (setq p (getpoint "\nPick origin parabola.. ")) (setq h (getreal "\nEnter height from origin.. ")) )     (progn(setq X (car p) Y (abs h) Y ([color="blue"]cal "[color="red"]sqrt(Y)"));
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-11 09:17 , Processed in 0.746985 second(s), 75 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表