Jump to content

lisp polyline


sadefa

Recommended Posts

Hello to all of you,

 

I am quite new to the forum and also to the lisp programing. I have written a small lisp program that will help me for the OHTL lines design. What I would like to do achieve is a parabola. The x coordinates are known - 0,5m apart, but the y coordinates have to be calculated. What I am looking for is an script that can add up vertexes to a polyline (the X coordinate is known and the Y is calculated for every single loop). The product should be a polyline with vertexes. It should look like this:

1yabz7.jpg

Edited by sadefa
Link to comment
Share on other sites

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • ymg3

    6

  • motee-z

    5

  • hanhphuc

    5

  • sadefa

    5

Top Posters In This Topic

Posted Images

Hello to all of you,

 

I am quite new to the forum and also to the lisp programing. I have written a small lisp program that will help me for the OHTL lines design. What I would like to do achieve is a parabola. The x coordinates are known - 0,5m apart, but the y coordinates have to be calculated. What I am looking for is an script that can add up vertexes to a polyline (the X coordinate is known and the Y is calculated for every single loop). The product should be a polyline with vertexes. It should look like this:

 

welcome to Cadtutor :)

 

parabola test.lsp V1.2: symmetric option: t/nil

V1.1: wrap the sub-function in C:TEST

 

(defun c:test (/ user p [b]symmetric[/b] [color="red"]*equation*[/color]) ; localize if no user prompt *OPTIONAL

;due to the sub-function is global variable, so prefix [color="red"]hp:[/color] is just making it unique name to avoid conflict
(defun [b]hp:graph[/b]	(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

[b][color="red"](setq symmetric [color="blue"]t[/color])[/color][/b] ; [color="blue"]<--- t / nil : user setting v1.2[/color] 
(or *equation* (setq *equation* [color="red"]"[b]X^2[/b]"[/color])) ;[color="blue"]<-- default example[/color]
 [color="red"]
;*[u]OPTIONAL: un-commented after this paragraph which prompt for user input[/u]
;(setq	user	   (getstring (strcat "\nKey your equation, Y= " *equation* " ? "))
;	*equation* (if (= user "")
;		     *equation*
;		     user
;		     ) ;_ end of if
;	) ;_ end of setq[/color]
 (if (setq p (getpoint "\nPick point.. "))
(foreach x '([color="red"][b]0.5 -0.5[/b][/color])     ;[color="blue"] <-- increment[/color]
   ([b]hp:graph[/b] 

[b][color="red"] (if symmetric [color="gray"]; v1.2[/color]

(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*)[/color][/b]

      x  
      [color="red"][b]50.0[/b][/color] 	   ;[color="blue"] <-- Distance[/color]
      p)
     )
   ) ;_ end of if
 (princ)
 ) ;_ end of defun

 

info: geomcal.arx all version, whereas .crx for v2013** Thanks GP

Edited by hanhphuc
updated: v1.2 symmetrical option
Link to comment
Share on other sites

Hi hanhphuc,

 

thank you for your help.

The y value is constant*x^2. The constant is calculated in accordance with input data, provided by user. This means that the equitation prompt might be skipped.

 

The problem is that I get an error - Pick point.. ; error: no function definition: HP:GRAPH

I still cannot get how exactly it works, as I expected an pline command with set of points with x and y coordinates provided as function argument ...

 

Please help me resolve this error message.

Many thanks in advance.

Link to comment
Share on other sites

(or cal (arxload "geomcal")) works on all version, from v2013 it has become geomcal.crx

 

Thank you for pointing, GP :)

greetings :beer:

 

Hi hanhphuc,

 

thank you for your help.

The y value is constant*x^2. The constant is calculated in accordance with input data, provided by user. This means that the equitation prompt might be skipped.

> In fact sub-function is not necessary but due to your initial post did not provide the equation / constant.

> however , i keep the sub-function which user may modify for different equation

 

The problem is that I get an error - Pick point.. ; error: no function definition: HP:GRAPH

I still cannot get how exactly it works, as I expected an pline command with set of points with x and y coordinates provided as function argument ...

 

> hp:graph is a sub-function, so should be loaded with c:test

 

Please help me resolve this error message.

Many thanks in advance.

 

updated v1.1 post#3

 


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

(defun c:test (/ user p [color="red"]*equation*[/color]) ; localize if no user prompt

...
...
...

(or *equation* (setq *equation* "[b]X^2[/b][color="red"]*0.1[/color]")) ; add constant *0.1
...
...

Edited by hanhphuc
Link to comment
Share on other sites

A version check

 

(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)
     ) 

Link to comment
Share on other sites

hanhphuc, thank you very much!

This works perfect. I have edited the script and added the constant, which comes from previous calculations.

 

Is there any way to make the parabola to be placed on screen at the start point (for e.g. the most top left point). And one more thing - the both ends are not always equal - can you please add additional condition for the parabola to start from certain vertical coordinate and to end at another level?

Honestly - I have no idea how to achieve this.

Link to comment
Share on other sites

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" "(""<" (rtos y3 2 2)"):")))
(if hmnew(setq y3 hmnew))
 (if(> y3 hm)
   (alert"reduce height please because it is higher than smaller column")
   )
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;(setq y3(getreal "\n enter minimum height must less than smaller column height<minimum Height( Hm ) :"))
 (setq y1(abs(-(-(cadr p1)(cadr p1d))y3)))
 (setq y2(abs(-(-(cadr p2)(cadr p2d))y3)))
 (setq L(abs(-(car p2)(car p1))))
 
 ;(setq x1(abs(/(* 2 L y1 y1)(* 2(+(* y2 y2)(* y1 y1))))))
 
 (setq A(* 2(- y2 y1)))
 (if(= 0 A)
   (setq x1(/ L 2))
   )
 (if(/= 0 A)
   (progn
 (setq B(* 4 y1 L))
 (setq c(* -2 y1 L L))
 (setq delta(-(* B B)(* 4 A C)))
 (setq jazerdelta(sqrt delta))
 (setq x1(abs(/(- jazerdelta B)(* 2 A))))
 (setq x2(abs(/(* -1(+ b jazerdelta))(* 2 A))))
 )
   )
 (setq p3(list(+(car p1)x1)(+(cadr p1d)y3)))
 (setq osmd(getvar"osmode"))
 (setvar"osmode"0)
 (command "point" p3)
 (command"_circle"p3 1)
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (setq f(/ y1(* x1 x1)))
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (setq st2(list(car p2)(cadr p3)))
 (setq st3(list(car p3)(cadr p1)))
 (command "ucs" "New" "3p"  p3 st2 st3 )
 (setq ptlst'())
 (setq k (* -1 x1))  
(while (<= k (- l x1))

(progn
  (setq y(* f k k))
  (setq px(list k y))
  (setq ptlst(cons px ptlst))
  (setq k (+ 1 k))
  )
 )
 ;(SETQ ptlst(REVERSE ptlst))
 (setq endp(list(- L x1)y2))
 (setq ptlst(cons endp ptlst))
 (setq clyr(getvar"clayer"))
 (command "layer" "make" "Line" "")
 (command "layer" "c" "2" "Line" "")
 (command "color" "bylayer")
 (command "__pline")
                        (foreach
                               pt
                                 ptlst
                              (command "_non" pt))
                        (command )
 (setvar"osmode"osmd)
 (command"ucs" "world")
 (setvar"clayer"clyr)
)

Link to comment
Share on other sites

the both ends are not always equal -

 

> example: Y=(X+0.2)^2 is not equal try calculate manually -X & +X

> i'll update symmetrical option v1.2 soon

 

can you please add additional condition for the parabola to start from certain vertical coordinate and to end at another level?

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 ([color="blue"][b]cal[/b][/color] "[color="red"][b]sqrt(Y)[/b][/color]")); <--- [color="blue"]X= sqrt(Y) ,derived from[/color] [color="red"][b]Y=X^2[/b][/color]
(entmakex (list'(0 . "CIRCLE") '(40 . 1.)'(62 . 1)
(cons 10 (list (+ Y X) ((if (minusp h)- +)(cadr p) (abs h)) )))))
)
(princ)
 )

