CamBam
News:
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 15, 2019, 15:31:30 pm


Login with username, password and session length


Pages: [1] 2
  Print  
Author Topic: Finding center of mass  (Read 11365 times)
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 8051



View Profile
« on: January 05, 2013, 00:43:35 am »

Does anyone have a script that will find the center of mass of a plane shape with holes (not necessarily centered on any axes) missing from the object?

Thanks,
Lloyd
Logged

"Pyro for Fun and Profit for More Than Fifty Years"
blowlamp
CNC Jedi
*****
Offline Offline

Posts: 1183


View Profile
« Reply #1 on: January 05, 2013, 00:52:09 am »

There's nothing that I know of in CamBam, but there is in ViaCAD (if you still have it), under Menu > Verify > Properties...


Martin.
Logged
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 8051



View Profile
« Reply #2 on: January 05, 2013, 00:59:21 am »

I do still have it, Martin.  Thanks... again, one of those features I've never explored enough to remember what's there.

LLoyd
Logged

"Pyro for Fun and Profit for More Than Fifty Years"
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 8051



View Profile
« Reply #3 on: January 05, 2013, 01:53:43 am »

And... that did the trick.  Thanks much for reminding me I had a tool.
I see a need for me to do this quite a lot in future.  The ViaCad way is tedious.  First export the shapes from CB and import them in ViaCad, or draw them in ViaCad and export to CB...  Then make sure any imports are converted to polygons, then find the center of mass...

I believe I will have to think about this and write a script to do it more easily.  Maybe just some automation for ViaCad, or maybe a stand-alone.

LLoyd
Logged

"Pyro for Fun and Profit for More Than Fifty Years"
Rodneyk
Droid
**
Offline Offline

Posts: 62


View Profile
« Reply #4 on: January 12, 2013, 18:53:26 pm »

Can you supply an example file so I understand what you mean? Happy to try and write a plugin for it once I know exactly what you are looking for.
Logged
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 8051



View Profile
« Reply #5 on: January 12, 2013, 21:53:57 pm »

Rodney,
Working with strictly a "uniform thickness" 2-D shape that may have holes in it, my intention is to seek the center of balance of a part -- truly, the center of mass.


I was able to do that with ViaCad, but it would be a useful tool in CB, as well.

Below is an example.  Just a simple rectangle with an oddly-shaped draft in one end.

The reason is that I have a part (frequently do) that cannot tip even under its own weight, and thus it must be anchored on its support right at the center of balance.

Because this is not a heavily used feature by me or others, it might be a better candidate for a script, but it would certainly do no harm to be a plug-in.


Thanks,
Lloyd

* Sliding pallet only for CG calcs.cb (4.89 KB - downloaded 213 times.)
Logged

"Pyro for Fun and Profit for More Than Fifty Years"
Rodneyk
Droid
**
Offline Offline

Posts: 62


View Profile
« Reply #6 on: January 13, 2013, 04:19:36 am »

Okay here you go.

To make thing simple for the plugin it has a few constraints:
1). This largest object is the Solid object
2). All other objects are considered "holes".
3). No objects with self intersecting lines (Bow ties, figure 8s, and the like).
4). The plugin should handle polylines, Regions, and even text (as long as my code can convert it to polylines).
5). I have checked the math and it appear correct to me, but it has been a while since I played with this stuff.
6). It only uses the 2D data of any objects past to it. It does not fine the center of MASS but the center of weighted area.

Sorry I won't be releasing the source on this one as it contains a LOT of code from my companies libraries and would not make a good sample for writing a plugin.


* CentroidIcon.png (1.32 KB, 48x48 - viewed 814 times.)
* Centroid.1.1.zip (8.05 KB - downloaded 231 times.)
« Last Edit: January 13, 2013, 17:16:57 pm by Rodneyk » Logged
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 8051



View Profile
« Reply #7 on: January 13, 2013, 13:53:46 pm »

