CamBam

Resources => Scripts and Plugins => Topic started by: lloydsp on January 05, 2013, 00:43:35 am



Title: Finding center of mass
Post by: lloydsp 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


Title: Re: Finding center of mass
Post by: blowlamp 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.


Title: Re: Finding center of mass
Post by: lloydsp 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


Title: Re: Finding center of mass
Post by: lloydsp 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


Title: Re: Finding center of mass
Post by: Rodneyk 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.


Title: Re: Finding center of mass
Post by: lloydsp 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


Title: Re: Finding center of mass
Post by: Rodneyk 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.


Title: Re: Finding center of mass
Post by: lloydsp 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


Title: Re: Finding center of mass
Post by: Rodneyk 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.




Title: Re: Finding center of mass
Post by: Rodneyk 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 :)

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


Title: Re: Finding center of mass
Post by: lloydsp on January 13, 2013, 18:17:46 pm
Wow!  You are not only a fast coder, but fast at finding problems!  Thanks!

LLoyd


Title: Re: Finding center of mass
Post by: Rodneyk 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 (https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4DFD56ADQNUS8)


Title: Re: Finding center of mass
Post by: lloydsp 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


Title: Re: Finding center of mass
Post by: Rodneyk 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.


Title: Re: Finding center of mass
Post by: Rodneyk 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.





Title: Re: Finding center of mass
Post by: lloydsp on January 14, 2013, 11:16:38 am
Hmmmm????  Same error, exactly.  I was careful to remove the old instance of centroid.dll before installing the new one, and its new help file.


and, confirming from the error details:
----------------------------------------
Centroid
    Assembly Version: 1.2.0.0
    Win32 Version: 1.2.0.0
    CodeBase: file:///C:/Program%20Files/CamBam%20plus%200.9.8/plugins/Centroid.dll
----------------------------------------

LLoyd


Title: Re: Finding center of mass
Post by: lloydsp on January 14, 2013, 11:52:59 am
PS...
CamBam.info just came back up.  I downloaded rc7, and it works with centroid 1.2.

I'm guessing the change you intended didn't get into 1.2, after all.

LLoyd


Title: Re: Finding center of mass
Post by: Rodneyk on January 14, 2013, 14:27:40 pm
PS...
CamBam.info just came back up.  I downloaded rc7, and it works with centroid 1.2.

I'm guessing the change you intended didn't get into 1.2, after all.

LLoyd


Darn, I think I understand. The exception is coming up before it even gets to the code that uses the method. So my fix does not have a chance to work.  I could remove the reference to Remove Arcs altogehter and just depend on my own function (I wanted to avoid that because my function does not enter uniform data points and cambam's does).  If there is a demand for this on R6 I will do just that...




Title: Re: Finding center of mass
Post by: Rodneyk on January 17, 2013, 06:22:59 am
IF using RC 6 is important to anyone I think I can make it work by removing the dependancy on the method in cambam.  Code is written but it no one wants it I will not release it...


Title: Re: Finding center of mass
Post by: lloydsp on January 17, 2013, 12:11:01 pm
I think rc7 is at least as stable as rc6.  It fixed a few bugs, added some features, and didn't seem to create any new 'undocumented features'.

LLoyd


Title: Polite request Re: Finding center of mass
Post by: nifty1a on December 03, 2018, 21:47:31 pm
Is there any chance that someone could recompile the Centroid plugin for CB+ v1.0 please?


Title: Re: Polite request Re: Finding center of mass
Post by: dh42 on December 03, 2018, 22:26:52 pm
Is there any chance that someone could recompile the Centroid plugin for CB+ v1.0 please?

Hello

It is working on V1 too ; no need to recompile.

++
David


Title: Re: Finding center of mass
Post by: nifty1a on December 05, 2018, 13:51:48 pm
Thanks David..

OK... it was my inexperience with Windows 10 on my new laptop...
The cause of my issue was that the .dll file I had dropped into the plugins folder was 'blocked'...
The error message in CamBam (How do I copy and paste from that window?) said something about network location, sandboxing, version of .NET framework and CAS policy..

All sorted now, thanks again...



Title: Re: Finding center of mass
Post by: dh42 on December 05, 2018, 15:24:11 pm
Hello

Ah yes, the "security"  ::)

more info here (and the problem exist also on W7, not only on W10)

http://www.cambam.co.uk/forum/index.php?topic=6294.0

Fortunately, I never had this problem because I unzip my files with "Winrar" that have the good idea to automatically unblock the unziped files ...

++
David