* i might be wrong, please get math expert to assist :)

 

A version check

"R17.0" not supported?

thanks BIGAL

greetings :beer:

Edited by hanhphuc
Link to comment
Share on other sites

try this

;writen by eng motee malazi,syria,latakia,date:10/2013

hi motee-z, interesting :) the circle mark at the lowest point?

so is equation applicable for road design?

Link to comment
Share on other sites

hi hanhphuc

the routine written for electric cable path between 2 pole which represent a parabola and the circle shows the lowest point in the cable

Link to comment
Share on other sites

hi hanphuc

the routine written for electric cable path between 2 pole and the circle shows the lowest point in the cable

yeah motee-z thanks for sharing :thumbsup:

 

hanphuc,

 

In road design, Vertical curves are Parabolas.

ymg

 

thanks ymg good knowledge:)

Link to comment
Share on other sites

motee-z,

 

What you are looking for is a CATENARY,

not a parabola.

 

Although a parabola is not very far and is sometimes used

as an approximation.

 

ymg

Edited by ymg3
Link to comment
Share on other sites

i am civil engineer but electrical engineer inform me that the path of cable of energy power between 2 pole is a parabola as mentioned in the routine

Link to comment
Share on other sites

motee-z,

 

I am sorry but it really is a catenary and dependant on the tension of the cable.

