Author Topic: Line perpendicular to other line  (Read 2910 times)

0 Members and 1 Guest are viewing this topic.

carmi

  • Newt
  • Posts: 27
Line perpendicular to other line
« on: March 09, 2016, 01:12:10 PM »
Hi all...
I have already seen other posts here but i can not find the solution to my problem.
From the midpoint of a line (line 1), i would like to draw a perpendicular line (line 2) extending from both sides for 50 cm (type a cross).
Can you help me?
Regards
Carmi



Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Line perpendicular to other line
« Reply #1 on: March 09, 2016, 01:16:20 PM »
Here is some pseudo-code for one possible method:
Code - Auto/Visual Lisp: [Select]
  1. (setq ang (angle <line-1-start> <line-1-end>)
  2.       mid (polar <line-1-start> ang (/ (distance <line-1-start> <line-1-end>) 2.0))
  3. )
  4. (command "_.line" "_non" (polar mid (+ ang (/ pi 2.0)) 50.0) "_non" (polar mid (- ang (/ pi 2.0)) 50.0) "")

carmi

  • Newt
  • Posts: 27
Re: Line perpendicular to other line
« Reply #2 on: March 09, 2016, 01:26:18 PM »
Here is some pseudo-code for one possible method:
Code - Auto/Visual Lisp: [Select]
  1. (setq ang (angle <line-1-start> <line-1-end>)
  2.       mid (polar <line-1-start> ang (/ (distance <line-1-start> <line-1-end>) 2.0))
  3. )
  4. (command "_.line" "_non" (polar mid (+ ang (/ pi 2.0)) 50.0) "_non" (polar mid (- ang (/ pi 2.0)) 50.0) "")

Its perfect  :wink:
Thank you

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Line perpendicular to other line
« Reply #3 on: March 09, 2016, 01:30:07 PM »
You're welcome!

carmi

  • Newt
  • Posts: 27
Re: Line perpendicular to other line
« Reply #4 on: March 11, 2016, 05:16:59 AM »
Hi again...
This lisp, thanks to part of your code and another code, draws a double line and a center line.

Code: [Select]
(defun c:porta(/ eao)
(setvar "blipmode" 0)
(if (not cwidth)
(setq cwidth 0.0)
)

(prompt (strcat "\n Width beetwin line <"(rtos cwidth) ">: "))
(setq tcwidth (getreal))
(if tcwidth
(setq cwidth tcwidth)
)

(setq pt1 (getpoint "\nStart point... "))
(if pt1
(setq pt2 (getpoint pt1 "\nTo point... "))
)
(setq threshold 1
segment 0
oang nil
ofrad (getvar "filletrad")
)
(if (>= cwidth threshold)
(setq inrad (* 1.0 cwidth) outrad (* 2.0 cwidth))
)

(setq a (angle pt1 pt2)
1o1 (polar pt1 (+ a (/ pi 2.0)) (/ cwidth 2.0))
1o2 (polar pt2 (+ a (/ pi 2.0)) (/ cwidth 2.0))
ro1 (polar pt1 (- a (/ pi 2.0)) (/ cwidth 2.0))
ro2 (polar pt2 (- a (/ pi 2.0)) (/ cwidth 2.0))
)
(if (> segment 0)
(setq eao ea ebo eb)
(setq dimpt (polar pt1 (+ a (/ pi 2.0))(+ (/ cwidth 2.0) 1.0)))
)
(command "line" 1o1 1o2 "")
(setq ea (entlast))
(command "line" ro1 ro2 "")
(setq eb (entlast))

(if (and (> segment 0)(/= a oang)(/= pi (abs (- a oang))))
(progn
(setq xa (- oang a))
(if (or (<= xa (* -1.0 pi))(and (> xa 0)(< xa pi)))
(setq ra outrad
rb inrad
dimpt (polar pt1 (+ a (/ pi 2.0)) (+ (/ cwidth 2.0) 1.0)))
(setq ra inrad
rb outrad
dimpt (polar pt1 (- a (/ pi 2.0)) (+ (/ cwidth 2.0) 1.0)))
)
(setq ss (ssadd ea))
(setq ss (ssadd eao ss))
(setvar "filletrad" ra)
(command "fillet" (ssname ss 0)(ssname ss 1))
(setq pp1 (cdr (assoc 10 (entget ea))))
(if (> segment 0)
(setq po1 (cdr (assoc 11 (entget eao))))
)
(setq ss (ssadd eb))
(setq ss (ssadd ebo ss))
(setvar "filletrad" rb)
(command "fillet" (ssname ss 0)(ssname ss 1))
)
)

(setq ang (angle pt1 pt2)
      mid (polar pt1 ang (/ (distance pt1 pt2) 2.0))
)
(command "_.line" "_non" (polar mid (+ ang (/ pi 2.0)) 0.3)) "_non" (polar mid (- ang (/ pi 2.0)) 0.3)) "")
)

