Author Topic: Polyline point  (Read 12212 times)

0 Members and 1 Guest are viewing this topic.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Polyline point
« Reply #15 on: July 05, 2012, 10:05:54 AM »
way of analyzing the geometry:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ e p pt)
  2.   (cond ((not (and (setq e (entsel "\nPick lwpolyline segment: ")) (= (cdadr (entget (car e))) "LWPOLYLINE"))
  3.          )
  4.          (princ "\n This is not lwpolyline!")
  5.         )
  6.                  (vlax-curve-getPointAtParam (car e) (setq p (fix (vlax-curve-getparamatpoint (car e) pt))))
  7.                  pt
  8.                  (vlax-curve-getPointAtParam (car e) (1+ p))
  9.          )
  10.          (princ "\n This is arc segment.")
  11.         )
  12.         ((princ "\n This is line segment."))
  13.   )
  14. )
« Last Edit: July 06, 2012, 12:03:05 AM by ElpanovEvgeniy »

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Polyline point
« Reply #16 on: July 05, 2012, 10:47:33 AM »
@irneb
how can I start your finally function ...
My previous post shows the new versions of my functions as I've linked to in reply #3. Sorry I should've been more clear. They're intended for use as a library of functions, not as commands.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Polyline point
« Reply #17 on: July 10, 2012, 08:06:21 AM »
Now Iīve studied little bit more. I know how can I get bulge and segments and properties from picked polylines
I understand angle = 4 * (arctan bulge)

probl 1)
But I donīt understand why I canīt get correctly radius. Formel is all rigtht

probl 2)
I want trim arc segement in 3 parts to can calculate 2 points on arc

In the end I want export alle Polylinevertex and arc-points in a txt-fil

Iīm beginner with vlisp, so Iīm little confuse with all your visual-functions.
So I try it only with Lisp

Code: [Select]
;; get bulge radius by Juergen Menzi

(defun get-radii  (p1 p2 bulge)
  (abs (/ (distance p1 p2) 2 (sin (/ (* 4 (atan (abs bulge))) 2)))))



;;; report lwpolyline vertex and bulge by Lee-Mac

(defun _lwvertices ( e )
  (if (setq e (member (assoc 10 e) e))
    (cons
      (cons
(cdr (assoc 10 e))
(cdr (assoc 42 e))
)
      (_lwvertices (cdr e))
      )
    )
  )