This defines by the unit weight of the conductor and wind loading.

 

Since the sag involved are relatively small, a parabola is actually quite close.

 

Alas you are not alone in doing this mistakes, even Galileo did it,

 

see: http://en.wikipedia.org/wiki/Catenary

 

That the curve followed by a chain is not a parabola was proven by Joachim Jungius (1587–1657)

 

ymg

Link to comment
Share on other sites

motee-z,

 

What you are looking for is a CATENARY,

not a parabola.

 

Although a parabola is not very far and is sometimes used

as an approximation.

 

ymg

 

1+

 

catenaria.jpg

 

 

 

edit: oops

ymg, two minutes later... :)

Link to comment
Share on other sites

motee-z,

 

Here's a routine I had modified a while ago

that will draw a catenary.

 

However no calculation for windload, temperature

or ice load.

 

; catenary.lsp   by ymg                                                       ;
; Modified from a program by Hector  Monroy, M.S. Civil Eng.                  ;

(defun c:catenary ( / t0 p p1 p2 x1 x2 y1 y2 h c l a v f xv yv pl x)
  (setq t0 (getreal "\nTension in the cable(In unit of weight):")
         p (getreal "\nCable weight per unit length:")
        p1 (getpoint "\nInitial point:")
        p2 (getpoint p1 "\nEnd point:")	  
        x1 (car p1)
        x2 (car p2)
  i (if (< x1 x2) 1.0 -1.0)
        y1 (cadr p1)
        y2 (cadr p2)
         h (- y1 y2)
         c (/ t0 p)
         l ( - x2 x1)
         a (/ h (* 2 c (sinh (/ l (* 2 c)))))
         v (+ (/ l 2) (* c (arcsinh a)))
         f (* c (- (cosh (/ v c)) 1))
        xv (+ x1 v)
        yv (- y1 f)
 pl (list p2)
  x x2
  )
  (while (if (< x1 x2) (> x x1) (< x x1))
     (setq pl (cons (list x (+ (* c (- (cosh (/ (- x xv) c)) 1)) yv)) pl)
            x (- x i)
     )
  )
  (setq pl (cons p1 pl))
  (mk_lwp pl)
)


(defun cosh (a) (/ (+ (exp a)(exp (- a))) 2))
(defun sinh (a) (/ (- (exp a)(exp (- a))) 2))
(defun arcsinh (a)(log (+ a (sqrt (+ 1.0 (* a a))))))

;;******************************************************************************;
;; mk_lwp    by Alan J Thompson                                                 ;
;; Argument: pl, A list of points (2d or 3d)                                    ;
;; Create an LWPolyline at Elevation 0, on Current Layer.                       ;
;; Return: Polyline Object                                                      ;
;;******************************************************************************;

(defun mk_lwp (pl)
   (vlax-ename->vla-object
     (entmakex
        (append (list '(0 . "LWPOLYLINE")
                      '(100 . "AcDbEntity")
                      '(100 . "AcDbPolyline")
                       (cons 90 (length pl))
                       '(70 . 0)
                )
                (mapcar '(lambda (p) (cons 10 (trans (list (car p) (cadr p)) 1 0))) pl)
       )
     )
   )
)

Edited by ymg3
To work left or right
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...