gyc Posted January 12, 2017 Report Share Posted January 12, 2017 (edited) Hi there. I need to compute the area within a closed shape (on XY plane) defined by an array of XY points (XY graph). Can't find anything for labview related to this. (not using Vision, of course) "splitting" the curve in two halves, integrating both along the diving (straight ) line and subtracting the resulting areas does not always yield a correct result because the shape may not always perfectly regular (check picture). Any suggestions? Edited January 12, 2017 by gyc Quote Link to comment
infinitenothing Posted January 12, 2017 Report Share Posted January 12, 2017 (edited) How accurate do you have to be? Maybe implement your own flood fill? Otherwise, you have to define some sort of point to point interpolation which could be as simple as defining a polygon Edited January 12, 2017 by infinitenothing Quote Link to comment
Tim_S Posted January 12, 2017 Report Share Posted January 12, 2017 Wat you are describing is the concept of an integral. Rather than sum up a large rectangle (which you don't have), you break up the object into little rectangles and sum those up. Quote Link to comment
ensegre Posted January 13, 2017 Report Share Posted January 13, 2017 If you already have the coordinates {x_i,y_i}, i=1...N, simple integration by trapezes gives A=sum_{i=1}^N (x_{i+1}-x_i)*(y_{i+1)+y_i)/2, identifying N+1 with 1. You can implement that in pure G as well as with mathscript, as you like. Quote Link to comment
gyc Posted January 16, 2017 Author Report Share Posted January 16, 2017 On 12/01/2017 at 7:34 PM, infinitenothing said: How accurate do you have to be? Maybe implement your own flood fill? Otherwise, you have to define some sort of point to point interpolation which could be as simple as defining a polygon Accurate: not a problem. It depends on how many (x,y) points i have, so I can control that beforehand. Floodfill: I am not working with images/pixels. (x,y) are actual floating point values in a measurement space. This is green theorem (which in turn is a particular case of Kelvin-Stokes) but I can't seem to find anything in LV help. Quote Link to comment
gyc Posted January 16, 2017 Author Report Share Posted January 16, 2017 On 12/01/2017 at 9:51 PM, Tim_S said: Wat you are describing is the concept of an integral. Rather than sum up a large rectangle (which you don't have), you break up the object into little rectangles and sum those up. Exactly, but I find it difficult to 'split' the figure into rectangles. What I thought of is to split it into triangles, of which one vertex is the center of mass of the figure itself. (good old romans already did that!) Quote Link to comment
ensegre Posted January 16, 2017 Report Share Posted January 16, 2017 Why arguing? If you have the coordinates you have the analytical solution. You may decompose it in summation of areas of oriented triangles with a common vertex (any point of the plane), or in trapezes based on the y axis, you will get to the same result. 1 Quote Link to comment
infinitenothing Posted January 16, 2017 Report Share Posted January 16, 2017 Ensegre, don't you need a convex polygon for that? 3 hours ago, gyc said: Accurate: not a problem. It depends on how many (x,y) points i have, so I can control that beforehand. Floodfill: I am not working with images/pixels. (x,y) are actual floating point values in a measurement space. This is green theorem (which in turn is a particular case of Kelvin-Stokes) but I can't seem to find anything in LV help. You could convert the vectors to discrete pixels using Bresenham's Algorithm Quote Link to comment
ensegre Posted January 16, 2017 Report Share Posted January 16, 2017 34 minutes ago, infinitenothing said: Ensegre, don't you need a convex polygon for that? No. https://en.wikipedia.org/wiki/Shoelace_formula, http://mathworld.wolfram.com/PolygonArea.html. Just with an alternative arrangement of the terms. 59 minutes ago, infinitenothing said: You could convert the vectors to discrete pixels using Bresenham's Algorithm You could if you want to rasterize your image. Do you need that? 1 Quote Link to comment
gyc Posted January 18, 2017 Author Report Share Posted January 18, 2017 On 16/01/2017 at 5:52 PM, ensegre said: Why arguing? If you have the coordinates you have the analytical solution. You may decompose it in summation of areas of oriented triangles with a common vertex (any point of the plane), or in trapezes based on the y axis, you will get to the same result. Not arguing, just learning (always learning). Excellent implementation, btw! Quote Link to comment
GregSands Posted January 24, 2017 Report Share Posted January 24, 2017 In fact there's Polygon Area.vi in the Mathematics/Geometry/Computational Geometry palette. Slightly different but equivalent implementation. Typing "area" into Quick Drop found it immediately Quote Link to comment
ensegre Posted January 24, 2017 Report Share Posted January 24, 2017 38 minutes ago, GregSands said: In fact there's Polygon Area.vi in the Mathematics/Geometry/Computational Geometry palette. Slightly different but equivalent implementation. Typing "area" into Quick Drop found it immediately Doh, completely right. That would be the first of the alternatives given in https://en.wikipedia.org/wiki/Shoelace_formula, plus argument checks. It occurred me to think that among the various alternatives, both the one I thought and this one are the most efficient needing only two array allocations and one multiplication. The determinant form in http://mathworld.wolfram.com/PolygonArea.html needs two. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.