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

0 Members and 1 Guest are viewing this topic.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Check line for accuracy
« on: February 22, 2007, 09:39:58 AM »

I am in need of some direction. I want to be able to check all lines in a drawing for for accuracy. (i.e. straight versus crooked lines). Please see picture.
Basically I want to be able to run a check on an entire drawing and have it check all lines for accuracy within a given tolerance of say 3 degrees from being straight and once found annotate them with somehow so that the user can go back through the drawing and correct accordingly if needed.

Any assistance is greatly appreciated.


AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

GDF

  • Water Moccasin
  • Posts: 2081
Re: Check line for accuracy
« Reply #1 on: February 22, 2007, 10:46:53 AM »
Check out this routine.

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

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

JohnK

  • Administrator
  • Seagull
  • Posts: 10627
Re: Check line for accuracy
« Reply #2 on: February 22, 2007, 10:48:57 AM »
You could always just do the math...http://www.theswamp.org/index.php?topic=5203.0



TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Check line for accuracy
« Reply #3 on: February 22, 2007, 10:50:42 AM »
Looks like it would be a fun project for some of the swampers! :-)

TheSwamp.org  (serving the CAD community since 2003)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Check line for accuracy
« Reply #4 on: February 22, 2007, 11:11:24 AM »
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
      (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)
     )
    )
   )
   (vla-put-Color Obj 121)
  )
 )
)

??
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 #5 on: February 22, 2007, 12:46:47 PM »

An example. I have this for for the propoerties of a line...

Command:  LIST
Select objects: 1 found

Quote
Command:  LIST
Select objects: 1 found

Select objects:
                  LINE      Layer: "A-WALL-TENT-EXST"
                            Space: Model space
                   Handle = CF05
              from point, X=154'-3 1/2"  Y=208'-1 1/8"  Z=    0'-0"
                to point, X=180'-8 3/4"  Y=208'-1 1/2"  Z=    0'-0"
          Length =26'-5 1/4",  Angle in XY Plane = 0.06453059
                  Delta X =26'-5 1/4", Delta Y = 0'-0 3/8", Delta Z =    0'-0

The Angle in the XY plane is off from being "0" by a very small amount. These are the types of lines that I want to be able to search for. In this case it is off by less than a degree.

The supplied code from T.Willey did not catch this line as being incorrect.
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 #6 on: February 22, 2007, 12:58:02 PM »

I am in need of some direction. I want to be able to check all lines in a drawing for for accuracy. (i.e. straight versus crooked lines). Please see picture.
Basically I want to be able to run a check on an entire drawing and have it check all lines for accuracy within a given tolerance of say 3 degrees from being straight and once found annotate them with somehow so that the user can go back through the drawing and correct accordingly if needed.

Any assistance is greatly appreciated.



This is what I went off of.  If you want a smaller tolerance, then change these lines in the code.
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)
     )
* don't forget that the angle is in radians.  That is how I got the 0.05
Quote
Command: (* (/ 3.0 180.0) pi)
0.0523599
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 #7 on: February 22, 2007, 02:41:45 PM »
Try this one ...

Code: [Select]
(defun c:checklines ( / ss cntr new_ss x y ang ent )

  (defun check_angle (ang)
    (cond
      ((= ang (* pi 0.5)) T) ; up
      ((= ang (* pi 1.0)) T) ; left
      ((= ang (* pi 1.5)) T) ; down
      ((= ang 0.0) T) ; zero
      )
    )

  (sssetfirst nil)

  (setq ss (ssget "X" '((0 . "LINE")))
cntr 0
new_ss (ssadd)
)

  (if (not (zerop (sslength ss)))
    (while (setq ent (ssname ss cntr))
   (setq x (cdr (assoc 10 (entget ent)))
y (cdr (assoc 11 (entget ent)))
ang (angle x y)
)
   (if (not (check_angle ang))
     (ssadd ent new_ss)
     )

   (setq cntr (1+ cntr))


   );while

    );if

  (if (not (zerop (sslength new_ss)))
    (sssetfirst nil new_ss)
    )

  (princ)
  )
TheSwamp.org  (serving the CAD community since 2003)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Check line for accuracy
« Reply #8 on: February 23, 2007, 12:42:12 AM »
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)
     )

My variant:

Code: [Select]
((lambda (a) (equal (sin a) (fix (sin a)) (sin (/ pi 60))))
 (vla-get-Angle Obj)
 )
« Last Edit: February 23, 2007, 12:44:05 AM by ElpanovEvgeniy »

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Check line for accuracy
« Reply #9 on: February 23, 2007, 02:56:17 AM »
Try this one ...

Code: [Select]
(defun c:checklines ( / ss cntr new_ss x y ang ent )

  (defun check_angle (ang)
    (cond
      ((= ang (* pi 0.5)) T) ; up
      ((= ang (* pi 1.0)) T) ; left
      ((= ang (* pi 1.5)) T) ; down
      ((= ang 0.0) T) ; zero
      )
    )

  (sssetfirst nil)

  (setq ss (ssget "X" '((0 . "LINE")))
cntr 0
new_ss (ssadd)
)

  (if (not (zerop (sslength ss)))
    (while (setq ent (ssname ss cntr))
   (setq x (cdr (assoc 10 (entget ent)))
y (cdr (assoc 11 (entget ent)))
ang (angle x y)
)
   (if (not (check_angle ang))
     (ssadd ent new_ss)
     )

   (setq cntr (1+ cntr))


   );while

    );if

  (if (not (zerop (sslength new_ss)))
    (sssetfirst nil new_ss)
    )

  (princ)
  )


If at check of a corner, it is not necessary to set accuracy (fuzz)
It is enough to check up:

Code: [Select]
(or
 (= (- x1 x2) 0.)
 (= (- y1 y2) 0.)
 )

For example:

Code: [Select]
(vl-some
 (function equal)
 (mapcar (function -)
         (cdr (assoc 10 (entget e)))
         (cdr (assoc 11 (entget e)))
         '(0 0)
 ) ;_  mapcar
 '(0. 0.)
 '(1e-8 1e-8)
) ;_  vl-some

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Check line for accuracy
« Reply #10 on: February 23, 2007, 11:05:44 AM »
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)
     )

My variant:

Code: [Select]
((lambda (a) (equal (sin a) (fix (sin a)) (sin (/ pi 60))))
 (vla-get-Angle Obj)
 )

You're math skills are better than mine, so I will just assume you are correct.  Nice short compact test Evgeniy.  :-)
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 #11 on: February 23, 2007, 11:47:22 AM »
Quote
((lambda (a) (equal (sin a) (fix (sin a)) (sin (/ pi 60))))
 (vla-get-Angle Obj)
 )

I think there's a mistake, except if a equals pi/2 or 3pi/2 (fix (sin a)) will always return 0.0.

Example: if a equals pi/120 radians (very closed to 0.0°), it works

Quote
_$ (setq a (/ pi 120))
0.0261799
_$ (sin a)
0.0261769
_$ (fix (sin a))
0
_$ (equal (sin a) (fix (sin a)) (sin (/ pi 60)))
T

But, if a is pi/2 + pi/120 radians (very closed to 90.0°), it don't work.

Quote
_$ (setq a (+ (/ pi 2) (/ pi 120)))
1.59698
_$ (sin a)
0.999657
_$ (fix (sin a))
0
_$ (equal (sin a) (fix (sin a)) (sin (/ pi 60)))
nil

Evgeniy's code should be right whith '=' or 'eq' functions, but can't be used with 'equal' and a 'fuzz'.
« Last Edit: February 23, 2007, 11:50:05 AM by gile »
Speaking English as a French Frog

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Check line for accuracy
« Reply #12 on: February 23, 2007, 12:18:58 PM »
Another version, less compact, but semms to work