I would like to change this code so as to give users two choices:
1. Enter the distance between the two lines directly in the command bar (as it is now);
2. Enter the distance between the two lines with the mouse by clicking two points.
Can you help me?
Regards
Carmi



Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Line perpendicular to other line
« Reply #5 on: March 11, 2016, 05:49:02 AM »
Change getreal to getdist

carmi

  • Newt
  • Posts: 27
Re: Line perpendicular to other line
« Reply #6 on: March 12, 2016, 03:16:15 PM »
Quote
(command "_.line" "_non" (polar mid (+ ang (/ pi 2.0)) 0.3)) "_non" (polar mid (- ang (/ pi 2.0)) 0.3)) "")   

What is the command "_non"?

hmspe

  • Bull Frog
  • Posts: 362
Re: Line perpendicular to other line
« Reply #7 on: March 12, 2016, 03:29:03 PM »
_non turns off entity snaps for the next operation.
"Science is the belief in the ignorance of experts." - Richard Feynman

carmi

  • Newt
  • Posts: 27
Re: Line perpendicular to other line
« Reply #8 on: March 20, 2020, 11:12:46 AM »
hi guys,
i reopen this topic for another request for help:

In the below code (completed with your help), i want to apply a default value for cwidth variable.

I tried to add this code but does not work (probably because i have "getdist") but i don't know how to solve.

Code: [Select]
(setq cwidth (getreal "Door thickness: <0.10> "))
(if (= cwidth nil) (setq cwidth 0.10))

Can you help me please?
Thank you very much


Code: [Select]
(defun c:door(/ eao)
 
(if (not cwidth) (setq cwidth 0))

(setq tcwidth (getdist "\nDoor thickness: "))

(if tcwidth (setq cwidth tcwidth))

(prompt (strcat "\thickness: "(rtos tcwidth) ))

(setq pt1 (getpoint "\nStart point... "))

(if pt1 (setq pt2 (getpoint pt1 "\nTo point... ")))

(setq threshold 1
segment 0
oang nil
ofrad (getvar "filletrad"))

(if (>= cwidth threshold) (setq inrad (* 1.0 cwidth) outrad (* 2.0 cwidth)))

(setq a (angle pt1 pt2)
1o1 (polar pt1 (+ a (/ pi 2.0)) (/ cwidth 2.0))
1o2 (polar pt2 (+ a (/ pi 2.0)) (/ cwidth 2.0))
ro1 (polar pt1 (- a (/ pi 2.0)) (/ cwidth 2.0))
ro2 (polar pt2 (- a (/ pi 2.0)) (/ cwidth 2.0)))

(if (> segment 0)
(setq eao ea ebo eb)
(setq dimpt (polar pt1 (+ a (/ pi 2.0))(+ (/ cwidth 2.0) 1.0))))

(command "line" 1o1 1o2 "")
(setq ea (entlast))
(command "line" ro1 ro2 "")
(setq eb (entlast))

(if (and (> segment 0)(/= a oang)(/= pi (abs (- a oang))))
(progn
(setq xa (- oang a))
(if (or (<= xa (* -1.0 pi))(and (> xa 0)(< xa pi)))
(setq ra outrad
rb inrad
dimpt (polar pt1 (+ a (/ pi 2.0)) (+ (/ cwidth 2.0) 1.0)))
(setq ra inrad
rb outrad
dimpt (polar pt1 (- a (/ pi 2.0)) (+ (/ cwidth 2.0) 1.0)))
)
(setq ss (ssadd ea))
(setq ss (ssadd eao ss))
(setvar "filletrad" ra)
(command "fillet" (ssname ss 0)(ssname ss 1))
(setq pp1 (cdr (assoc 10 (entget ea))))
(if (> segment 0)
(setq po1 (cdr (assoc 11 (entget eao))))
)
(setq ss (ssadd eb))
(setq ss (ssadd ebo ss))
(setvar "filletrad" rb)
(command "fillet" (ssname ss 0)(ssname ss 1))))

(setq ang (angle pt1 pt2) mid (polar pt1 ang (/ (distance pt1 pt2) 2.0)))

(command "_.line" "_non" (polar mid (+ ang (/ pi 2.0)) (+ 0.3 (/ tcwidth 2))) "_non" (polar mid (- ang (/ pi 2.0)) (+ 0.3 (/ tcwidth 2))) ""))


BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: Line perpendicular to other line
« Reply #9 on: March 21, 2020, 02:10:32 AM »
The answer was in the next post have a look
Code: [Select]
(setq *moff 10)
(initget 6)
(setq tmp (getdist (strcat "\nSpecify Offset <" (vl-princ-to-string *moff) "> : ")))
A man who never made a mistake never made anything