## Saturday, December 31, 2011

### Volume Under a Twisted Plane

If you want to know what a twisted plane is, check out my previous post on it.  Basically, a twisted plane is what you get if you take a plane and twist it and the application I have in view is surface modelling.  In that previous post, I developed the equation of this surface as defined by the (x, y, z) coordinates at the 4 corners of a rectangular area (rectangular in plan view).  For review, that equation is

In construction estimation, it is often necessary to measure volumes of material to be excavated or filled in.  To do so, we need to be able to turn elevation and position data into volumes.  A common approach is to find average depths and multiply by the relevant area.  If the depths are different in different areas, the average will need some kind of weighting or the areas treated separately and summed afterwards for a total.  If using a TIN to model a surface, volume calculations are straightforward and fit this idea of using an average depth and multiplying by the area.  (I have the derivation here.)

So, an interesting question that remains, is whether the twisted plane is as well behaved.  The answer is yes, the derivation is straightforward (but tedious to write and is omitted), and the result is

(The result is obtained by integrating z(x, y) for x over [0, length] and then y over [0, width].)

### Field Measurement of Quadrilaterals Using Only a Tape Measure

##### Trapezoids
A common nonrectangular area that needs to me measured in the field is a trapezoid. Sometimes shapes are approximated by a trapezoid, if a rectangle is not considered a reasonable approximation or not easily visualized. The well-known formula for the area of a trapezoid is

where b1 and b2 are the lengths of the two parallel sides and h is the distance between them (measured perpendicularly to the parallel sides, of course). It is noteworthy that the (b1+b2)/2 can be interpreted as the average of the lengths of the parallel sides. This is the length of a line referred to as the median of the trapezoid. In the field, it is often more convenient/faster to measure the median and the height (h, also called the altitude) than to measure both bases and the height. If the location of the median can be “eye-balled” with sufficient precision for the purposes being met, this may increase productivity by decreasing the number of measurements needed. For more information on the trapezoid and the median, see a description here.
There are (at least) two approaches to measuring quadrilaterals when nothing is known about the internal angles or “parallelness” of nonadjacent lines. The following diagram displays both methods.

We can determine the area of this shape by making 5 measurements and produce an exact picture, or by taking 3 measurements and getting an approximate area. Both are “area by triangles” methods.
##### Area by Triangles – Heron Method
If we measure the sides AB, BC, CD, DA, and one of the diagonals (either AC or BD), we can use Heron’s theorem to determine the area of the triangles on either side of the chosen diagonal. We can use the law of cosines and law of sines to determine the angles. Alternatively, a basic AutoCAD drawing using temporary construction-line circles would allow you to determine these results without manual calculations. This would give us a full description of the area. This method also generalizes well to an arbitrary number of sides.
##### Area by Triangles – By Altitude
On the other hand, we could measure the length of a diagonal (say, AC), leave the measuring tape (or a string line) in place and use a second tape measure to measure from the other vertices (B and D) to the diagonal. As long as the accuracy/precision of the result desired is not too high, we can “eye-ball” perpendicular to the diagonal to get the heights of the triangles to an acceptable accuracy. The area calculation is obvious from there. This method involves fewer measurements, minimal extra equipment, and is quicker to calculate, which may make it more efficient for a quadrilateral. It does not generalize to an n-sided figure as easily as the previous method, but could be done with additional string lines used simultaneously.

## Tuesday, December 20, 2011

### Introducing the Twisted Plane

This idea is motivated by something that comes up often in the world of surveying.  Not always do we have simple straight lines, and not always do we have a simple plane.  Here is an example of the situation in plan view:

You may know that three points define a plane and that an arbitrary fourth point, may not be on the same plane.  We can unambiguously define the elevation of every point on the outside of our rectangle by "stringing a line" (which is surveyor-speak for straight interpolation).  We want the elevations we would get if we pulled a string really tight all the way around the outside of the rectangle.  (If you care about the units, call them meters, but they are not really the point of this example.)

What about arbitrary points on the interior of the rectangle?  It is possible to use interpolation schemes to determine the elevation of a point on the interior of a plane such that it will coincide with the plane.  But in the above situation, we have four points that are not coplanar.  A common, and highly adaptable, solution to this problem is to break our region up into triangles.  There are two ways we could do this.

 Case 1
Notice that in case 1 the elevation at the midpoint of the diagonal line would be 100.125 m.

 Case 2
On the other hand, the elevation at the middle of the diagonal line drawn in case 2 would be 100.000 m.

The general case of this sort of procedure - breaking a region up into triangles - is called creating a triangular irregular network (TIN) and is a well established method.  The fact that there may be multiple solutions which are not equivalent does not normally concern us.  We just pick one that works because all we care about is that the water will run.  In a complex plan, it is not uncommon to see the choice of lines given on the plan.  As a surveyor you like to see that as it mean the ambiguity of your job is largely removed.

When it comes to disadvantages, the first thing that is noteworthy about the TIN is that triangles and graders (or their operators) do not like each other very much.  Although the grader is a very versatile machine, it still likes following a line.  Rectangles are ideal.  Look up at case 2 and pretend you're driving a grader, starting from the SW corner and proceeding to the SE corner.  As you approach the SE corner, you have a problem: you've got two edges that you are trying to put the blade against.  This is frankly infeasible.  If this is a very large area (5 miles by 8 miles), we don't care, because the tricky spot is so small compared with the total area.  For a smaller area, this might be significant.  So what happens?  The watchword is "blend", which basically means the grader operator is supposed to figure it out himself and "make it work."

