Author Topic: How find of center of a random object?  (Read 733 times)

0 Members and 1 Guest are viewing this topic.

Vikram

  • Newt
  • Posts: 42
How find of center of a random object?
« on: January 22, 2020, 02:14:45 AM »
Is there any lisp or method to get center of a random object?
I want to find the center of an object and move its center to the 0,0 axis as I have shown it in the pic.


Lee Mac

  • Seagull
  • Posts: 12373
  • London, England
Re: How find of center of a random object?
« Reply #1 on: January 22, 2020, 08:17:58 AM »
I'm not sure why this is posted in the DCL forum.

Are you looking for the center of the bounding box or the centroid?

Vikram

  • Newt
  • Posts: 42
Re: How find of center of a random object?
« Reply #2 on: January 22, 2020, 11:51:37 PM »
I want center of the bounding box

But to get center of mass how can I do it?

My post is on AutoLisp forum

Tharwat

  • Swamp Rat
  • Posts: 525
  • Hypersensitive
Re: How find of center of a random object?
« Reply #3 on: January 23, 2020, 01:54:56 AM »
I want center of the bounding box

But to get center of mass how can I do it?

The following would get the center of the bounding box of the selected object but to get the Centroid of a curved object, you need to convert it to region object in prior of getting the Centroid property of it.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:ctr (/ sel lft rgt mid)
  2.   ;; Tharwat - 23.Jan.2020      ;;
  3.   (and
  4.     (setq sel (car (entsel "\nPick an object : ")))
  5.     (or
  6.              (setq obj (vlax-ename->vla-object sel))
  7.              'GetBoundingBox
  8.            )
  9.            (progn (vla-getboundingbox obj 'lft 'rgt)
  10.                   (setq mid (mapcar '(lambda (p q) (/ (+ p q) 2.0)) (vlax-safearray->list lft)
  11.                                                (vlax-safearray->list rgt)
  12.                             )
  13.                   )
  14.            )
  15.       )
  16.       (alert
  17.         "The method 'Getboundingbox' isn't appplicable on the picked object <!>"
  18.       )
  19.     )
  20.   )
  21.   (if mid
  22.     (entmake (list '(0 . "POINT") (cons 10 mid)))
  23.   )
  24.  
  25.  
« Last Edit: January 23, 2020, 02:50:24 AM by Tharwat »

Vikram

  • Newt
  • Posts: 42
Re: How find of center of a random object?
« Reply #4 on: January 23, 2020, 02:31:01 AM »
I tried your lisp but Im not getting the center of the object I'm getting output (66594.1 1.678e+006) which is out of the bound. Please refer to the drawing I have attached to this reply.

My main motive is to shift the center of the bound box to 0,0 position. Like datum feature in NX cam.

I googled a bit and Geometric center can help me but I'm using AutoCAD 2012 and the feature is added in 2016

PS: I have tried this on AutoCAD and not IntelliCAD
« Last Edit: January 23, 2020, 02:54:46 AM by Vikram »

Tharwat

  • Swamp Rat
  • Posts: 525
  • Hypersensitive
Re: How find of center of a random object?
« Reply #5 on: January 23, 2020, 02:53:08 AM »
Yeah you are right, actually I used the multiply symbol instead of summation symbol.
I have revised the codes above and added a line of codes to create a point at the mid point of the bounding box border.

Vikram

  • Newt
  • Posts: 42
Re: How find of center of a random object?
« Reply #6 on: January 23, 2020, 03:16:32 AM »
Its still not working mate. Can you try it on yourself on the drawing I have attached?
I got the centeroid of that object by converting it into region and using MASSPROP. But Im not sure if that is the exact geometrical center.

I'm confused between geometrical center and centeroid. Whats the difference?

ronjonp

  • Needs a day job
  • Posts: 7126
Re: How find of center of a random object?
« Reply #7 on: January 23, 2020, 11:54:37 AM »
Its still not working mate. Can you try it on yourself on the drawing I have attached?
I got the centeroid of that object by converting it into region and using MASSPROP. But Im not sure if that is the exact geometrical center.

I'm confused between geometrical center and centeroid. Whats the difference?
Tharwats code returns the midpoint of the bounding box ( red ) and you want the centroid ( green ). Have you seen this? http://www.theswamp.org/index.php?topic=46820.msg518432#msg518432
Many examples with a Google search: centroid site:theswamp.org
« Last Edit: January 23, 2020, 12:08:18 PM by ronjonp »

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

Vikram

  • Newt
  • Posts: 42
Re: How find of center of a random object?
« Reply #8 on: January 24, 2020, 04:52:59 AM »
Thanks for the information!

ronjonp

  • Needs a day job
  • Posts: 7126
Re: How find of center of a random object?
« Reply #9 on: January 24, 2020, 10:01:01 AM »
Thanks for the information!
You're welcome. :-)

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC