CamBam
News:
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 26, 2017, 06:25:16 am


Login with username, password and session length


Pages: [1] 2
  Print  
Author Topic: Area enclosed by a polyline script  (Read 4898 times)
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 7086



View Profile
« on: June 19, 2014, 21:40:02 pm »

Ok... I DID have the time, because I had a long job running, had all today's design work done, and was only listening for cutters hitting the clamps!

The attached script and sample file explores calculating the enclosed area of an irregular polyline, and calculates its perimeter length, as well.

It uses the ancient "Surveyor's formula".

It presently only works on polys consisting entirely of line segments, and they must be closed polys.

Some work could be done to manage calculating the segment of a circle in order to handle arcs, as well; but I really don't have time for that.

So, if you have a polyline which has arcs in it, do a "remove arcs" on it before trying this.

It will bark at you for un-closed polylines, or those containing any arcs.

Just unzip the file, and place the resulting .vbs file in your CamBam/System/Scripts folder.

Below.  Updated 06/20/14 for any closed shape, including circles, and change the name, since it no longer requires polylines, only closed shapes.

LLoyd


* Area inside an object.zip (1.59 KB - downloaded 346 times.)
* Surveyors test.cb (4.27 KB - downloaded 134 times.)
« Last Edit: June 20, 2014, 13:28:22 pm by lloydsp » Logged

"Pyro for Fun and Profit for More Than Fifty Years"
macbob
Storm Trooper
***
Offline Offline

Posts: 179



View Profile WWW
« Reply #1 on: June 19, 2014, 23:45:22 pm »

http://en.wikipedia.org/wiki/Shoelace_formula

Sorry - I had to look it up!

Bob
Logged
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 7086



View Profile
« Reply #2 on: June 19, 2014, 23:57:26 pm »

<G>

It's really a simple algorithm.  I'm looking at ways to handle arc segments, also.  It's not that hard, but will take some thoughtful coding to make sure it's accurate, and properly handles the bulges.


Lloyd
Logged

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

Posts: 7086



View Profile
« Reply #3 on: June 20, 2014, 02:45:52 am »

Updated...
It was WAY simpler to deal with arcs than I expected.

Updated version and testing .cb file below.  Now handles any closed polyline (although I have not tested what happens with overlaps and/or crossovers....)

LLoyd

ps have removed attachments for all but the first post.  Updates are there.
« Last Edit: June 20, 2014, 13:29:09 pm by lloydsp » Logged

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

Posts: 771


View Profile
« Reply #4 on: June 20, 2014, 03:27:19 am »

Works fine, Tested some objects against DraftSight  Area/perimeter Tools for comparison.
Dave.
Logged
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 7086



View Profile
« Reply #5 on: June 20, 2014, 11:49:21 am »

Thanks, Dave.  That's good confirmation.

I might add that to the toolbar as a plugin.  My most frequent use of it would be to calculate the weights of various parts.

Many of my mechanisms have 'balanced' parts, or use scales the limits of which can be exceeded if the weights of holders, etc. become too much.

It's easy to calculate the mass of a regular shape, but not oddball geometries.

LLoyd
Logged

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

Posts: 7086



View Profile
« Reply #6 on: June 20, 2014, 13:30:50 pm »

Updated again (in top post of thread).

More testing added for types, circles now handled.

Except for any possible bugs, I _think_ this is as far as this needs to go until it's made into a plugin.

Please test.  Suggestions welcome.

LLoyd
Logged

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

Posts: 7086



View Profile
« Reply #7 on: June 20, 2014, 15:10:57 pm »

BTW,
Upon thinking of the potentials for this, I think it could be turned into a general-purpose function to calculate areas, volumes, and mass based upon specific densities of materials.

I'll work on that as time permits.  Ideas?

Lloyd
Logged

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

Posts: 4628



View Profile WWW
« Reply #8 on: June 21, 2014, 00:57:20 am »

Hello Lloyd

Nice job  Cheesy (but I realy don't understand the math formulas on the wiki  Shocked  Embarrassed)

++
David
Logged
dave benson
CNC Jedi
*****
Offline Offline

Posts: 771


View Profile
« Reply #9 on: June 21, 2014, 01:09:20 am »

Lloyd 
Yes I think to add these functions to CamBam would good idea, As I've often had to use other programs
to do just that.
Perhaps you could incorporate a user editable .txt file for the material densities, And you would need
to supply the 2D objects with a thickness (or Z value ) to calculate the volume from a popup window.
Dave.
Logged
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 7086



View Profile
« Reply #10 on: June 21, 2014, 01:10:08 am »

Thanks, David.

The formula is a lot simpler than you can make it in your mind.  All it does is divide up the whole object into little right triangles, and sum their area.

I'm working up some concept documents to turn this into an area/volume/mass calculator for 2D objects.

Lloyd
Logged

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

Posts: 7086



View Profile
« Reply #11 on: June 21, 2014, 01:12:35 am »

Yes, Dave.

The concept already includes a data file for densities of common materials, plus the ability to edit it.

Since I don't intend to take this past 2.5D, it will be necessary for the user to enter the material thickness.

I've written some plugins that use user-input boxes, so that shouldn't be a problem.


Thanks for the input.

Lloyd
Logged

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

Posts: 3066



View Profile
« Reply #12 on: July 28, 2017, 20:18:47 pm »

So, on another wet day (they don't call it the "Lake District" for nothing), for something semi interesting to do, I made this into a plugin and added Splines to the objects it can handle.
It appears in the 'Tools' menu as "Area"
Lloyd, what was the crack with your planned additions re volume and mass ?

Edit: attachment removed see later post.
« Last Edit: August 05, 2017, 20:46:11 pm by EddyCurrent » Logged
dh42
Administrator
CNC Jedi
*****
Offline Offline

Posts: 4628



View Profile WWW
« Reply #13 on: August 03, 2017, 18:28:03 pm »

Hello eddy

I just try this plugin before to add it to the web site and I fall on a bug ; if you select an open polyline then run the plugin, you first get "Drawing object ID#x is not closed: skipped', then when you click OK, a second message appears ; 'There were no closed objects selected', then after clicking OK, CB run in an infinite loop (Cambam is thinking) and I can't cancel the job, except by closing CB. (tested on V1.0 R13)

++
David

Edit: texts are not translatable (except the menu, of course)
« Last Edit: August 03, 2017, 18:33:19 pm by dh42 » Logged
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 7086



View Profile
« Reply #14 on: August 03, 2017, 18:40:41 pm »

Nothing yet, Eddie.  I did some searching the other evening, but didn't find the mass/density tables I _thought_ I intended to use. 

In the middle of a four-day 'rush job' right now, but as soon as I spring free, I'll do some more looking-around.

Lloyd
Logged

"Pyro for Fun and Profit for More Than Fifty Years"
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines

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

Copyright © 2008 HexRay Ltd. | Sitemap