Area Calculation from points

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    I tested it offline this morning, it works !
    On a circle scan 4 hits/mm Ø50 mm, the error between the assignment and PI*R^2 is 0.032 mm2. (about 0.0015%)
    With a scan 8hits/mm, the error is 0.008 mm2.

    Comment


    • #17
      Jefman

      Nice work, i wish i knew what you were doing mathematically/programatically. I tried it this morning with out success on my shape :/ The CAD surface area is -151mm from PCDMIS calculated.

      Comment


      • #18
        Originally posted by JEFMAN View Post
        I'm not at the cmm.
        I would try this for the external scan :
        ASSIGN/V1=SUM(SCN1.HIT[1..SCN1.NUMHITS].X)/SCN1.NUMHITS
        ASSIGN/V2=SUM(SCN1.HIT[1..SCN1.NUMHITS].Y)/SCN1.NUMHITS
        ASSIGN/V3=SUM(SCN1.HIT[1..SCN1.NUMHITS].Z)/SCN1.NUMHITS
        ASSIGN/V4=MPOINT(V1,V2,V3)

        ASSIGN/V5=SCN1.HIT[1..(SCN1.NUMHITS-1)].XYZ-V4
        ASSIGN/V6=SCN1.HIT[2..SCN1.NUMHITS].XYZ-V4

        ASSIGN/SURFACE=SUM(SQRT(DOT(V1,V1))*SQRT(DOT(V2,V2))*SIN(DEG2RAD(ANGLEBETWEEN(V1,V2))))/2

        If it works, you do the same for others scans, then calculate the area...
        (I can't check if it works now...)
        V1, V2, V3 and V4 are generating the centroid of the scan.

        V5 and V6 are setting up an overlapping of points, so that V5 uses HIT1 while V6 uses HIT2, and then V5 uses HIT2 while V6 uses HIT3, etc. But they don't seem to be in use. Shouldn't the red labels be some combo of V4, V5 and V6?

        SURFACE is supposed to be calculating the sums of the triangular areas? (I dunno, I got lost there. Square of the dot product's multiplied together multiplied by the sin of the angle between something ((V1,V2) doesn't make sense to me).
        "This is my word... and as such is beyond contestation."

        Comment


        • #19
          What is the CAD value ?
          Did you add the "/2" that I forgot yesterday ?

          Comment


          • #20
            VinniUSMC at the rescue !
            ASSIGN/SURFACE=SUM(SQRT(DOT(V5,V5))*SQRT(DOT(V6,V6))*SIN( DEG2RAD(ANGLEBETWEEN(V5,V6))))/2 !!!!!!!

            V4 is the centroid of the scan, V5 and V6 are 2 arrays of vectors between hits and the centroid.
            SQRT(DOT(V5,V5)) is an array of length of vectors, same for V6.

            The norm of a cross product is also the area of the parallelogram formed by both vectors, and its (length of V5)*(length of V6)*(sin of anglre between V5 and V6) (math definition)

            Thanks a lot Vinni !!!!!
            (CTRL + C ; CTRL + V is sometimes too easy )

            Comment


            • VinniUSMC
              VinniUSMC commented
              Editing a comment
              JEFMAN 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)).

            • JEFMAN
              JEFMAN commented
              Editing a comment
              VinniUSMC : Just a precision, sum (parallelograms areas)/2 = sum (parallelograms areas/2), so the calculation gives the sum of triangles areas...

            • VinniUSMC
              VinniUSMC commented
              Editing a comment
              Thanks Jef, I noted that in my comment above. I was just wondering aloud whether calculating directly from 3 points would be any easier.

          • #21
            In addition :
            https://en.wikipedia.org/wiki/Cross_...metric_meaning

            Comment


            • #22
              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
              area of polygon.PNG

              Which led me to this code: (sorry for the lazy variables)
              Code:
              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.

              JEFMAN & VinniUSMC thanks for the troubleshooting and mathematical explanation.
              Attached Files

              Comment


              • #23
                Originally posted by VinniUSMC
                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:

                Code:
                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:

                Code:
                            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 'JEFMAN spirit' too - no loops, totally undecipherable :-)) and fast!

                Code:
                            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
                Last edited by AndersI; 02-08-2018, 05:21 AM.
                AndersI
                SW support - Hexagon Metrology Nordic AB

                Comment


                • VinniUSMC
                  VinniUSMC commented
                  Editing a comment
                  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.

              • #24
                Jesus. There should be a disclaimer popping up before visiting a thread like this.
                PC-DMIS CAD++ 2o19 R1 SP6

                Comment


                • vpt.se
                  vpt.se commented
                  Editing a comment
                  I did order the BDSM option for PC-DMIS... :P

                • AndersI
                  AndersI commented
                  Editing a comment
                  Is there any other one?

                • vpt.se
                  vpt.se commented
                  Editing a comment
                  Touché, AndersI

              • #25
                I was wondering where the formula came from…
                So I searched a little, and found the explanation.
                To explain the way, I must begin by the start.
                There are two kinds of products with vectors, the dot product (or scalar product) whose result is a number, and cross product (or vectorial product) whose result is a vector, perpendicular of both vectors of the product.
                The “cross product” name comes from the way to realize it.
                The vectors are written in columns:
                cross prod 1.JPG
                The result of product between i and j values is written on k line, j and k on i line and k and i on j line.
                If the product is made on the XY plane, the result is along Z.
                In this case, Ak and Bk are zero, so the only non zero value of the product is Ck.
                Therefore, the length of the vector result is :

                cross prod 2.JPG

                It’s also (by definition) the area of the constructed parallelogram.

                The Shoelace formula, given in 2D, so in XY plane, the vectors are written from the extremes coordinates:
                cross prod 3.JPG
                Applying xi yi to A and B, it gives :
                cross prod 4.JPG
                The Shoelace formula is “just” a simplification of the cross product, available in 2D only…

                Thanks to AndersI, VinniUSMC , vpt.se and Krbrumma to had been interested by it !
                Last edited by JEFMAN; 02-11-2018, 09:08 AM.

                Comment


                • VinniUSMC
                  VinniUSMC commented
                  Editing a comment
                  JEFMAN Thanks for the clarification SuperJef

                  Fun stuff to play with.

              Related Topics

              Collapse

              Working...
              X