So, can we model this "blending"?  (I don't mean just at the diagonal edge, I want to get rid of that.)  Can we figure out what the math looks like that describes the result which the grader (operator) would produce if given four corner points on a small, rectangular area and told to "blend" and "make it work"?  If we can do this, then we can apply this same method to areas too big for the grader to cover in just one or two passes.  Or apply it to the problem of setting grades on concrete islands that are on such a surface.  I call it a twisted plane and it allows us to completely discard the diagonal line.

A twisted plane is a surface formed by using a line (segment) and "sweeping" laterally while changing its angle (vertically).  The line segment is just like the blade of a grader running from one edge of the rectangle to the opposite side.  If the width of our rectangle was exactly the width of the grader blade, it would begin with north end of the blade at elevation 99.50 m and the south end at 100.00 m at the west edge of the area.  As the grader proceeded to the east the blade would gradually change its vertical angle from having 0.500 m  fall from south to north to having 0.250 m fall from the south to north.  (The realities of grading are somewhat swept under the carpet for the sake of simplicity.)  Here is an attempt to show what the terrain would look like:

 GNU plot of "twisted plane" performed using Maxima

We will now proceed to develop the equation which describes this surface.  Let's start with a fresh diagram that uses variables in it:

For completeness, here are the equations for the elevations of the north, south, east, and west line elevations (we take the south-west corner as the origin):

Now, to determine the elevation at any point on the interior, we can use the west and east lines and do straight interpolation across them like so:

This produces the equation:

If we were to use the north and south lines and interpolate across them instead, we would get:

In both cases the resulting equation is

So, we have a consistent definition with which we can make a surface from four corners of a rectangular area and which can be created with real equipment (a grader) without requiring the operator to interpret, "blend", or "make it work".

There is, however, a disadvantage to using the twisted plane.  It may require frequent adjustment of the blade angle, if this level of detailed adjustment is not important to project goals.  The twisted plane may be best reserved for situations where TINs are troublesome or do not accurately describe the real desired result.  Experience should dictate.

## Monday, December 19, 2011

### 3D AutoCAD – work sequence to eliminate overlapping volumes

There is more than one way to accomplish the above stated goal.  I'm going to focus on using the interfere command.  Let's just draw a few overlapping solids.  You can use any overlapping solids if you want to follow along.  Here I've just created some boxes that overlap:

We don't really like intersecting solids very much - not if we're modelling something real.  Real solid objects don't like to coincide with each other very much and so we want to eliminate the intersections.  If we only want a single piece out of the above, we would use the union command.

But, let's suppose we want to model three different pieces - perhaps because we intend to manufacture and assemble the pieces afterwards.  In that case, we want to remove the offending intersections from one or more of our shapes.  Ideally, we don't want to have to create all such intersections ourselves and then subtract them from the appropriate shapes.  Enter the interfere command:

1. Create and make current a new layer called, say, interfere and use a distinct colour for it.
2. Command line: interfere
3. Select all relevant objects - those which may have intersections you wish to remove.
4. <enter> or <space>
5. <enter> or <space> to implement the default <checK> command
6. Now you'll see:

7.  Uncheck the box that says delete interference objects on Close, and then Close the dialog box.
8.  Turn on selection cycling (the right-most option at the bottom where all of the modes are).
9.  Use the subtract command.
10.  Select the object you want to subtract from and press <enter> or <space>.
11.  Using selection cycling, select relevant the object(s) created from the interfere command:

After subtracting all of the relevant shapes (2 in my case) it looks like this:

Here I've moved it around a bit to show the results more clearly:

## Friday, December 2, 2011

### Why Direction Vectors Are Better Than Slopes

A direction vector is an ordered pair (in 2D) or triple (in 3D) which indicates direction by breaking it up into components that are perpendicular to each other.  A favorite trick of math people is to make the magnitude of this vector equal to 1, but it doesn’t always have to be – you can do a number of things with it even if its magnitude is random.

The first neat thing about direction vectors is that you don’t have to think about the special case of a vertical line.  When we use slopes, we are usually using either the point-slope form of a line or the slope-intercept form of a line.  These, respectively, are

where m is the slope of the line and b is the y-intercept.  In the world of slopes, you can’t deal with this without taking a special case because anything divided by zero is undefined.  For this application, maybe we could denote that as infinity, but infinity does not cooperate with ordinary numbers without a good deal of coaxing.  The workaround is to say x = c, where c is a constant.  More generally, we could use the general form of the equation:

If we had our rise and run for our slope as a and b, respectively, then m = a/b.  But if we put this into the point-slope form we get

If we do it this way, and b = 0, we can skip the whole division by zero thing.  Unless you blinked, you just learned what direction vectors are.  Okay, you probably blinked, so let me put that differently.

The values a and b are the components of our direction vector which can be expressed as (b, a).  The most fun thing we can do with a direction vector is rotate it.  For example, to rotate this vector counter-clockwise 90°, we would use (–a, b).  To rotate clockwise 90°, we would use (a, –b).  Both of these are, by definition, normal to our given direction vector.  You can see from the above equation that the general form equation of a line contains the normal vector.  To rotate a direction vector (b, a) counter-clockwise by θ, we take

This leads us to a useful way to treat direction vectors as complex numbers.  The above product is produced in complex numbers according to

The above rotation scheme(s) preserve the magnitude of the vector.  The complex multiplication representation can be convenient as a matter of notation and for programming in systems that support complex numbers – or so I believe.

Another really cool thing you can do with direction vectors is use parametric equations.  The parametric representation of a line (in 2D and 3D) offers some interesting benefits.