Jump to content

How to pick a side (i.e. left or right) of a line


Recommended Posts

Posted

Hi all,

 

used to have a fair amount of lisproutine back in the days, but it's all lost when I changed jobs (a decade ago...) and to LT.

Now I'm trying to write (recreate) a lisp, but my memory is not what it used to be... and this is probably very simple, I've tried to look for it on the forum, but could not find it...

 

What I want: there is a line, you pick begin and end point, you click to one or the other side of the line and on that selected side of the line it draws something...

See attachement: A line (pt1 and pt2) and a point which can be on either side of the line (i.e. left or right if it's a vertical line) I've drawn a circel to indicate the two possible quadrants, in this case left and right. Most lines will be vertical, however on some occasions the line can be at a different angle.

Once these three points are selected, the lisp will draw a set of lines perpendicular and parallel lines to the primary line, at set distances (drawn in red).

 

My problem is that I can't get my head around about how to select which side of the line. I'm pretty sure it's something simple, but I can't remember how it's done.

 

This is what I've got sofar. I can select the three points, I can draw the lines, but someting goes wrong with calculating the angles and it draws the lines basically not where I want them to be...

 

 
(defun C:HH() 
(defun RTD (nbrOfRadians)    ;convert to degrees
  (* 180.0 (/ nbrOfRadians pi))
);defun RTD
 (defun DTR (a)     ;convert to radians
  (* pi (/ a 180.0))
);defun DTR

  (setq  OLDECHO (getvar "CMDECHO")  ;store system variables
        OLDBLIP (getvar "BLIPMODE")
 OLDSNAP (getvar "OSMODE")
  );setq
  (setvar "CMDECHO" 0)
  (setvar "BLIPMODE" 0)
  (setq P1 nil     P2 nil     P3 nil     P4 nil );setq Zorgt dat P1 etc nil zijn

(setq pt1(getpoint "\n Startpoint: "))  ;store base point
    (setq pt2(getpoint "\n Endpoint: "))

(setq a-rad1 (angle pt1 pt2))    ;angle in radians
(setq a-deg1 (RTD a-rad1))       ;angle in degrees

(setq pt3(getpoint "\n On which side of the line would like to draw?: "))

;
(setq a-rad2 (angle pt1 pt3))    ;angle in radians
(setq a-deg2 (RTD a-rad2))
  (setq Diff-deg1-2 (- a-deg1 a-deg2))
  (COND  ((< 90 Diff-deg1-2)   ;Als het links van de pt1-pt2 lijn is
  (setq hoek1 (DTR 180.0))
  (setq hoek2 (DTR 0.0))
  (setq hoeka (RTD Hoek1))
  (setq hoekb (RTD hoek2)))
   ((> 90 Diff-deg1-2)  ;Als het rechts van de pt1-pt2 lijn is  
  (setq hoek1 (DTR 0.0))
  (setq hoek2 (DTR 180.0)) 
  (setq hoeka (RTD hoek1)) 
  (setq hoekb (RTD hoek2)))
);end cond 1=links 2=rechts



;(setq hoek1 (+ a-rad1 hoek1)) 
;(setq  hoek2 (+ a-rad1 hoek2))
;(setq hoeka (RTD Hoek1))
;(setq hoekb (RTD hoek2))



  (setq Lengte (distance pt1 pt2))
(setq Lagen (/ (/ lengte 2) 60)); waarbij

    (command "_UCS" "_n" "z" a-deg1)
  (setvar "OSMODE" 0)
      (setq  P1 (polar pt1 hoek1 165)
     P2 (polar P1 (DTR 90.0) 60)
     P3 (polar P2 hoek2 165)
     P4 (polar P3 (DTR 90.0) 60)
);setq
(command "PLINE" pt1 "W" "0.0" "0.0" P1 P2 P3 P4""
);command
(setq cntr 1)   ;setup counter   
(while (< cntr lagen)  ;loop until cntr is not less than lagen
 (command "copy" "last" "" pt1  P4
 );command
 (setq cntr(+ cntr 1)) ;increment the counter
       );while 
(setq cntr 1)   ;Reset counter   
(command "_UCS" "_p" "" );reset ucs to previous

(setvar "OSMODE" OLDSNAP)
(setvar "BLIPMODE" OLDBLIP)
(setvar "CMDECHO" OLDECHO)
(princ)
);end defun
(princ)

 

So my question is, does anybody have a solution to my problem? It's driving me... I know I'm close, but yet so far...

 

thanks for having a look!

 

 

 

If anybody would like to know, I'm making scalemodels of buildings, which are superfine in detail. This means every brick has to be in place. I've got the correct hatch to draw the brick pattern, but there are certain rules how corners are done, which can't be caught in the hatchpattern. This lisp will help me greatly in doing just so, by changing the hatch boundary.

example of what lips should do.dxf

Posted

a different approach

 

(defun c:test (/       ent     obj     pt_pick pt1     osm_old pt_start
       pt_end  pt2     num     pt3     pt4     pt5     pt6
      )
 (vl-load-com)
 (setq ent  (entsel "\nSelect the line near the brick base : ")
obj  (vlax-ename->vla-object (car ent))
pt_pick  (cadr ent)
pt1  (getpoint "\nPick the desired side: ")
osm_old  (getvar "OSMODE")
pt_start (vlax-curve-getStartPoint obj)
pt_end  (vlax-curve-getEndPoint obj)
pt2  (vlax-curve-getClosestPointTo obj pt1 T)
num  (fix (- (/ (/ (vla-get-Length obj) 60) 2) 0.5))
 )
 (setvar "OSMODE" 0)
 (if (< (distance pt_end pt_pick) (distance pt_start pt_pick))
   (progn
     (setq pt_start pt_end
    pt_end   (vlax-curve-getStartPoint obj)
     )
   )
 )
 (setq pt3 (polar pt_start (angle pt2 pt1) 165)
pt4 (polar pt3 (angle pt_start pt_end) 60)
pt5 (polar pt4 (angle pt1 pt2) 165)
pt6 (polar pt5 (angle pt_start pt_end) 60)
 )
 (command "PLINE" pt_start "W" "0.0" "0.0" pt3 pt4 pt5 pt6 "")
 (repeat num (command "copy" "last" "" pt_start Pt6))
 (setvar "OSMODE" osm_old)
 (princ)
)

 

hope that helps

Henrique

Posted

This looked like an interesting program so I experimented with a 'dynamic' version:

 

dynamiczigzag2.gif

 

[color=GREEN];; Dynamic Zig-Zag  -  Lee Mac[/color]
([color=BLUE]defun[/color] c:hh ( [color=BLUE]/[/color] ang dis ent gr1 gr2 inc len lst ocs pt1 pt2 spc tmp )
   ([color=BLUE]setq[/color] spc  60.0 [color=GREEN];; Spacing[/color]
         len 165.0 [color=GREEN];; Length[/color]
   )    
   ([color=BLUE]while[/color]
       ([color=BLUE]progn[/color] ([color=BLUE]setvar[/color] 'errno 0) ([color=BLUE]setq[/color] ent ([color=BLUE]car[/color] ([color=BLUE]entsel[/color] [color=MAROON]"\nSelect Line: "[/color])))
           ([color=BLUE]cond[/color]
               (   ([color=BLUE]=[/color] 7 ([color=BLUE]getvar[/color] 'errno))
                   ([color=BLUE]princ[/color] [color=MAROON]"\nMissed, try again."[/color])
               )
               (   ([color=BLUE]null[/color] ent)
                   [color=BLUE]nil[/color]
               )
               (   ([color=BLUE]/=[/color] [color=MAROON]"LINE"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]setq[/color] ent ([color=BLUE]entget[/color] ent)))))
                   ([color=BLUE]princ[/color] [color=MAROON]"\nSelected object is not a Line."[/color])
               )
               (   [color=BLUE]t[/color]
                   ([color=BLUE]setq[/color] pt1 ([color=BLUE]trans[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 10 ent)) 0 1)
                         pt2 ([color=BLUE]trans[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 11 ent)) 0 1)
                         dis ([color=BLUE]distance[/color] pt1 pt2)
                         inc ([color=BLUE]/[/color] [color=BLUE]pi[/color] 2.0)
                         ang ([color=BLUE]angle[/color] pt1 pt2)
                   )
                   ([color=BLUE]princ[/color] [color=MAROON]"\nChoose Side [</>/-/+] <Exit>: "[/color])
                   ([color=BLUE]while[/color]
                       ([color=BLUE]progn[/color]
                           ([color=BLUE]setq[/color] gr1 ([color=BLUE]grread[/color] [color=BLUE]t[/color] 15 0)
                                 gr2 ([color=BLUE]cadr[/color] gr1)
                                 gr1 ([color=BLUE]car[/color]  gr1)
                           )
                           ([color=BLUE]cond[/color]
                               (   ([color=BLUE]or[/color] ([color=BLUE]=[/color] 3 gr1) ([color=BLUE]=[/color] 5 gr1))
                                   ([color=BLUE]setq[/color] tmp pt1
                                         inc ([color=BLUE]abs[/color] inc)
                                   )
                                   ([color=BLUE]if[/color] ([color=BLUE]minusp[/color] ([color=BLUE]sin[/color] ([color=BLUE]-[/color] ([color=BLUE]angle[/color] pt1 gr2) ang)))
                                       ([color=BLUE]setq[/color] inc ([color=BLUE]-[/color] inc))
                                   )
                                   ([color=BLUE]redraw[/color])
                                   ([color=BLUE]repeat[/color] ([color=BLUE]*[/color] 2 ([color=BLUE]fix[/color] ([color=BLUE]/[/color] ([color=BLUE]1+[/color] ([color=BLUE]/[/color] dis spc)) 2)))
                                       ([color=BLUE]grdraw[/color] tmp ([color=BLUE]setq[/color] tmp ([color=BLUE]polar[/color] tmp ([color=BLUE]+[/color] ang inc) len)) 1 1)
                                       ([color=BLUE]grdraw[/color] tmp ([color=BLUE]setq[/color] tmp ([color=BLUE]polar[/color] tmp ang spc)) 1 1)
                                       ([color=BLUE]setq[/color] inc ([color=BLUE]-[/color] inc))
                                   )
                                   ([color=BLUE]=[/color] 5 gr1)
                               )
                               (   ([color=BLUE]=[/color] 2 gr1)
                                   ([color=BLUE]cond[/color]
                                       (   ([color=BLUE]or[/color] ([color=BLUE]=[/color] 45 gr2) ([color=BLUE]=[/color] 95 gr2))
                                           ([color=BLUE]setq[/color] spc ([color=BLUE]*[/color] 0.9 spc))
                                       )
                                       (   ([color=BLUE]or[/color] ([color=BLUE]=[/color] 43 gr2) ([color=BLUE]=[/color] 61 gr2))
                                           ([color=BLUE]setq[/color] spc ([color=BLUE]*[/color] 1.1 spc))
                                       )
                                       (   ([color=BLUE]or[/color] ([color=BLUE]=[/color] 46 gr2) ([color=BLUE]=[/color] 62 gr2))
                                           ([color=BLUE]setq[/color] len ([color=BLUE]*[/color] 0.9 len))
                                       )
                                       (   ([color=BLUE]or[/color] ([color=BLUE]=[/color] 44 gr2) ([color=BLUE]=[/color] 60 gr2))
                                           ([color=BLUE]setq[/color] len ([color=BLUE]*[/color] 1.1 len))
                                       )
                                       (   ([color=BLUE]or[/color] ([color=BLUE]=[/color] 32 gr2) ([color=BLUE]=[/color] 13 gr2))
                                           [color=BLUE]nil[/color]
                                       )
                                       (   [color=BLUE]t[/color]   )
                                   )
                               )
                           )
                       )
                   )
                   ([color=BLUE]redraw[/color])
                   ([color=BLUE]if[/color] ([color=BLUE]=[/color] 3 gr1)
                       ([color=BLUE]progn[/color]
                           ([color=BLUE]setq[/color] inc ([color=BLUE]abs[/color] inc)
                                 ocs ([color=BLUE]trans[/color] '(0.0 0.0 1.0) 1 0 [color=BLUE]t[/color])
                           )
                           ([color=BLUE]if[/color] ([color=BLUE]minusp[/color] ([color=BLUE]sin[/color] ([color=BLUE]-[/color] ([color=BLUE]angle[/color] pt1 gr2) ang)))
                               ([color=BLUE]setq[/color] inc ([color=BLUE]-[/color] inc))
                           )
                           ([color=BLUE]repeat[/color] ([color=BLUE]*[/color] 2 ([color=BLUE]fix[/color] ([color=BLUE]/[/color] ([color=BLUE]1+[/color] ([color=BLUE]/[/color] dis spc)) 2)))
                               ([color=BLUE]setq[/color] lst ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] 10 ([color=BLUE]trans[/color] pt1 1 ocs)) lst)
                                     lst ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] 10 ([color=BLUE]trans[/color] ([color=BLUE]setq[/color] pt1 ([color=BLUE]polar[/color] pt1 ([color=BLUE]+[/color] ang inc) len)) 1 ocs)) lst)
                                     lst ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] 10 ([color=BLUE]trans[/color] ([color=BLUE]setq[/color] pt1 ([color=BLUE]polar[/color] pt1 ang spc)) 1 ocs)) lst)
                                     inc ([color=BLUE]-[/color] inc)
                               )
                           )
                           ([color=BLUE]entmake[/color]
                               ([color=BLUE]append[/color]
                                   ([color=BLUE]list[/color]
                                      '(000 . [color=MAROON]"LWPOLYLINE"[/color])
                                      '(100 . [color=MAROON]"AcDbEntity"[/color])
                                      '(100 . [color=MAROON]"AcDbPolyline"[/color])
                                       ([color=BLUE]cons[/color] 90 ([color=BLUE]length[/color] lst))
                                      '(070 . 0)
                                   )
                                   lst
                                   ([color=BLUE]list[/color] ([color=BLUE]cons[/color] 210 ocs))
                               )
                           )
                           [color=BLUE]nil[/color]
                       )
                   )
               )
           )
       )
   )
   ([color=BLUE]princ[/color])
)

 

The above should also perform successfully in all UCS & Views.

Posted

A different different approach you do not need the second pick desired side

 

In the prompt message you say "pick left hand End" this then implies which is up and down, in v's out then like code above you compare the distance to the end & start pts to work out the correct "Left" end, with a little practice you get used to picking lines that are upside down for direction.

Posted

Hi all, thanks for your replies! This helps me out a lot. Been away a few days, saw the code yesterday, but out of reach of my acad machine... Couldn't wait till I got back and test the codes!

@hmsilva thanks, nice and short, does exactly what I wanted it to do! Although it also means I need to read up on my Vlisp... This will certainly help me out.

 

@LeeMac also thanks for your effort, this looks very slick, although I still need to dig in to find out what does what in this code! But it's very nicely done with being able to select a side in wysiwyg-mode!

 

Now I need to try and incorporate it in my lisps. Thanks all

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...