Author Topic: Check line for accuracy  (Read 11929 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Check line for accuracy
« Reply #15 on: February 23, 2007, 12:58:28 PM »

Thanks for all of the responses. Great work. All of the posted code seems to find all lines that are greatly at an angle but not find others that are off just so slightly.
Did you change the my code as I noted?  If so, then it still doesn't grab all the lines?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: Check line for accuracy
« Reply #16 on: February 23, 2007, 01:07:11 PM »

Quote
Did you change the my code as I noted?  If so, then it still doesn't grab all the lines?

I used the following code.

Code: [Select]
(vlax-for Lo (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-Acad-Object)))
  (vlax-for Obj (vla-get-Block Lo)
   (if
    (and
     (= (vla-get-ObjectName Obj) "AcDbLine")
     (not
      (or
((lambda (a)
   (or
     (equal (sin a) 0.0 0.02)
     (equal (abs (sin a)) 1.0 0.02)
   )
 )
  (vla-get-Angle Obj)
)
     )
     )
    )
    (vla-put-Color Obj 221)
   )
  )
)
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Check line for accuracy
« Reply #17 on: February 23, 2007, 01:22:14 PM »
You are still allowing for a tolerance of 1.14592 degrees.  If you want a very small number, then change this
Code: [Select]
   (or
     (equal (sin a) 0.0 0.02)
     (equal (abs (sin a)) 1.0 0.02)
   )
to
Code: [Select]
   (or
     (equal (sin a) 0.0 0.0000001)
     (equal (abs (sin a)) 1.0 0.0000001)
   )
This will get all lines that are not at a right angle.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Check line for accuracy
« Reply #18 on: February 23, 2007, 01:23:56 PM »
Evgeniy,

There's still a problem with your new code, if (sin a) is closed to -1.

Code: [Select]
((lambda (a) (equal (sin a) (fix (+ (sin a) 0.5)) (sin (/ pi 60))))
 (+ (* pi 1.5) (/ pi 90))
 )

Should return T, but return nil.

Maybe replace 'fix' function by a 'round' function working with negative numbers.

Code: [Select]
(defun round (num)
  (if (minusp num)
    (fix (- num 0.5))
    (fix (+ num 0.5))
  )
)

Speaking English as a French Frog

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: Check line for accuracy
« Reply #19 on: February 23, 2007, 01:35:06 PM »


Quote
You are still allowing for a tolerance of 1.14592 degrees.  If you want a very small number, then change this

Code:
   (or
     (equal (sin a) 0.0 0.02)
     (equal (abs (sin a)) 1.0 0.02)
   )
to

Code:
   (or
     (equal (sin a) 0.0 0.0000001)
     (equal (abs (sin a)) 1.0 0.0000001)
   )


Thanks T.Willey That was the problem. Works like a dream.
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Check line for accuracy
« Reply #20 on: February 23, 2007, 01:38:09 PM »


Quote
You are still allowing for a tolerance of 1.14592 degrees.  If you want a very small number, then change this

Code:
   (or
     (equal (sin a) 0.0 0.02)
     (equal (abs (sin a)) 1.0 0.02)
   )
to

Code:
   (or
     (equal (sin a) 0.0 0.0000001)
     (equal (abs (sin a)) 1.0 0.0000001)
   )


Thanks T.Willey That was the problem. Works like a dream.
You're welcome.  You might want to change the code back the the first one I posted, with making the same changes to it.  It seems like a debate aboutt he math of the code you are using.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Check line for accuracy
« Reply #21 on: February 23, 2007, 01:52:42 PM »
Thanks for all of the responses. Great work. All of the posted code seems to find all lines that are greatly at an angle but not find others that are off just so slightly.

Mine does! :-)

TheSwamp.org  (serving the CAD community since 2003)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Check line for accuracy
« Reply #22 on: February 23, 2007, 02:51:14 PM »
Evgeniy,

There's still a problem with your new code, if (sin a) is closed to -1.

Code: [Select]
((lambda (a) (equal (sin a) (fix (+ (sin a) 0.5)) (sin (/ pi 60))))
 (+ (* pi 1.5) (/ pi 90))
 )

Should return T, but return nil.

Maybe replace 'fix' function by a 'round' function working with negative numbers.

