Author Topic: Grdraw a point  (Read 165 times)

0 Members and 1 Guest are viewing this topic.

Grrr1337

  • Bull Frog
  • Posts: 355
Grdraw a point
« on: September 04, 2017, 01:50:42 pm »
Hi guys,
I just wanted to share this recent subfunction I wrote, about grdraw'ing a point:

Code - Auto/Visual Lisp: [Select]
  1. ; Grdraw a point
  2. ; Display variables that might worth exploring: (mapcar 'getvar '(viewsize viewctr screensize))
  3. ; (* (/ (cadr (getvar 'screensize)) YourScreenResolution2ndNumber YourPhysicalScreenHeight)) somewhere Kent Cooper explained
  4. ; (GrdrawPoint (getpoint "\nPick:") nil nil nil nil)
  5. ; (GrdrawPoint (getpoint "\nPick:") 1 nil nil 10)
  6. ; (GrdrawPoint '(0. 0. 0.) -3 nil 3 10)
  7. (defun GrdrawPoint ( p c d n idx / i L )
  8.  (cond
  9.    ( ((lambda (x) (and (listp x) (= 3 (length x)) (vl-every 'numberp x))) p)             ; pointp
  10.      (or (eq 'INT (type c)) (setq c -1))                                                 ; c - colour
  11.      (or (numberp d) (setq d (* 10 (/ (getvar 'viewsize) (cadr (getvar 'screensize)))))) ; d - radius size
  12.      (or (and (eq 'INT (type n)) (< 0 n)) (setq n 12))                                   ; n - number of increments
  13.      (or (and (eq 'INT (type idx)) (< 0 n)) (setq idx 1))                                ; idx - highlighting index
  14.  
  15.      (redraw) (setq i 0) (repeat n (setq L (cons (polar p (setq i (+ i (/ (* 2. PI) n))) d) L))) ; (/ (* 2. PI) n) is the angle increment
  16.      (repeat idx
  17.        (grvecs (cons c (apply 'append (mapcar 'list L (cons (last L) L))))) ; This technique was demonstrated by Roy - Thank you!
  18.        ; (grdraw (polar p (* PI -0.25) (* d 2.)) (polar p (* PI 0.75) (* d 2.)) c)
  19.        ; (grdraw (polar p (* PI -0.75) (* d 2.)) (polar p (* PI 0.25) (* d 2.)) c)
  20.        (mapcar
  21.          '(lambda (a) (apply 'grdraw (reverse (cons c (mapcar '(lambda (x) (polar p (* PI x) (* d 2.))) a)))))
  22.          '((-0.25 0.75)(-0.75 0.25)) ; '((-0.25 0.75)(-0.75 0.25)(1. 0.)(0.5 -0.5))
  23.        ); mapcar
  24.      ); repeat
  25.      L
  26.    )
  27.  ); cond
  28. ); defun GrdrawPoint

You may ask where I use this: I had one grread routine where I had to draw the basepoint (for reference), but also it was constantly changing its location - hence I had to entmake and entdel a POINT entity, which was way buggy'n'uncomfortable to do in a relatively big code.
It also contains some useless comments (sorry bout that).
Hopefully you'll find it useful in your codes...

BTW I don't think this thread belongs to "show your stuff" section, since its more related to lisp coding.

MP

  • Seagull
  • Posts: 16985
  • brevity != aggression
Re: Grdraw a point
« Reply #1 on: September 04, 2017, 02:21:41 pm »
Good to see you exploring different ways to exploit lisp for tool making. Feel free to lift ideas from this post from yesteryear. Cheers.
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

Grrr1337

  • Bull Frog
  • Posts: 355
Re: Grdraw a point
« Reply #2 on: September 04, 2017, 03:19:14 pm »
Good to see you exploring different ways to exploit lisp for tool making. Feel free to lift ideas from this post from yesteryear. Cheers.

Ahh, thanks for sharing - I didn't expected anything related! :)
I was searching before, but couldn't find anything - perhaps of the lack of important keyword(s): grdraw / grvecs.
So I guess it would be nearly impossible to find something similar without help, since 95% of the threads related to point(s) are about dealing with vertices / xyz coordinates / trans / bla-bla...

BTW I thought, that I could play a bit more, so the geometry could replicate the one to the PDMODE variable, but it would be a bit too much (considering my task is already solved).

Lee Mac

  • Seagull
  • Posts: 11780
  • AutoCAD 2015 Windows 7 London, England
Re: Grdraw a point
« Reply #3 on: September 04, 2017, 06:17:51 pm »
Nice one Grrr1337 - I see you are also catching the gr* bug: the use of such functions quickly becomes addictive. :lol:

This is how I used to approach this particular task:
Code - Auto/Visual Lisp: [Select]
  1. ;; grX  -  Lee Mac
  2. ;; p - [lst] WCS point at which to display 'X'
  3. ;; s - [int] size of point (in pixels)
  4. ;; c - [int] ACI colour of point
  5. ;; Returns supplied WCS point.
  6.  
  7. (defun LM:grx ( p s c / -s r q )
  8.    (setq r (/ (getvar 'viewsize) (cadr (getvar 'screensize)))
  9.          q (trans p 0 3)
  10.         -s (- s)
  11.    )
  12.    (grvecs
  13.        (list c
  14.            (list -s -s) (list s  s) (list -s (1+ -s)) (list (1- s)  s) (list (1+ -s) -s) (list s (1-  s))
  15.            (list -s  s) (list s -s) (list -s (1-  s)) (list (1- s) -s) (list (1+ -s)  s) (list s (1+ -s))
  16.        )
  17.        (list
  18.            (list r  0. 0. (car  q))
  19.            (list 0. r  0. (cadr q))
  20.            (list 0. 0. r  0.)
  21.            (list 0. 0. 0. 1.)
  22.        )
  23.    )
  24.    p
  25. )

e.g.

(LM:grX (getpoint "\nPick a point: ") 5 3)

Grrr1337

  • Bull Frog
  • Posts: 355
Re: Grdraw a point
« Reply #4 on: September 05, 2017, 04:50:21 am »

Nice one Grrr1337 - I see you are also catching the gr* bug: the use of such functions quickly becomes addictive. :lol:

Indeed, I like to implement them wherever I can! :)

This is how I used to approach this particular task:

Thats a very pretty and confusing (for me) code and I assume you wrote it on-the-fly.
Thanks for posting it, I'll try to learn something from it, as grvecs is my hardest function to use from the gr* functions.