TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: velasquez on February 21, 2015, 07:25:02 AM

Title: Text position
Post by: velasquez on February 21, 2015, 07:25:02 AM
To follow a pattern I need to position text on a line in the following figure posted.
I have the points and angles that showed.
P3 and p4 points when I can drag the cursor and they can be above or below the red line.
I tried to help in other post but not very far.
Can anyone give me a way?
Title: Re: Text position
Post by: ymg on February 21, 2015, 07:46:58 AM
velasquez,

Use this function to keep your text at readable angle:

Code - Auto/Visual Lisp: [Select]
  1. ;; Make Angle Readable                                                        ;
  2.  (defun MakeReadable (a)
  3.      (setq a (rem (+ a pi pi) (+ pi pi)))
  4.      (rem (if (< (* pi 0.5) a (* pi 1.5))(+ a pi) a) (+ pi pi))  
  5.   )
  6.  

This will return the angle at which your text shuld be drafted.

ymg
Title: Re: Text position
Post by: Lee Mac on February 21, 2015, 08:18:37 AM
This is what I use:

Code - Auto/Visual Lisp: [Select]
  1. ;; Readable  -  Lee Mac
  2. ;; Returns an angle corrected for text readability.
  3.  
  4. (defun LM:readable ( a )
  5.     (   (lambda ( a )
  6.             (if (and (< (* pi 0.5) a) (<= a (* pi 1.5)))
  7.                 (LM:readable (+ a pi))
  8.                 a
  9.             )
  10.         )
  11.         (rem (+ a pi pi) (+ pi pi))
  12.     )
  13. )
Title: Re: Text position
Post by: velasquez on February 21, 2015, 11:35:25 AM
Thanks
 I will work with the functions.
Title: Re: Text position
Post by: roy_043 on February 22, 2015, 06:48:48 AM
Similar: http://www.theswamp.org/index.php?topic=47220.0

Small issue: both functions proposed here do not work properly if the input is smaller than -2*pi.
Code: [Select]
(MakeReadable (* -1 pi)) => 0.0
(MakeReadable (* -3 pi)) => -3.14159
(LM:READABLE (* -1 pi)) => 0.0
(LM:READABLE (* -3 pi)) -3.14159
Title: Re: Text position
Post by: Lee Mac on February 22, 2015, 07:00:45 AM
Similar: http://www.theswamp.org/index.php?topic=47220.0

Small issue: both functions proposed here do not work properly if the input is smaller than -2*pi.
Code: [Select]
(MakeReadable (* -1 pi)) => 0.0
(MakeReadable (* -3 pi)) => -3.14159
(LM:READABLE (* -1 pi)) => 0.0
(LM:READABLE (* -3 pi)) -3.14159

Thanks roy - a possible correction:

Code - Auto/Visual Lisp: [Select]
  1. ;; Readable  -  Lee Mac
  2. ;; Returns an angle corrected for text readability.
  3.  
  4. (defun LM:readable ( a )
  5.     (   (lambda ( a )
  6.             (if (< a 0.0)
  7.                 (LM:readable a)
  8.                 (if (and (< (* pi 0.5) a) (<= a (* pi 1.5)))
  9.                     (LM:readable (+ a pi))
  10.                     a
  11.                 )
  12.             )
  13.         )
  14.         (rem (+ a pi pi) (+ pi pi))
  15.     )
  16. )
Title: Re: Text position
Post by: ymg on February 23, 2015, 03:33:01 PM
Roy,

Maybe this to normalize the angle between 0 and 2pi.

Code: [Select]
(defun MakeReadable (a)
     (if (minusp (setq a (rem  a (+ pi pi)))) (setq a (+ a pi pi)))
     (rem (if (< (* pi 0.5) a (* pi 1.5))(+ a pi) a) (+ pi pi)) 
  )

ymg
Title: Re: Text position
Post by: efernal on February 23, 2015, 05:21:17 PM
Code - Auto/Visual Lisp: [Select]
  1. (DEFUN ef:txt:ang (e)
  2.   (IF (AND (> e (* PI 0.5)) (< e (* PI 1.5)))
  3.     (+ e PI)
  4.     e
  5.   )
  6. )
  7.  
Title: Re: Text position
Post by: velasquez on February 28, 2015, 07:47:47 AM
I'm finishing the code to test all the suggested options.
Great help.
Title: Re: Text position
Post by: velasquez on March 03, 2015, 04:13:33 PM
Similar: http://www.theswamp.org/index.php?topic=47220.0

Small issue: both functions proposed here do not work properly if the input is smaller than -2*pi.
Code: [Select]
(MakeReadable (* -1 pi)) => 0.0
(MakeReadable (* -3 pi)) => -3.14159
(LM:READABLE (* -1 pi)) => 0.0
(LM:READABLE (* -3 pi)) -3.14159






Thanks roy - a possible correction:

Code - Auto/Visual Lisp: [Select]
  1. ;; Readable  -  Lee Mac
  2. ;; Returns an angle corrected for text readability.
  3.  
  4. (defun LM:readable ( a )
  5.     (   (lambda ( a )
  6.             (if (< a 0.0)
  7.                 (LM:readable a)
  8.                 (if (and (< (* pi 0.5) a) (<= a (* pi 1.5)))
  9.                     (LM:readable (+ a pi))
  10.                     a
  11.                 )
  12.             )
  13.         )
  14.         (rem (+ a pi pi) (+ pi pi))
  15.     )
  16. )



Hi Lee
I tested its corrected function.
She worked well with the angles that I informed:
(LM: readable (angle p1 p2)) or (LM: readable (angle p2 p1)) -> Returns the correct angle

Thanks



Title: Re: Text position
Post by: Lee Mac on March 03, 2015, 04:46:14 PM
Hi Lee
I tested its corrected function.
She worked well with the angles that I informed:
(LM: readable (angle p1 p2)) or (LM: readable (angle p2 p1)) -> Returns the correct angle

Thanks

Excellent - I'm pleased it works well for you.  :-)