(defun c:t ( / ptbu i )
  (setq i 0
iL 0
iA 0)
  (if (setq ptbu (_lwvertices (entget (car (entsel "\nSelect Polyline! "))))
    ptbu (cdr (reverse ptbu))
    )
    (repeat (length ptbu)
      (cond
((equal 0.0 (cdr (nth i ptbu)))
(setq iL (1+ iL))
)
((not (equal 0.0 (setq bulge (cdr (nth i ptbu)))))
(setq p1 (car (nth i ptbu)))
(setq p2 (car (nth (1+ i) ptbu)))
(setq rad (get-radii p1 p2 bulge))
(setq iA (1+ iA))
)
)
      (setq i (1+ i))
      )
    )
  (princ (strcat "\nPolyline has\n" (itoa iL) " Line segments and"
"\n" (itoa iA) " Arc segements"))

  (princ)
  )

   


Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Polyline point
« Reply #18 on: July 10, 2012, 10:33:40 AM »
Your thread has inspired me to write this program, you may find it useful in your studies  :-)

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: Polyline point
« Reply #19 on: July 10, 2012, 03:01:05 PM »
This version uses vlax-curve to get points on arcs. No math required...:)
Of course, you can export coordinates instead drawing points.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / ss l e d z p n)
  2.   (if
  3.     (and
  4.       (setq ss (ssget ":E:S" '((0 . "lwpolyline"))))
  5.       (setq n (getint "\nArc divisions:"))
  6.       (> n 1)
  7.       )
  8.     (progn
  9.       (setq e (ssname ss 0)
  10.             z (cdr (assoc 38 (entget e)))
  11.             l (vl-remove-if-not '(lambda (x) (member (car x) '(10 42))) (entget e))
  12.             d (mapcar '(lambda (x) (/ x 1.0 n)) (repeat (1- n) (setq d (cons (1- (cond ((car d)) (n))) d))))
  13.             )
  14.       (while l
  15.         (setq p (trans (list (cadar l) (caddar l) z) e 0))
  16.         (entmake (list '(0 . "POINT") (cons 10 p)))
  17.         (if (/= 0.0 (cdadr l))
  18.           (foreach x d
  19.             (entmake (list '(0 . "POINT") (cons 10 (vlax-curve-GetPointAtParam e (+ x (vlax-curve-GetParamAtPoint e p))))))
  20.             )
  21.           )
  22.         (setq l (cddr l))
  23.         )
  24.       )
  25.     )
  26.   (princ)
  27.   )

ribarm

  • Gator
  • Posts: 3257
  • Marko Ribar, architect
Re: Polyline point
« Reply #20 on: July 10, 2012, 05:41:03 PM »
Here is quick handy tool in case you didn't get formula for radius of pline arc... Works only on arc segments of heavy or lightweight 2d polyline...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:plarcdata ( / e ent pt p p1 p2 bulge rad cen )
  2.   (setq e (entsel "\nPick arc on polyline to calculate its data"))
  3.   (setq ent (car e) pt (cadr e))
  4.   (setq bulge (vla-getbulge (vlax-ename->vla-object ent) (float (fix (vlax-curve-getparamatpoint ent p)))))
  5.   (setq rad (/ (distance p1 p2) (* 2 (sin (* 2 (atan bulge))))))
  6.   (setq cen (polar p1 (+ (angle p1 p2) (- (/ pi 2.0) (* 2 (atan bulge)))) rad))
  7.   (alert (strcat "\nRadius of arc is : " (rtos (abs rad)) "\nCenter of arc is : " (rtos (car cen)) "," (rtos (cadr cen)) "," (rtos (caddr cen)) "\nAngle of arc is : " (rtos (cvunit (* 4 (atan bulge)) "radians" "degrees"))))
  8.   (princ)
  9. )
  10.  

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Polyline point
« Reply #21 on: July 11, 2012, 03:57:39 AM »
Thanks so much for different proposals. I try it to build in my function. But it doesnīt work somtimes correctly if I have a polyline begins with line-arc-lin entities. Know somebody a better way as calc angle in circlepoint c to p1(tangent) and p2(tangent)
Hopefully you understand what I mean
Code: [Select]
(defun c:t ( /
;;;     l i
    )
  (setq i 0
iL 0
iA 0)
  (if (setq l (LM:LWVertices (entget (car (entsel "\nSelect Polyline! ")))))
    (repeat (length l)
      (cond
((equal 0.0 (cdr (assoc 42 (nth i l))))
(setq iL (1+ iL))
(entmake (list '(0 . "POINT") (cons 10 (cdar (nth i l)))))
)
((not
   (equal 0.0
  (setq b (cdr (assoc 42 (nth i l))))
  )
   )
(setq p1 (cdr (assoc 10 (nth i l))))
(entmake (list '(0 . "POINT") (assoc 10 (nth i l))))
(setq p2 (cdr (assoc 10 (nth (1+ i) l))))
(setq rad (LM:BulgeRadius p1 p2 b))
(setq c (LM:BulgeCentre p1 p2 b))
(setq iA (1+ iA))
(if
   (not
     (equal 0.0 c))
   (progn
     (setq a (- (angle c p1) (angle c p2)))
     (setq ap1 (polar c (- (angle c p1) (/ a 3)) (distance c p1)))
     (setq ap2 (polar c (- (angle c ap1) (/ a 3)) (distance c p1)))
     (entmake (list '(0 . "POINT") (cons 10 ap1)))
     (entmake (list '(0 . "POINT") (cons 10 ap2)))
     )
   )
)
)
      (setq i (1+ i))
      )
    )
  (princ (strcat "\nPolyline has\n" (itoa (1- iL)) " Line segments and"
"\n" (itoa iA) " Arc segements"))

  (princ)
  )
« Last Edit: July 11, 2012, 05:49:12 AM by cadplayer »

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Polyline point
« Reply #22 on: July 11, 2012, 04:40:19 AM »
Code: [Select]
(if
   (not
     (equal 0.0 c))
   (progn
     (setq a (- (angle c p1) (angle c p2)))
     (setq ap1 (polar c (- (angle c p1) (/ a 3)) (distance c p1)))
     (setq ap2 (polar c (- (angle c ap1) (/ a 3)) (distance c p1)))

means if it haves a centerpoint from arcentity calculate angle between lines c,p1 and c,p2. (p1 and p2 are start and endpoint of arc.)

In the case I have dubble arc in a polyline it doenīt works  idea, because I miss p2

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Polyline point
« Reply #23 on: July 11, 2012, 05:47:46 AM »
...next
« Last Edit: July 13, 2012, 01:54:16 AM by cadplayer »

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Polyline point
« Reply #24 on: July 13, 2012, 01:53:52 AM »
Can you help me. I would like have all radius of polyline which have only 3 arc segments

(setq l (LM:LWVertices (entget (car (entsel "\nSelect Polyline! "))))) ; I get all vertex but not the last one

list l looks like so...
(((10 -86.1312 67.2658) (40 . 0.0) (41 . 0.0) (42 . 0.677818))   ((10 -80.777 71.06) (40 . 0.0) (41 . 0.0) (42 . 0.348949))  ((10 -85.2064 74.5137) (40 . 0.0) (41 . 0.0) (42 . 2.38414)))
But here I miss endvertex of polyline

Thats why I have a problem: first two arcs calculates but the last canīt because VAR p2 is nil. How can I say in program the last vertex is end of polyline ?

(setq b (cdr (assoc 42 (nth i l))))
        (setq p1 (cdr (assoc 10 (nth i l))))
        (setq p2 (cdr (assoc 10 (nth (1+ i) l))))
        (setq rad (LM:BulgeRadius p1 p2 b))
        (setq c (LM:BulgeCentre p1 p2 b))
       )
« Last Edit: July 13, 2012, 04:08:36 AM by cadplayer »