Author Topic: Two points that are the same - but not equal?..!  (Read 5105 times)

0 Members and 1 Guest are viewing this topic.

Paul Munford

  • Guest
Two points that are the same - but not equal?..!
« on: January 23, 2008, 02:24:01 PM »
This one has me stumped... I would welcome comment from anyone that has seen this before.

The attached routine dimensions the major and minor axis of ellipses. It doesn't allways work, however. This seems to be a problem with the Minor points of the Ellipse and the osnap quadrent points of the minor axis.

Although both variables contain the same point list, the equal function returns 'Nil'... Help!

Code: [Select]
;Ellipsedim
;a routine for dimensioning the major and minor axis of ellipses
;Paul Munford - work in progress

;Subroutines

(defun DTR (a) ;degrees to radians function
(* pi (/ a 180.0))
);defun

(defun RTD (r) ;degrees to radians function
(* 180.0 (/ r pi))
);defun

(defun C:ellipsedim ()

(setq PickData (nentsel "\nPick an Ellipse")) ;Pick an ellipse
(setq ObjID (car PickData)) ;Get its entity name
(setq EntList (entget ObjID)) ;List its properties

(setq Cpt(cdr(assoc 10 Entlist))) ;find the centre point - in wcs
(setq Mj (cdr(assoc 11 Entlist))) ;Find the major axis  - in ocs
(setq Ratio (cdr (assoc 40 Entlist))) ;Find the ratio betwhen the major and minor axes

(setq Mjpt1 (list ;Find the Major axis point by...
      (+ (nth 0 cpt)(nth 0 Mj)) ;...adding the Centre point in wcs to...
      (+ (nth 1 cpt)(nth 1 Mj)) ;...the major axis in ocs
      (+ (nth 2 cpt)(nth 2 Mj))
      )
      )

(setq Mjpt2 (list ;Find the opposite major axis point...
      (- (nth 0 cpt)(nth 0 Mj)) ;..by taking the major axis in ocs...
      (- (nth 1 cpt)(nth 1 Mj)) ;...away from the centre point in wcs
      (- (nth 2 cpt)(nth 2 Mj))
      )
      )

(setq Major (distance cpt Mjpt1)) ;Find the length of the major axis
(setq Minor (* Major Ratio)) ;find the length of the minor axis by...
;...dividing the major axis by the ratio
(setq Majang (angle cpt Mjpt1))
(setq Mipt1 (polar cpt (+ Majang (dtr 90)) minor))
(setq Mipt2 (polar cpt (+ Majang (dtr 270)) minor))

(setq quapt (osnap (nth 1 Pickdata)  "_qua")) ;find the nearest quadrent osnap

(if (or (equal quapt Mjpt1) ;if the qudrent snap equals...
(equal quapt Mjpt2))
;...either or the two major axis points
  (cond
    ((= (car Mjpt1)(car Mjpt2)) ;if the x coordinates of the major points are equal
    (command "._dimlinear" Mjpt1 Mjpt2 "h" pause)) ;add horizontal dimension
      ((= (cadr Mjpt1)(cadr Mjpt2)) ;if the y coordinates of the major points are equal
    (command "._dimlinear" Mjpt1 Mjpt2 "v" pause)) ;add vertical dimension
((T nil ;otherwise...
   (command "._dimaligned" Mjpt1 Mjpt2 pause))) ;add aligned dimension
  );end of cond
  );end of if

[color=red](if (or (equal quapt Mipt1) ;if the qudrent snap equals...
(equal quapt Mipt2)) ;...either or the two minor axis points[/color]
  (cond
    ((= (car Mipt1)(car Mipt2)) ;if the x coordinates of the minor points are equal
    (command "._dimlinear" Mipt1 Mipt2 "h" pause)) ;add horizontal dimension
      ((= (cadr Mipt1)(cadr Mipt2)) ;if the y coordinates of the minor points are equal
    (command "._dimlinear" Mipt1 Mipt2 "v" pause)) ;add vertical dimension
((T nil ;otherwise...
   (command "._dimaligned" Mipt1 Mipt2 pause))) ;add aligned dimension
  );end of cond
  );end of if
 )

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Two points that are the same - but not equal?..!
« Reply #1 on: January 23, 2008, 02:43:29 PM »
Use a "fuzz" factor. 
(setq fuzz 0.0001)
;;if things are within 1/10000 of the same then they are, for all intents and purposes, equal. Adjust to suit

(equal quapt Mjpt1 fuzz)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Two points that are the same - but not equal?..!
« Reply #2 on: January 23, 2008, 02:55:00 PM »
Without actually looking at your code I'm guessing it's a fuzz factor issue, that is, there are, relatively speaking, differences insiginificant to you, yet mathematically significant to the unadorned equal function for one or more ordinates of the points.

The solution is to use the equal function's optional fuzz factor and apply it on an ordinate by ordinate basis, rather than simply comparing the list of ordinates as a composite value.

It's been done a million times, and I'm sure the first AutoCAD centric solution, and definitive one to boot was penned by Mr. Tanzillo. I've not the time or interest in finding said definitive solution and reposting. Rather, here's a quick offering that you an use as a starting point to be improved upon:

Code: [Select]
(defun _PointsEqualP ( point1 point2 fuzz )
    (vl-every
       '(lambda ( a b ) (equal a b fuzz))
        point1
        point2
    )
)

Quote from: AutoCAD command line
Command: (_PointsEqualP '(1 1) '(1 0.9) 0.01) nil