Thanks.
Problem.

With a circle or rectangle centered about zero, the centroid is at zero/zero, also.

A 'rounded bar' (two circles with joining tangents, broken at intersections, and re-joined), moves the centroid slightly right of center if the bar was created horizontally, centered about x and y.

A 'dumbell' made the same way, but with a joining thin bar, moves the centroid WAY right.

I re-ordered the points list on the dumbell, so that the "starting point" was different, and it did not change the centroid.  I then rotated the shape 180 degrees.  That did move the centroid to the other side.

I think it has to do not with the starting point, but perhaps where the algorithm starts determining the surface area.

LLoyd

* Centroid tests.cb (5.43 KB - downloaded 209 times.)
Logged

"Pyro for Fun and Profit for More Than Fifty Years"
Rodneyk
Droid
**
Offline Offline

Posts: 62


View Profile
« Reply #8 on: January 13, 2013, 16:43:18 pm »

A problem is that Cambam circles are really arc with bulge paramters. The algorithm I am using is only aware of real verticies and the bulge means nothing.  See the image. This is what it sees for the HRounded bar object.

I wil look into this, I think Andy sent me an email with more details about getting the real points from polygons... Another option (temporarily) would be to use the polygon plugin I made and set the number of verticies high to simulate a circle.  Not as smooth cutting, but the center would be more accurate for now.




* nobuldge.PNG (47.24 KB, 1165x360 - viewed 437 times.)
Logged
Rodneyk
Droid
**
Offline Offline

Posts: 62


View Profile
« Reply #9 on: January 13, 2013, 17:23:21 pm »

Okay, I have updated the code to take the buldges into account. Also added rounding (at the 9th decimal place) because in doubles 1.748930280e-10 is damn close to 0. (if you want more accuracy than that we need to talk about how the heck you get a cnc that accurate Smiley

For all the example you sent I am now getting (0,0,0) as the center of mass with the new plugin.  The plugin is attached to the original post where I put the previous version.

Enjoy
Logged
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 8051



View Profile
« Reply #10 on: January 13, 2013, 18:17:46 pm »

Wow!  You are not only a fast coder, but fast at finding problems!  Thanks!

LLoyd
Logged

"Pyro for Fun and Profit for More Than Fifty Years"
Rodneyk
Droid
**
Offline Offline

Posts: 62


View Profile
« Reply #11 on: January 13, 2013, 18:55:23 pm »

I do try to please. As soon as I saw your examples I had a pretty good idea what the issue was.  Luckily I had structured the code so that fix could be applied in one spot and I found a method in cambam that did most of the work. 

I will gladly accept "donations" for the plugin at:
 https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4DFD56ADQNUS8
Logged
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 8051



View Profile
« Reply #12 on: January 13, 2013, 19:06:29 pm »

And gladly...

On RC6, I get this:

"Unhandled exception has occurred.....

Method not found: 'CamBam.CAD.Polyline.CamBam.CAD.Polyline.RemoveArcs(Double)' "

Lloyd
Logged

"Pyro for Fun and Profit for More Than Fifty Years"
Rodneyk
Droid
**
Offline Offline

Posts: 62


View Profile
« Reply #13 on: January 13, 2013, 20:03:07 pm »

I guess this is a new feature he added in RC-7. Sorry if you want this functionality you will need to use RC7.
Logged
Rodneyk
Droid
**
Offline Offline

Posts: 62


View Profile
« Reply #14 on: January 14, 2013, 04:11:23 am »

Give this a try.  I think it should work with RC6. I think I got the arcs figures out with a bit of work and a very long day... I now understand more about the arc object than I ever wanted to know.




* Centroid.1.2.zip (8.97 KB - downloaded 408 times.)

* CentroidIcon.png (1.32 KB, 48x48 - viewed 757 times.)
Logged
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.133 seconds with 19 queries.

Copyright © 2018 HexRay Ltd. | Sitemap