Code: [Select]
(defun round (num)
  (if (minusp num)
    (fix (- num 0.5))
    (fix (+ num 0.5))
  )
)




Once again I apologize, for the carelessness...
In Russia today a holiday and not the working day.
Now we with family celebrate.
Thanks gile for the instruction of mistakes!

New variant...
Code: [Select]
(equal (abs(sin a)) (fix (+ (abs(sin a)) 0.5)) (sin (/ pi 60)))

GDF

  • Water Moccasin
  • Posts: 2081
Re: Check line for accuracy
« Reply #23 on: February 23, 2007, 03:30:58 PM »
Check out this routine.

;;;SNAPLINE.LSP   Rectify Lines   (c)1998, Galen A. Light

Gary

You should check out the routine above, you can enter a fudge factor, and it will fix the line.
To Rectify Lines that are not truely Horizontal or Vertical.

(prompt "\n* Change angled Line to a 0 or 90 setting *")
(setq dvar (abs (getreal "\n* Enter degrees of variance: *")))

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Check line for accuracy
« Reply #24 on: February 23, 2007, 03:42:02 PM »
 :oops: :|

I'm sorry, none code posted by Evgeniy and I are realy exact.

Comparing only the angle sinus to 0 or 1 is not rigorous.

I'm going to try an explaination. If a equals pi/60 radians (3°) and b equals pi/2 + pi/60 (93°)

sinus a is equal to 0.052336
sinus b is equal to 0.99863

The codes posted by Evgeniy and I were comparing as well sinus a to 0 and sinus b to 1 and the result isn't the same even there's in both case the same rotation from 0° and 90°. The comparation isn't the same for 'horizontal' or 'vertical' angles.

I think it have been more rigorous to compare sinus a and cosinus b both to 0 (as sinus a, cosinus b is equal to -0.052336)

So, if we want to use trigonometry, instead of :
Code: [Select]
(or
      (equal (vla-get-Angle Obj) 0.0 0.05)
      (equal (vla-get-Angle Obj) (* pi 0.5) 0.05)
      (equal (vla-get-Angle Obj) pi 0.05)
      (equal (vla-get-Angle Obj) (* pi 1.5) 0.05)
     )

the good algorithm should be :
Code: [Select]
((lambda (a)
   (or
     (equal (sin a) 0.0 0.05)
     (equal (cos a) 0.0 0.05)
   )
 )
  (vla-get-Angle Obj)
)

Speaking English as a French Frog

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Check line for accuracy
« Reply #25 on: February 23, 2007, 03:52:21 PM »
Thanks Gile.  I was going to try and understand what you two have been posting when I got some time.  My trig sucks really bad right now, so it will take a while for me to understand it.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Check line for accuracy
« Reply #26 on: February 23, 2007, 04:56:54 PM »
Quote
My trig sucks really bad right now, so it will take a while for me to understand it.

It's not very difficult to understand.
In my opinion the simplest way to understand/remeber trigonometry is using the 'trigonometric circle'.

A circle which radius is equal to 1, with two axis : cosinus axis (horizontal) and sinus axis (vertical).
In this circle angles are increasing conterclockwise from 0 (East).
The projection of each angle line on cosinus axis is the cos value as well for sinus.
So :
cos 0° = 1 and sin 0° = 0
cos 90° = 0 and sin 90° = 1
cos 1800° = -1 and sin 180° = 0
cos 270° = 0 and sin 270° = -1

Speaking English as a French Frog

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Check line for accuracy
« Reply #27 on: February 24, 2007, 04:15:19 AM »
Summed up, at me it has turned out four programs...

