sadefa 发表于 2022-7-5 20:21:42

lisp多段线

大家好,
 
我对论坛和lisp编程都很陌生。我已经写了一个小的lisp程序,将帮助我的OHTL线的设计。我想要实现的是一条抛物线。已知x坐标-相距0.5m,但必须计算y坐标。我要找的是一个可以将顶点添加到多段线的脚本(X坐标已知,Y是为每个循环计算的)。乘积应该是具有顶点的多段线。它应该是这样的:

motee-z 发表于 2022-7-5 20:25:52

抛物线必须有常数,所以必须有常数

hanhphuc 发表于 2022-7-5 20:31:03

 
欢迎来到Cadtutor
 
抛物线试验。lsp V1.2:对称选项:t/nil
V1.1:将子函数包装在C中:测试
 

(defun c:test (/ user p symmetric *equation*) ; localize if no user prompt *OPTIONAL

;due to the sub-function is global variable, so prefix hp: is just making it unique name to avoid conflict
(defun hp:graph        (str i dist pt / X lst)
;;;hanhphuc 25.12.2014 merry Xmas
(or cal (arxload "geomcal"))
(if (and str i dist pt)
   (progn (setq X 0.0 ) ;_ end of setq
   (repeat (1+ (abs (fix (/ dist i))))
   (setq lst (cons (list (+ (car pt) X) (+ (cadr pt) (cal str))) lst)
           X   (+ X i)
           ) ;_ end of setq
   ) ;_ end of repeat
   (entmakex (vl-list* '(0 . "LWPOLYLINE")
                     '(100 . "AcDbEntity")
                     '(100 . "AcDbPolyline")
                     '(70 . 0)
                     (cons 90 (length lst))
                     (mapcar ''((x) (cons 10 (trans x 1 0))) lst)
                     ) ;_ end of vl-list*
             ) ;_ end of entmakex
   ) ;_ end of progn
   ) ;_ end of if
(princ)
) ;_ end of defun

(setq symmetric t) ; <--- t / nil : user setting v1.2
(or *equation* (setq *equation* "X^2")) ;<-- default example

;*OPTIONAL: un-commented after this paragraph which prompt for user input
;(setq        user           (getstring (strcat "\nKey your equation, Y= " *equation* " ? "))
;        *equation* (if (= user "")
;                     *equation*
;                     user
;                     ) ;_ end of if
;        ) ;_ end of setq
(if (setq p (getpoint "\nPick point.. "))
(foreach x '(0.5 -0.5)   ; <-- increment
   (hp:graph

(if symmetric ; v1.2

(if (minusp x)
        ((lambda(str)(last
          (mapcar ''((a b) (setq str (vl-string-translate a b str))) '("+" "-" "?") '("?" "+" "-"))
          ) ;_ end of last
          ) *equation* )
        *equation*
        ) ;_ end of if

*equation*)

      x
      50.0            ; <-- Distance
      p)
   )
   ) ;_ end of if
(princ)
) ;_ end of defun

sadefa 发表于 2022-7-5 20:31:52

版本检查
 


;example: if you have a constant =0.1 , just add in the default

(defun c:test (/ user p *equation*) ; localize if no user prompt

...
...
...

(or *equation* (setq *equation* "X^2*0.1")) ; add constant *0.1
...
...

GP_ 发表于 2022-7-5 20:36:20

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

hanhphuc 发表于 2022-7-5 20:38:19

试试这个
(vl-load-com)

(if ((lambda (vrsn)
(cond
      ((vl-string-search "R17.2" vrsn) (setq appstr "6.0")) ;09
      ((vl-string-search "R18.0" vrsn) (setq appstr "7.0")) ;10
      ((vl-string-search "R18.1" vrsn) (setq appstr "8.0")) ;11
      ((vl-string-search "R18.2" vrsn) (setq appstr "9.0")) ;12 ?
      ((vl-string-search "R19.0" vrsn) (setq appstr "10.0")) ;13
      ((alert "This version of C3D not supported!"))
       )
)
      (vlax-product-key)
   )

BIGAL 发表于 2022-7-5 20:43:32

感谢ymg3和GP_添加此信息

sadefa 发表于 2022-7-5 20:45:09

motee-z 发表于 2022-7-5 20:47:19

try this

;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" "(""

hanhphuc 发表于 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
 

(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 (cal "sqrt(Y)"));
页: [1] 2
查看完整版本: lisp多段线