Author Topic: Draw perpendicular line both side from point on curve  (Read 3562 times)

0 Members and 1 Guest are viewing this topic.

kruuger

  • Swamp Rat
  • Posts: 638
Draw perpendicular line both side from point on curve
« on: March 17, 2011, 03:15:37 AM »
Hello Everyone,

Can some give me some tips how to draw two line like described in subject (please see also picture for clarification).
I guess my answer is here:
http://www.theswamp.org/index.php?topic=32789.0
But it is hard to extract what i want (to much information for me now  :-()

Thanks
kruuger


Stefan

  • Bull Frog
  • Posts: 320
  • The most I miss IRL is the Undo button
Re: Draw perpendicular line both side from point on curve
« Reply #1 on: March 17, 2011, 05:25:23 AM »
Some start point

Code: [Select]
  (setq dist1 (getreal)
dist2 (getreal))
  (setq enti           (entsel)
curve          (vlax-ename->vla-object (car enti))
point_on_curve (vlax-curve-getClosestPointTo curve (cadr enti))
param          (vlax-curve-getParamAtPoint curve point_on_curve)
tangential_dir (vlax-curve-getFirstDeriv curve param)
perp_angle1    (+ (angle '(0 0) tangential_dir) (* 0.5 pi))
perp_angle2    (+ perp_angle1 pi)
your_point_1   (polar point_on_curve perp_angle1 dist1)
your_point_2   (polar point_on_curve perp_angle2 dist2)
)

kruuger

  • Swamp Rat
  • Posts: 638
Re: Draw perpendicular line both side from point on curve
« Reply #2 on: March 17, 2011, 05:51:40 AM »
Thank you VERY VERY MUCH phanaem . Good start for me with "curve"   :-)
Code: [Select]
(defun C:P2P (/ dist1 dist2 enti curve point_on_curve
                param tangential_dir perp_angle1 perp_angle2
                your_point_1 your_point_2)
  (setq dist1 (getreal "\nFirst distance: ")
        dist2 (getreal "\nSecond distance: ")
  )
  (setq enti (entsel "\nSelect object: ")
        curve          (vlax-ename->vla-object (car enti))
        point_on_curve (vlax-curve-getClosestPointTo curve (cadr enti))
        param          (vlax-curve-getParamAtPoint curve point_on_curve)
        tangential_dir (vlax-curve-getFirstDeriv curve param)
        perp_angle1    (+ (angle '(0 0) tangential_dir) (* 0.5 pi))
        perp_angle2    (+ perp_angle1 pi)
        your_point_1   (polar point_on_curve perp_angle1 dist1)
        your_point_2   (polar point_on_curve perp_angle2 dist2)
  )
  (foreach % (list your_point_1 your_point_2)
    (entmakex
      (list
        (cons 0 "LINE")
        (cons 10 point_on_curve)
        (cons 11 %)
      )
    )
  )
  (princ)
)

hava a good day
kruuger

EDIT: awesome variable name. very helpfull
« Last Edit: March 17, 2011, 06:21:36 AM by kruuger »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Draw perpendicular line both side from point on curve
« Reply #3 on: March 17, 2011, 06:17:10 AM »
phanaem,
excellent reply !!
 
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Stefan

  • Bull Frog
  • Posts: 320
  • The most I miss IRL is the Undo button
Re: Draw perpendicular line both side from point on curve
« Reply #4 on: March 17, 2011, 06:49:08 AM »
kruuger, I am glad it helps you.

Thank you Kerry.

ScottMC

  • Newt
  • Posts: 198
Re: Draw perpendicular line both side from point on curve
« Reply #5 on: November 03, 2023, 10:31:16 PM »
Sorry this to be so old, it was a worthwhile learner though.
Just wanted to include re.usability of vars. Comments Please!
Code: [Select]
(defun c:p2p (/ *error*
              enti    curve     point_on_curve wdst wdlt
              param      tangential_dir perp_angle1
              perp_angle2    your_point_1   your_point_2
             ) ;; https://www.theswamp.org/index.php?topic=37522.msg425311#msg425311

  (defun *error* ( msg )
    (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
    (if qaf (setvar 'qaflags qaf))
    (if msg (prompt msg))
          (progn
          (setvar 'osmode snw)
             (setvar 'cmdecho 1)   
          )
    (princ)
  )
 
(setq snw (getvar 'osmode))
(setvar 'osmode (boole 6 (getvar 'osmode) 512)) ;; add nearest osnap to existing

;; first perp line
      (if dst1 ;; set default if first run [nil]
           (setq wdst 1.0)
      )
  (setq dst1 (getdist (strcat "\n First/Inner Distance: < was: " (rtos wdst 2 3)" > "))) ;; get offset, else <enter> for 1.0
       (if dst1                   ;; test for new entry
          (setq wdst 1.0) ;; if not new entry, use 1
          (setq dst1 wdst) ;; else use last/saved
          )
      (setq wdst dst1) ;; set next use prompt
     
 ;; second perp line
          (if dst2             ;; set default if first run [nil]
               (setq wdlt 1.0)
          )
    (setq dst2 (getdist (strcat "\n Second/Outer Distance: < was: " (rtos wdlt 2 3)" > "))) ;; get offset, else <enter> for 1.0
              (if dst2                   ;; test for new entry
                (setq wdlt 1.0) ;; if not new entry, use 1
                 (setq dst2 wdlt) ;; else use last/saved
                )
                (setq wdlt dst2) ;; set next use prompt
       
          (if (and          ;; both 0 quit
            (= dst1 0)
            (= dst2 0)
            )
            (quit)
            )

          (princ (strcat " 1st: " (rtos dst1 2 3) " | 2nd: " (rtos dst2 2 3)))
 (while
     (setq pt (getpoint "\n Select object: " )
              enti (nentselp pt) ;
            curve          (vlax-ename->vla-object (car enti))
            point_on_curve (vlax-curve-getClosestPointTo curve (cadr enti))
            param          (vlax-curve-getParamAtPoint curve point_on_curve)
            tangential_dir (vlax-curve-getFirstDeriv curve param)
            perp_angle1    (+ (angle '(0 0) tangential_dir) (* 0.5 pi))
            perp_angle2    (+ perp_angle1 pi)
            your_point_1   (polar point_on_curve perp_angle1 dst1)
            your_point_2   (polar point_on_curve perp_angle2 dst2)
      ) ;_ end of setq
  (foreach % (list your_point_1 your_point_2)
    (entmakex
      (list
        (cons 0 "LINE")
        (cons 10 point_on_curve)
        (cons 11 %)
      ) ;_ end of list
    ) ;_ end of entmakex
  ) ;_ end of foreach
 ) ;_ end of  while
 (setvar 'osmode snw) ;; restore osmode
 (*error* nil)
  (princ)
) ;_ end of defun
« Last Edit: November 03, 2023, 11:10:38 PM by ScottMC »

ScottMC

  • Newt
  • Posts: 198
Re: Draw perpendicular line both side from point on curve
« Reply #6 on: November 05, 2023, 09:06:23 PM »
OOPs - correction on variables from 'was'
     Any suggestions greatly appreciated.

Code: [Select]
(defun c:p2p (/ *error* ;; https://www.theswamp.org/index.php?topic=37522.msg425311#msg425311
              enti    curve     point_on_curve
              param      tangential_dir perp_angle1
              perp_angle2    your_point_1   your_point_2
             ) ;;  wdst wdlt <'was' entries for next use

  (defun *error* ( msg )
    (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
    (if qaf (setvar 'qaflags qaf))
    (if msg (prompt msg))
          (progn
          (setvar 'osmode snw)
             (setvar 'cmdecho 1)   
          )
    (princ)
  )
 
(setq snw (getvar 'osmode))
(setvar 'osmode (boole 6 (getvar 'osmode) 512)) ;; 'just add nea'

;; first perp line
      (if (= wdst nil) ;; set default if first run [nil]
           (setq wdst 1.0)
      )
  (setq dst1 (getdist (strcat "\n First/Inner Distance: < was: " (rtos wdst 2 3)" > "))) ;; get offset, else <enter> for 1.0
       (if (= dst1 nil)                   ;; test for new entry
            (setq dst1 wdst) ;; if not new entry, use previous
          )
      (setq wdst dst1) ;; set next use prompt
     
 ;; second perp line
          (if (= wdlt nil)             ;; set default if first run [nil]
               (setq wdlt 1.0)
          )
    (setq dst2 (getdist (strcat "\n Second/Outer Distance: < was: " (rtos wdlt 2 3)" > "))) ;; get offset, else <enter> for 1.0
              (if (= dst2 nil)                   ;; test for new entry
                (setq dst2 wdlt) ;; if not new entry, use previous
                )
           (setq wdlt dst2) ;; set next use prompt
       
          (if (and          ;; both 0.0 ?  quit
            (= dst1 0)
            (= dst2 0)
            )
            (quit)
            )

          (princ (strcat " 1st: " (rtos dst1 2 3) " | 2nd: " (rtos dst2 2 3))) ;; show entries
 (while
     (setq pt (getpoint "\n Select object: " )
              enti (nentselp pt) ;
            curve          (vlax-ename->vla-object (car enti))
            point_on_curve (vlax-curve-getClosestPointTo curve (cadr enti))
            param          (vlax-curve-getParamAtPoint curve point_on_curve)
            tangential_dir (vlax-curve-getFirstDeriv curve param)
            perp_angle1    (+ (angle '(0 0) tangential_dir) (* 0.5 pi))
            perp_angle2    (+ perp_angle1 pi)
            your_point_1   (polar point_on_curve perp_angle1 dst1)
            your_point_2   (polar point_on_curve perp_angle2 dst2)
      ) ;_ end of setq
  (foreach % (list your_point_1 your_point_2)
    (entmakex
      (list
        (cons 0 "LINE")
        (cons 10 point_on_curve)
        (cons 11 %)
      ) ;_ end of list
    ) ;_ end of entmakex
  ) ;_ end of foreach
 ) ;_ end of  while
 (setvar 'osmode snw)
 (*error* nil)
  (princ)
) ;_ end of defun

« Last Edit: November 07, 2023, 10:43:04 PM by ScottMC »