Code: [Select]
((lambda (a)
   (or
     (equal (sin a) 0.0 0.05)
     (equal (abs (sin a)) 1.0 0.05)
   )
 )
  (vla-get-Angle Obj)
)
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 #13 on: February 23, 2007, 12:54:16 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.
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Check line for accuracy
« Reply #14 on: February 23, 2007, 12:56:18 PM »
Quote
((lambda (a) (equal (sin a) (fix (sin a)) (sin (/ pi 60))))
 (vla-get-Angle Obj)
 )

I think there's a mistake, except if a equals pi/2 or 3pi/2 (fix (sin a)) will always return 0.0.

Example: if a equals pi/120 radians (very closed to 0.0°), it works

Quote
_$ (setq a (/ pi 120))
0.0261799
_$ (sin a)
0.0261769
_$ (fix (sin a))
0
_$ (equal (sin a) (fix (sin a)) (sin (/ pi 60)))
T

But, if a is pi/2 + pi/120 radians (very closed to 90.0°), it don't work.

Quote
_$ (setq a (+ (/ pi 2) (/ pi 120)))
1.59698
_$ (sin a)
0.999657
_$ (fix (sin a))
0
_$ (equal (sin a) (fix (sin a)) (sin (/ pi 60)))
nil

Evgeniy's code should be right whith '=' or 'eq' functions, but can't be used with 'equal' and a 'fuzz'.

I am sorry! :oops:
I have hastened and have badly expressed the idea...
Many thanks gile! You have corrected me.

In my example, it is necessary to use
Code: [Select]
(fix (+ (sin a) 0.5))
Then all example will look:

Code: [Select]
((lambda (a) (equal (sin a) (fix (+(sin a)0.5)) (sin (/ pi 60))))
 (vla-get-Angle Obj)
 )

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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Check line for accuracy
« Reply #30 on: March 01, 2007, 09:41:54 AM »
OK, I'm having a problem with this angle:
a = 6.25215 or 358.222 deg

_1_$ (sin (+ a a))
-0.0620258
_1_$ (rtod (sin (+ a a)))
-3.55382
_1_$ (- (* 2 pi) a)
0.0310328
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.

fools

  • Newt
  • Posts: 72
  • China
Re: Check line for accuracy
« Reply #31 on: March 01, 2007, 10:05:56 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)
  )

Thanks CAB for your greeting. And thanks u again for pointing out my mistake. :-)

In my function , +-3 deg is double.   (sin (/ pi 30))=0.104528 , not 0.0523599.
other angles :
Code: [Select]
(mapcar (function (lambda (x) (sin (/ (* 2 PI x) 180)))) '(3 87 93 177 183 267 273 357))
;;return (0.104528 0.104528 -0.104528 -0.104528 0.104528 0.104528 -0.104528 -0.104528)
So the code is
Code: [Select]
((LAMBDA (a)
   (EQUAL (SIN (+ a a)) 0.0 0.104528) ; +-3 deg
 )(VLA-GET-ANGLE Obj)
)
Good good study , day day up . Sorry about my Chinglish .

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Check line for accuracy
« Reply #32 on: March 01, 2007, 10:10:17 AM »
You'er quite right. Too much math for me. :-)

I did find my mistake though, using my test rig.
Code: [Select]
(defun c:test2()

  (mapcar '(lambda (a / b)
             (setq b (print (rtod a)))
             (print a)
             (print (sin (+ a a)))
             (print (equal (sin (+ a a)) 0.0 0.104528)) ; +-3 deg
             (print)
          )
         (mapcar 'dtor '(2 2.9 3 87 87.9 92 92.9 94 176 176.9 177 182 182.9 183 267 267.9 268 272 272.9 273 357 357.9 359))
  )
  (princ)
  )

PS, yes the "Double" got me. :oops:
« Last Edit: March 01, 2007, 10:11:55 AM by CAB »
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.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Check line for accuracy
« Reply #33 on: March 01, 2007, 01:13:49 PM »
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)
)

Thank you, fools  :-)
Realy nice one, I like it, indeed.
Speaking English as a French Frog