Author Topic: How can I know if the shapes are the same?  (Read 8976 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: How can I know if the shapes are the same?
« Reply #15 on: February 17, 2009, 01:56:46 PM »
Very nice Ron.

I like your method of calculating the centroid.  Much more concise than mine.

Thanks David :) I like this solution as well for averaging the point list
Code: [Select]
(mapcar '(lambda (x) (/ x (length points))) (apply 'mapcar (cons '+ points))) I grabbed it from somewhere off the swamp....perhaps MP's or Giles code?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

litss

  • Guest
Re: How can I know if the shapes are the same?
« Reply #16 on: February 18, 2009, 08:27:05 AM »
wow, ronjonp, u r fast :)

Quote
Here is how I would group the objects as sublists.
ur way is better. I still have some problems in applying the "mapcar" and "lambda". hard to understand...need to do more homework

Quote
Here is one using David's centroid\vertex distance method...
My way of calculating the centroid is much more complicated and much slower than urs. Do we get the same centroid by these two methods? Here's mine.
Code: [Select]
  (defun centroid (ENT /)
    (command "_REGION" ENT "")
    (setq p1 (vlax-safearray->list (vlax-variant-value
                                                       (vla-get-centroid
                                                                         (vlax-ename->vla-object
                                                                                                 (ENTLAST)
                                                                         )
                                                       )
                                   )
             )
    )
    (entdel (entlast))
    p1
  ) 




ronjonp

  • Needs a day job
  • Posts: 7526
Re: How can I know if the shapes are the same?
« Reply #17 on: February 18, 2009, 09:48:06 AM »
wow, ronjonp, u r fast :)

Quote
Here is how I would group the objects as sublists.
ur way is better. I still have some problems in applying the "mapcar" and "lambda". hard to understand...need to do more homework

Quote
Here is one using David's centroid\vertex distance method...
My way of calculating the centroid is much more complicated and much slower than urs. Do we get the same centroid by these two methods? Here's mine.
....

From my tests they return different results depending on the shape (square\rectangle same) other polygons different. My guess is the centroid function uses more points along the boundary.

You can shorten your routine above by using "vlax-get" since it will return the point and not a variant.

Code: [Select]
(defun centroid (ent /)
  (command "_REGION" ent "")
  (setq p1 (vlax-get (vlax-ename->vla-object (entlast)) 'centroid))
)

Enjoy :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC