# Help on getting started on cut/fill

I am looking on help on cut/fill volumes on terrain using Ruby. Comfortable with Ruby and plugin development as part of a solar design plugin for the past yest or two. However, I looked in the forum and extension warehouse and just need some help on how to get started.

Scenario is I have a terrain mesh (converted from sandbox tool). Given a flat sloping face which follows the overall terrain gradient, how do I get started on calculation the cut and fill of the dirt to remove/fill to make the terrain flat. I saw Section Plane help, but am not clear how I can use that in Ruby to get the cut/fill volumes.
Any pointers to get started is appreciated.

Got some screenshots? Example models? Concept drawings? Would help to fully understand the question.
Are you looking to only calculate data? Or actually generate/modify geometry?

Calculating Cut and fill and fill is a simple geometry problem. No Section plane needed.
Overall just remember you don’t have to calculate all the individual areas of cut versus fill: just the overall totals.

1. First calc total volume under the original triangular mesh:
a. for each triangle calc area (using only x and y coordinates of vertices) see Area of a triangle (Coordinate Geometry) - Math Open Reference. Multiply area by average z of 3 vertices to get voume.
b accumulate to get total volume under the mesh.
2. Now calc total area under desired plane or proposed mesh.
3. Subtract one total from the other to get net cut or fill.

The larger problem is to design a new plane face which requires no cut or fill.
This is because there are infinite solutions depending on 3D plane angle of the surface you want.

For this you can draw (or generate from the mesh corners) a face close to what you want.
Calculate area under this face within mesh boundaries. Calculate volume under face using average z. Calculate average z needed to get same volume as mesh. Move face up by delta z.

Hi,
I am looking to calculate the cut/fill data only. geometry need not be
modified. I saw this thread were TIG had a diagram explaining it slightly
differently. But could not figure out how to get started.
http://sketchucation.com/forums/viewtopic.php?f=15&t=55103

From a sample, it is just any irregular terrain with small hills and
valleys and what is the cost of doing a cut fill to make it flat uniform
surface. The goal is, try cut/fill keeping a flat surface as reference at a
few heights and minimize cost of cut/fill. reason is in a large piece of
land, the hills/valleys are of different depths. So, for the entire site, I
need to determine the volume of cut/fill of a terrain against a flat
surface placed at different heights and determine the optimum cut/fill for
that site.

OOps, I was replying through gmail and missed Barry’s response. Thanks
Barry, let me try your approach.

Don’t forget the lesson of Archimedes, the king’s crown and the bathtub.

If the terrain mesh tops off a manifold group, then:
http://www.sketchup.com/intl/en/developer/docs/ourdoc/group#volume

If using Pro, boolean operations can be used.

In the “CutFillTerrain.skp” example attached, The red volume (manifold component instance) represents the cut, is named “Cut” and is assigned to layer “Cut”. The aqua volume (manifold component instance) represents the fill, is named “Fill”, and is assigned to layer “Fill”. The brown volume (manifold group) represents a volume with a sloping terrain mesh on top. It is assigned to layer “Terrain”. (Color by layer is activated for display purposes.)

The idea is to move the Cut and Fill volumes around together (perhaps they are glued to each other.) They can be moved up and down until the desired intersection with the terrain is reached.

Then using Pro API boolean methods, a boolean operation is done return that hidden part of the red cut volume that “cuts” into the terrain volume. Then also the hidden part of the aqua fill volume is subtracted leaving that part which lies atop the terrain.

CutFillTerrain.skp (38.4 KB)

This could be done off to the side, on a copy of the terrain group.

Great! Thanks for the sample. It is much easier to work with and try it out.

Actually I just notice this method in the API:
Geom.fit_plane_to_points
http://www.sketchup.com/intl/en/developer/docs/ourdoc/geom#fit_plane_to_points
You could try this out to get your starting plane,
then intersect the plane with your XY extents to get a face parallel to the plane,
then move the face vertically to get equal volume to the original mesh.

Thanks for pointing this API. Never noticed it too. That could help in
getting my parallel plane and getting the volume as you suggested.