Author Topic: Area enclosed by a polyline script  (Read 30451 times)

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Area enclosed by a polyline script
« on: June 19, 2014, 20: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

« Last Edit: June 20, 2014, 12:28:22 pm by lloydsp »
"Pyro for Fun and Profit for More Than Fifty Years"

Offline macbob

  • Storm Trooper
  • ***
  • Posts: 189
    • View Profile
    • Bob Mackay
Re: Area enclosed by a polyline script
« Reply #1 on: June 19, 2014, 22:45:22 pm »
http://en.wikipedia.org/wiki/Shoelace_formula

Sorry - I had to look it up!

Bob

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: Area enclosed by a polyline script
« Reply #2 on: June 19, 2014, 22: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
"Pyro for Fun and Profit for More Than Fifty Years"

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: Area enclosed by a polyline script
« Reply #3 on: June 20, 2014, 01: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, 12:29:09 pm by lloydsp »
"Pyro for Fun and Profit for More Than Fifty Years"

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1826
    • View Profile
Re: Area enclosed by a polyline script
« Reply #4 on: June 20, 2014, 02:27:19 am »
Works fine, Tested some objects against DraftSight  Area/perimeter Tools for comparison.
Dave.

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: Area enclosed by a polyline script
« Reply #5 on: June 20, 2014, 10: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
"Pyro for Fun and Profit for More Than Fifty Years"

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: Area enclosed by a polyline script
« Reply #6 on: June 20, 2014, 12: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
"Pyro for Fun and Profit for More Than Fifty Years"

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: Area enclosed by a polyline script
« Reply #7 on: June 20, 2014, 14: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
"Pyro for Fun and Profit for More Than Fifty Years"

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: Area enclosed by a polyline script
« Reply #8 on: June 20, 2014, 23:57:20 pm »
Hello Lloyd

Nice job  :D (but I realy don't understand the math formulas on the wiki  :o  :-[)

++
David

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1826
    • View Profile
Re: Area enclosed by a polyline script
« Reply #9 on: June 21, 2014, 00: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.

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: Area enclosed by a polyline script
« Reply #10 on: June 21, 2014, 00: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
"Pyro for Fun and Profit for More Than Fifty Years"

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: Area enclosed by a polyline script
« Reply #11 on: June 21, 2014, 00: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
"Pyro for Fun and Profit for More Than Fifty Years"

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5262
  • Made in England
    • View Profile
Re: Area enclosed by a polyline/rectangle/circle/spline plugin
« Reply #12 on: July 28, 2017, 19: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, 19:46:11 pm by EddyCurrent »
Filmed in Supermarionation

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: Area enclosed by a polyline script
« Reply #13 on: August 03, 2017, 17: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, 17:33:19 pm by dh42 »

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: Area enclosed by a polyline script
« Reply #14 on: August 03, 2017, 17: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
"Pyro for Fun and Profit for More Than Fifty Years"