Check of a corner of a line, without taking into account fuzz.
function use vla-object.
Code: [Select]
(defun test-not-orto (/ ss)
 ;; use vla-object
 (if (setq ss (ssget '((0 . "LINE"))))
  (foreach e (mapcar (function vlax-ename->vla-object)
                     (vl-remove-if (function listp) (mapcar (function cadr) (ssnamex ss)))
             ) ;_  mapcar
   (if (not (vl-some (function equal) (vlax-curve-getFirstDeriv e 0.) '(0. 0.) '(1e-8 1e-8)))
    (vla-put-Color e 1)
   ) ;_  if
  ) ;_  foreach
 ) ;_  if
 (princ)
) ;_  defun


Check of a corner of a line, without taking into account fuzz.
function not use vla-object.
Code: [Select]
(defun test-not-orto (/ ss)
 ;; not use vla-object
 (if (setq ss (ssget '((0 . "LINE"))))
  (foreach e (mapcar (function entget) (vl-remove-if (function listp) (mapcar (function cadr) (ssnamex ss))))
   (if (not (vl-some (function equal)
                     (mapcar (function -) (cdr (assoc 10 e)) (cdr (assoc 11 e)) '(0 0))
                     '(0. 0.)
                     '(1e-8 1e-8)
            ) ;_  vl-some
       ) ;_  not
    (entmod
     (if (assoc 62 e)
      (subst '(62 . 1) (assoc 62 e) e)
      (append (reverse (cons '(62 . 1) (vl-member-if (function (lambda (x) (= (car x) 8))) (reverse e))))
              (cdr (vl-member-if (function (lambda (x) (= (car x) 8))) e))
      ) ;_  append
     ) ;_  if
    ) ;_  entmod
   ) ;_  if
  ) ;_  foreach
 ) ;_  if
 (princ)
) ;_  defun


Check of a corner of a line, taking into account fuzz.
function use vla-object.
Code: [Select]
(defun test-not-orto-fuzz (/ ss)
 ;; use vla-object
 (if (setq ss (ssget '((0 . "LINE"))))
  (foreach e (mapcar (function vlax-ename->vla-object)
                     (vl-remove-if (function listp) (mapcar (function cadr) (ssnamex ss)))
             ) ;_  mapcar
   (if (not ((lambda (a) (or (equal (sin a) 0.0 0.05) (equal (cos a) 0.0 0.05))) (vla-get-Angle e)))
    (vla-put-Color e 1)
   ) ;_  if
  ) ;_  foreach
 ) ;_  if
 (princ)
) ;_  defun


Check of a corner of a line, taking into account fuzz.
function not use vla-object.
Code: [Select]
(defun test-not-orto-fuzz (/ ss)
 ;; not use vla-object
 (if (setq ss (ssget '((0 . "LINE"))))
  (foreach e (mapcar (function entget) (vl-remove-if (function listp) (mapcar (function cadr) (ssnamex ss))))
   (if (not ((lambda (a) (or (equal (sin a) 0.0 0.05) (equal (cos a) 0.0 0.05)))
             (angle (cdr (assoc 10 e)) (cdr (assoc 11 e)))
            )
       ) ;_  not
    (entmod
     (if (assoc 62 e)
      (subst '(62 . 1) (assoc 62 e) e)
      (append (reverse (cons '(62 . 1) (vl-member-if (function (lambda (x) (= (car x) 8))) (reverse e))))
              (cdr (vl-member-if (function (lambda (x) (= (car x) 8))) e))
      ) ;_  append
     ) ;_  if
    ) ;_  entmod
   ) ;_  if
  ) ;_  foreach
 ) ;_  if
 (princ)
) ;_  defun

fools

  • Newt
  • Posts: 72
  • China
Re: Check line for accuracy
« Reply #28 on: March 01, 2007, 07:45:20 AM »
:oops: :|

the good algorithm should be :
Code: [Select]
((lambda (a)
   (or
     (equal (sin a) 0.0 0.05)
     (equal (cos a) 0.0 0.05)
   )
 )
  (vla-get-Angle Obj)
)


how about this solution? :-) a little faster
because SIN(2*A)=2*SIN(A)*COS(A)
Code: [Select]
((LAMBDA (a)
   (EQUAL (sin (+ a a) 0.0 0.104528))
 )
 (vla-get-Angle Obj)
)
« Last Edit: March 01, 2007, 08:26:43 AM by fools »
Good good study , day day up . Sorry about my Chinglish .

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Check line for accuracy
« Reply #29 on: March 01, 2007, 09:27:04 AM »
Welcome to the swamp fools

Nice lisp, although there is a miss-placed parentheses in your post

Code: [Select]
  ((lambda (a)
            (equal (sin (+ a a)[color=red])[/color] 0.0 0.0523599) ; +-3 deg
          )
         (vla-get-angle Obj)
  )
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.