Command: (_PointsEqualP '(1 1) '(1 0.99) 0.01) nil

Command: (_PointsEqualP '(1 1) '(1 0.999) 0.01) T

For what it's worth / hope it helps.

Doh: Someone snuck in as I went to post this; posting anyway. If superfluous / a repeat please accept my apology.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Two points that are the same - but not equal?..!
« Reply #3 on: January 23, 2008, 04:28:39 PM »
One more way: 8-)
Code: [Select]
(< (distancel quapt Mjpt1) fuzz)
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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Two points that are the same - but not equal?..!
« Reply #4 on: January 23, 2008, 07:56:19 PM »
One more way: 8-)
Code: [Select]
(< (distance quapt Mjpt1) fuzz)

Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Two points that are the same - but not equal?..!
« Reply #5 on: January 23, 2008, 08:42:40 PM »
I don't know which is worser, my spelling or my typing.  :|
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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Two points that are the same - but not equal?..!
« Reply #6 on: January 23, 2008, 09:04:55 PM »
Good tihng I nveer epxreeicne tpyo porlbmes.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Two points that are the same - but not equal?..!
« Reply #7 on: January 23, 2008, 09:15:04 PM »
.............  Rather, here's a quick offering that you an use as a starting point to be improved upon:

Code: [Select]
(defun _PointsEqualP ( point1 point2 fuzz )
    (vl-every
       '(lambda ( a b ) (equal a b fuzz))
        point1
        point2
    )
)

very elegant Michael !
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Two points that are the same - but not equal?..!
« Reply #8 on: January 23, 2008, 09:31:03 PM »
Nice of you to say KB but I'd have a hard time believing it's not been posted before as noted in my first post. That said I like the brevity of Alan's offering.

Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Two points that are the same - but not equal?..!
« Reply #9 on: January 23, 2008, 11:59:57 PM »
And I think I picked up the distance method form TT.  8-)
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: Two points that are the same - but not equal?..!
« Reply #10 on: January 24, 2008, 01:59:57 AM »
.............  Rather, here's a quick offering that you an use as a starting point to be improved upon:

Code: [Select]
(defun _PointsEqualP ( point1 point2 fuzz )
    (vl-every
       '(lambda ( a b ) (equal a b fuzz))
        point1
        point2
    )
)

very elegant Michael !

Why not using directly the equal function ?

(equal '(1 1) '(1 0.9) 0.01) --> nil
(equal '(1 1) '(1 0.99) 0.01) --> nil
(equal '(1 1) '(1 0.999) 0.01) --> T
« Last Edit: January 24, 2008, 02:10:07 AM by gile »
Speaking English as a French Frog

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Two points that are the same - but not equal?..!
« Reply #11 on: January 24, 2008, 04:51:38 AM »
Why not using directly the equal function ?

(equal '(1 1) '(1 0.9) 0.01) --> nil
(equal '(1 1) '(1 0.99) 0.01) --> nil
(equal '(1 1) '(1 0.999) 0.01) --> T


Code: [Select]
(equal '(1 1) '(1 0.990000001) 0.01) --> T

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Two points that are the same - but not equal?..!
« Reply #12 on: January 24, 2008, 08:35:37 AM »
Why not using directly the equal function ?

Because I suffer from classic over engineeringitus?



I aplogize for my ineptitude, especially to the orginal poster.
« Last Edit: January 24, 2008, 10:08:31 AM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

daron

  • Guest
Re: Two points that are the same - but not equal?..!
« Reply #13 on: January 24, 2008, 09:10:50 AM »
MP, you kill me. over engineeringitus. :lmao:

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Two points that are the same - but not equal?..!
« Reply #14 on: January 24, 2008, 09:15:28 AM »
Over engineering terminosis is probably more appropriate because it will likely kill me one day.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Two points that are the same - but not equal?..!
« Reply #15 on: January 24, 2008, 09:21:38 AM »
Code: [Select]
(equal 1 0.99 0.01)
(< (abs(- 1 0.99)) 0.01)
(equal 1 0.99001 0.01)
(< (abs(- 1 0.99001)) 0.01)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Two points that are the same - but not equal?..!
« Reply #16 on: January 24, 2008, 10:03:38 AM »
Why not using directly the equal function ?

Because I suffer from classic over engineeringitus?



I aplogize for my ineptitude, especially to the orginal poser.

Why is Paul a poser?  :-D

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Two points that are the same - but not equal?..!
« Reply #17 on: January 24, 2008, 10:08:06 AM »
Why is Paul a poser?  :-D

Damn! Purely unintentional I assure you!  :-o

Fixed (thanks for the good eye).
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Two points that are the same - but not equal?..!
« Reply #18 on: January 24, 2008, 10:11:13 AM »
Feels good to be not alone. :lmao:
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.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Two points that are the same - but not equal?..!
« Reply #19 on: January 24, 2008, 10:20:57 AM »
Why is Paul a poser?  :-D

Damn! Purely unintentional I assure you!  :-o

Fixed (thanks for the good eye).

 :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Paul Munford

  • Guest
Re: Two points that are the same - but not equal?..!
« Reply #20 on: January 26, 2008, 03:55:10 PM »
Uh, I had a few days of... I'm glad you guys have been having fun in my abscence! Thanks for the tips. I will try them out and see how I get on :-)

Paul Munford

  • Guest
Re: Two points that are the same - but not equal?..!
« Reply #21 on: January 29, 2008, 03:13:20 PM »
Good call! Fuzz factor does the trick for me... Works like a charm :->