hexagon logo

Area Calculation from points

I am measuring a feature that is somewhat round but has lot of jagged edges. I want to use all of the areas to calculate the area. I am measuring this using hundreds of points. Anyone have any ideas ? I have searched for answers but can't seem to come up with any.
  • Ahh, you're calculating the sums of the areas of a series of parallelograms and then dividing that sum by 2 to turn the "sum-parallelogram" into "area of a triangle", which should be nearly equivalent to the area of the shape, regardless of the shape. Interesting, out-of-the-box thought process. Super@JEFMAN to the rescue.
  • , one of the "enhancements" should be a real cross product calculation.
    Cross product of PC-DMIS gives a unit vector, but the real cross product gives interested results, like the area.
    Thanks for your compliments !
  • Would it be possible (maybe even slightly easier) to adapt the Shoelace Formula ( https://en.wikipedia.org/wiki/Shoelace_formula) to this? Then you could focus on the centroid and any pair of consecutive points (although both methods are skipping the area of the triangle given by the vertices (centroid, first point, last point)).
  • The CAD Value is 563.4mm I was getting 720mm in offline PCDMIS after troubleshooting the variables.

    Then scoured the internet and found this: https://www.mathopenref.com/coordpolygonarea.html


    Which led me to this code: (sorry for the lazy variables)
    ASSIGN/V9=(PRF1.HIT[2..PRF1.NUMHITS].X*PRF1.HIT[1..(PRF1.NUMHITS-1)].Y)
                ASSIGN/V10=(PRF1.HIT[1..(PRF1.NUMHITS-1)].X*PRF1.HIT[2..PRF1.NUMHITS].Y)
                ASSIGN/V11=ABS(SUM(V10-V9)/2)
    
                ASSIGN/V19=(PRF2.HIT[2..PRF2.NUMHITS].X*PRF2.HIT[1..(PRF2.NUMHITS-1)].Y)
                ASSIGN/V110=(PRF2.HIT[1..(PRF2.NUMHITS-1)].X*PRF2.HIT[2..PRF2.NUMHITS].Y)
                ASSIGN/V111=ABS(SUM(-V110+V19)/2)
    
                ASSIGN/V119=(PRF3.HIT[2..PRF3.NUMHITS].X*PRF3.HIT[1..(PRF3.NUMHITS-1)].Y)
                ASSIGN/V1110=(PRF3.HIT[1..(PRF3.NUMHITS-1)].X*PRF3.HIT[2..PRF3.NUMHITS].Y)
                ASSIGN/V1111=ABS(SUM(-V1110+V119)/2)
    
                ASSIGN/AREA=V11-V111-V1111


    It also did not work in the offline mode and returned an area of 620mm but the two symmetrical internal features were different by 200mm to each other. Ran real samples online and got 557 and 553.

    Consensus: I will have to retest Jefman's code and will update if it works for the shape.

    & thanks for the troubleshooting and mathematical explanation.

    Attached Files
  • Would it be possible (maybe even slightly easier) to adapt the Shoelace Formula ( https://en.wikipedia.org/wiki/Shoelace_formula) to this?


    Thanks for this link! The Shoelace Formula was an interesting read. I tested a bit, and got this generalized version:

    PNT_A1     =FEAT/POINT,CARTESIAN,NO
                THEO/<4,10,0>,<0,0,1>
                ACTL/<4,10,0>,<0,0,1>
                CONSTR/POINT,CAST,PNT_A
    SCN1       =FEAT/SET,CARTESIAN
                THEO/<6,6.2,0>,<0,0,1>
                ACTL/<6,6.2,0>,<0,0,1>
                CONSTR/SET,BASIC,PNT_A,PNT_B,PNT_C,PNT_D,PNT_A1,,
                ASSIGN/N=SCN1.NUMHITS-1
                ASSIGN/VX=SCN1.HIT[1..SCN1.NUMHITS].X
                ASSIGN/VY=SCN1.HIT[1..SCN1.NUMHITS].Y
                ASSIGN/AREA=0
                ASSIGN/I=1
                WHILE/I<=N
                  ASSIGN/XY=VX[I]*VY[I+1]
                  ASSIGN/YX=VY[I]*VX[I+1]
                  ASSIGN/AREA=AREA+(XY-YX)
                  ASSIGN/I=I+1
                END_WHILE/
                ASSIGN/AREA=ABS(AREA/2)
                COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
                "area = "+AREA
    


    The only trick is in duplicating the first point PNT_A into PNT_A1 and creating a set of all points (A, B, C, D, A in this example). Then looping from 1 to N and accumulating the AREA, finally taking ABS() and dividing by 2.

    I wrote every step as a separate command, but it can of course be much more crammed together, but will be more difficult to understand:

                ASSIGN/AREA=0
    I          =LOOP/START,ID=NO,NUMBER=N,START=1,SKIP=,
                  OFFSET:XAXIS=0,YAXIS=0,ZAXIS=0,ANGLE=0
                  ASSIGN/AREA=AREA+(SCN1.HIT[I].X*SCN1.HIT[I+1].Y-SCN1.HIT[I].Y*SCN1.HIT[I+1].X)
                LOOP/END
                ASSIGN/AREA=ABS(AREA/2)
                COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
                AREA
    




    Edit: OK, now I've done code in the ' spirit' too - no loops, totally undecipherable :-)) and fast!

                CONSTR/SET,BASIC,PNT_A,PNT_B,PNT_C,PNT_D,PNT_A1,,
                ASSIGN/N=SCN1.NUMHITS-1
                ASSIGN/AR=SCN1.HIT[1..N].X*SCN1.HIT[2..N+1].Y-SCN1.HIT[1..N].Y*SCN1.HIT[2..N+1].X
                ASSIGN/AR[N+1]=0
                ASSIGN/AREA=ABS(SUM(AR))/2
                COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
                AREA
    
  • Jesus. There should be a disclaimer popping up before visiting a thread like this.
  • Coding this stuff is way above my head, but I love the math behind it, and I thought there had to be a way to calculate a triangle's area with the 3 points making its vertices as the known variables. I found something else before finding this, but the Shoelace formula is the underlying math behind it, and JEFMAN's elegant (but roundabout) solution.
  • *****Warning: MATH and CODING inside. Open at your own peril.*****

    Slight smile Don't lie, you know you love it.
  • I did order the BDSM option for PC-DMIS... :P