LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Surface integral for two dimensional array

I have two arrays with x and y values. Plotted against each other they almost form a kind of circle. I want to close the two-dimensional surface with a straight line and calculate the area. What VI should I use?
My idea is to find xmin and xmax and do two integrations, but there must be an easier way?
0 Kudos
Message 1 of 4
(3,460 Views)
> I have two arrays with x and y values. Plotted against each other they
> almost form a kind of circle. I want to close the two-dimensional
> surface with a straight line and calculate the area. What VI should I
> use?

If your sampled points resemble a circle, you have at least two
approaches. If the data you are acquiring is really circular, and the
noncircular shape is due to measurement noise, you could look at the
data, determine the average center and radius, then compute the circle
size based on the computed radius. There is a VI for finding the sphere
that contains the points, and if you input your own Z of say zero for
each point, then it works in 2D as well and will give you the parameters
of a circle.

More than likely, that is not the case
, and you will want to use the
equivalent of a trapezoidal approach. If it is easy to find a point
inside the circle, then you can just iterate through taking them three
at a time and computing the area of the triangles and adding them
together. Use the first and last point to get the final triangle that
closes the curve. Note that this approach is somewhat simplistic and
will not work on shapes like a cardoid since some of the triangles will
overlay and be counted multiple times. This can be detected by
measuring the angles between the center and the two points. If the
angle to the first point is always less than the angle to the second, or
always greater, then the computation is accurate, when it switches, then
the shape isn't that circular, and you can either average some points,
throw out the triangle, or have other fixup steps. I'm sure there are
some approaches for error correction, but I'll stop while I'm ahead.

Greg McKaskle
0 Kudos
Message 2 of 4
(3,460 Views)
The problem with the trapezoidal approach is that the shape I want to measure is irregular enough to make it difficult to find the point in the circle where there is "free sight" to all points on the edge. The angle will not always be less (or greater) than the last one, and I think the error will get too big.

(My error, I used the word circle to explain that the values in the arrays forms a closed shape with an area)

What I really would like is a VI that can do area integrals with two arrays as input. One way of doing this is to see the shape as two separate lines, one upper and one lower. (The shape cannot be too irregular). You just calculate the integral from xmin to xmax for both lines and the deduct the result from the lower line from the
result from the upper line. My thought was that there maybe was a standard VI that can do this, but since I am a LabView newbie I just could not find it.

//Cecilia
0 Kudos
Message 3 of 4
(3,460 Views)
> The problem with the trapezoidal approach is that the shape I want to
> measure is irregular enough to make it difficult to find the point in
> the circle where there is "free sight" to all points on the edge. The
> angle will not always be less (or greater) than the last one, and I
> think the error will get too big.
>

Understood. And there might be a clever way to do this, but I thought
I'd give you obvious adhoc answer. If you don't get a better solution
and you end up writing this, the point really doesn't have to be near
the center of the circle, it just helps to think about it that way. You
can also take a point on the shape. Then, loop around doing the
triangles, detecting if the shape is complex and your point and
triangles overlap. If you detect it, pick another point, say the point
on the other side of the circle, and split the circle into two. The sum
of the areas is the same as the original area. You can also insert
points, say the midpoint on the new edge, near the center of the circle,
and attempt to use that point as your common triangle vertex. If you
write the VI to allow arbitrary splitting of any complex polygon into
simple ones and correctly sum their areas together, I think this will work.

I bet there is still a possibility that the final split makes two
triangles, both of which are simple, but they do have an overlap. For
this four pointed exception to the rule, you can compute new points at
intersection points and subtract out the duplicated triangle or the
triangle that isn't really a part of the interior of the shape. And in
fact, you can probably do this as you go around the circle without any
splitting of the shape.

I've done algorithms similar to this to determine if a point is on the
interior, edge, or exterior of an arbitrary polygon, and they do get
tricky. If you do end up implementing it, I'd suggest doing some
algorithm animation -- pretty easy in LV. Sometimes probing a strategic
point is useful, but othertimes, it is good to branch a wire off and
build an array of intermediate values. Copy the indicator, put the data
into another VI, and use a graph or picture control to loop through the
data visualizing what the algorithm accomplished in more detail to find
bugs or convince yourself of correctness.

Its also good to have test cases. Since you can take a smooth shape
with a known answer, like a circle or cardioid, and sample the shape,
you can then run the sampled points through your algorithm and see how
close you get to the canonical answer.

Greg McKaskle
0 Kudos
Message 4 of 4
(3,460 Views)