hexagon logo

Extracting 3 largest values?

Is there a way to set up a code to extract the largest 3 values of a group of hits?

I have 9 points around an arc and want to create a circle using the 3 largest -PR- values from the 9 points.

I'm able to get the Max/Min values from the group, but want a way to find the three largest -PR- values.

Thanks,

Parents
  • This should work...

    CIR_1      =FEAT/CONTACT/CIRCLE/DEFAULT,CARTESIAN,OUT,LEAST_SQR
                THEO/<0,-32,0>,<0,-1,0>,122,0
                ACTL/<-0.003,-32,0.001>,<0,-1,0>,122.004,0
                TARG/<0,-32,0>,<0,-1,0>
                START ANG=0,END ANG=360
                ANGLE VEC=<-1,0,0>
                DIRECTION=CCW
                SHOW FEATURE PARAMETERS=NO
                SHOW CONTACT PARAMETERS=YES
                  NUMHITS=11,DEPTH=5,PITCH=0
                  SAMPLE METHOD=SAMPLE_HITS
                  SAMPLE HITS=0,SPACER=53.59
                  AVOIDANCE MOVE=NO
                  FIND HOLE=DISABLED,ONERROR=NO,READ POS=NO
                SHOW HITS=YES
                  HIT/BASIC,<-61,-37,0>,<-1,0,0>,<-60.999,-37.001,-0.005>
                  HIT/BASIC,<-51.316,-37,-32.979>,<-0.8412535,0,-0.5406408>,<-51.324,-37.002,-32.978>
                  HIT/BASIC,<-25.34,-37,-55.488>,<-0.415415,0,-0.909632>,<-25.343,-37.003,-55.489>
                  HIT/BASIC,<8.681,-37,-60.379>,<0.1423148,0,-0.9898214>,<8.689,-36.995,-60.383>
                  HIT/BASIC,<39.947,-37,-46.101>,<0.6548607,0,-0.7557496>,<39.954,-36.996,-46.1>
                  HIT/BASIC,<58.529,-37,-17.186>,<0.959493,0,-0.2817326>,<58.521,-36.998,-17.185>
                  HIT/BASIC,<58.529,-37,17.186>,<0.959493,0,0.2817326>,<58.526,-36.998,17.187>
                  HIT/BASIC,<39.947,-37,46.101>,<0.6548607,0,0.7557496>,<39.944,-36.997,46.103>
                  HIT/BASIC,<8.681,-37,60.379>,<0.1423148,0,0.9898214>,<8.674,-37,60.387>
                  HIT/BASIC,<-25.34,-37,55.488>,<-0.415415,0,0.909632>,<-25.357,-37.006,55.489>
                  HIT/BASIC,<-51.316,-37,32.979>,<-0.8412535,0,0.5406408>,<-51.322,-37.002,32.975>
                ENDMEAS/
    L1         =LABEL/
                DISPLAYPRECISION/6
    $$ NO,
                .
                . biggest PR 
                .
                ASSIGN/X1=CIR_1.HIT[1..CIR_1.NUMHITS].X
                ASSIGN/Y1=CIR_1.HIT[1..CIR_1.NUMHITS].Y
                ASSIGN/Z1=CIR_1.HIT[1..CIR_1.NUMHITS].Z
                ASSIGN/PRS1=SQRT(X1^2+Y1^2+Z1^2)
                ASSIGN/MAXHIT1=MAXINDEX(PRS1)
    DIM LOC1= LOCATION OF POINT CIR_1.HIT[MAXHIT1]  UNITS=MM ,$
    GRAPH=OFF  TEXT=OFF  MULT=10.00  OUTPUT=BOTH  HALF ANGLE=NO
    AX    NOMINAL       +TOL       -TOL       MEAS        DEV     OUTTOL
    PR   61.000000   0.050000   0.050000  61.007994   0.007994   0.000000 -----#---
    END OF DIMENSION LOC1
    $$ NO,
                2nd biggest PR
                .
                ASSIGN/HINX=0
                ASSIGN/AINX=0
                DO/
                  ASSIGN/HINX=HINX+1
                  IF/HINX<>MAXHIT1
                    ASSIGN/AINX=AINX+1
                    ASSIGN/X2[AINX]=CIR_1.HIT[HINX].X
                    ASSIGN/Y2[AINX]=CIR_1.HIT[HINX].Y
                    ASSIGN/Z2[AINX]=CIR_1.HIT[HINX].Z
                  END_IF/
                UNTIL/HINX==CIR_1.NUMHITS
                ASSIGN/PRS2=SQRT(X2^2+Y2^2+Z2^2)
                ASSIGN/MAXHIT2=MAXINDEX(PRS2)
    DIM LOC3= LOCATION OF POINT CIR_1.HIT[MAXHIT2]  UNITS=MM ,$
    GRAPH=OFF  TEXT=OFF  MULT=10.00  OUTPUT=BOTH  HALF ANGLE=NO
    AX    NOMINAL       +TOL       -TOL       MEAS        DEV     OUTTOL
    PR   61.000000   0.050000   0.050000  61.005935   0.005935   0.000000 -----#---
    END OF DIMENSION LOC3
    $$ NO,
                3rd biggest PR
                .
                ASSIGN/HINX=0
                ASSIGN/AINX=0
                DO/
                  ASSIGN/HINX=HINX+1
                  IF/HINX<>MAXHIT1 AND HINX<>MAXHIT2
                    ASSIGN/AINX=AINX+1
                    ASSIGN/X3[AINX]=CIR_1.HIT[HINX].X
                    ASSIGN/Y3[AINX]=CIR_1.HIT[HINX].Y
                    ASSIGN/Z3[AINX]=CIR_1.HIT[HINX].Z
                  END_IF/
                UNTIL/HINX==CIR_1.NUMHITS
                ASSIGN/PRS3=SQRT(X3^2+Y3^2+Z3^2)
                ASSIGN/MAXHIT3=MAXINDEX(PRS3)
    DIM LOC2= LOCATION OF POINT CIR_1.HIT[MAXHIT3]  UNITS=MM ,$
    GRAPH=OFF  TEXT=OFF  MULT=10.00  OUTPUT=BOTH  HALF ANGLE=NO
    AX    NOMINAL       +TOL       -TOL       MEAS        DEV     OUTTOL
    PR   61.000000   0.050000   0.050000  61.000433   0.000433   0.000000 ----#----
    END OF DIMENSION LOC2

  • Thank you for the help, every little bit helps.

    I'm trying to get this code to work. I'm not very fluent with scripting, so I'm probably missing something rather simple. I got the section to work for the largest PR. When I completed the 2nd biggest PR, my Until/HINX==CIR1_1.NUMHITS is coming up as 0, shouldn't it be looking at all 9 hits? Also, for X2/Y2/Z2 it's taking the values from the smallest PR. Anyone see what I'm missing.

  • That is a boolean statement since it is part of a flow control statement I believe, so it'll be a 1 or 0, or True / False

    Do this until HINX = CIR1_1.NUMHITS. So do this until the statement is true.

    As for the X2/Y2/Z2 has it ran through the statement entirely yet?

    https://docs.hexagonmi.com/pcdmis/2022.2/en/helpcenter/mergedProjects/core/22_flow_topics/Do_Until.htm

  • Yes, it ran through the statement, just can't figure out why it's taking the values from the lowest PR

  • Can you post your code in a code tag here with all the relevant information for this portion


  • CIR1_1     =FEAT/CIRCLE,CARTESIAN,IN,LEAST_SQR,NO
                THEO/<1.1,0,0>,<1,0,0>,1.786
                ACTL/<1.1,-0.002,-0.009>,<1,0,0>,1.781
                CONSTR/CIRCLE,BF,2D,PT63_39,PT63_37,PT63_21,PT63_22,PT63_23,PT63_24,PT63_25,PT63_40,PT63_43,,
                OUTLIER_REMOVAL/OFF,3
                FILTER/OFF,UPR=0
                ASSIGN/X1=CIR1_1.HIT[1..CIR1_1.NUMHITS].X
                ASSIGN/Y1=CIR1_1.HIT[1..CIR1_1.NUMHITS].Y
                ASSIGN/Z1=CIR1_1.HIT[1..CIR1_1.NUMHITS].Z
                ASSIGN/PRS1=SQRT(X1^2+Y1^2+Z1^2)
                ASSIGN/MAXHIT1=MAXINDEX(PRS1)
    $$ NO,
                ****************************************************
                ASSIGN/HINX=0
                ASSIGN/AINX=0
                DO/
                  ASSIGN/HINX=HINX+1
                  IF/HINX<>MAXHIT1
                    ASSIGN/AINX=AINX+1
                    ASSIGN/X2[AINX]=CIR1_1.HIT[HINX].X
                    ASSIGN/Y2[AINX]=CIR1_1.HIT[HINX].Y
                    ASSIGN/Z2[AINX]=CIR1_1.HIT[HINX].Z
                  END_IF/
                UNTIL/HINX==CIR1_1.NUMHITS
                ASSIGN/PRS2=SQRT(X2^2+Y2^2+Z2^2)
                ASSIGN/MAXHIT2=MAXINDEX(PRS2)
    $$ NO,
                ****************************************************
                DO/
                  ASSIGN/HINX=HINX+1
                  IF/HINX1<>MAXHIT1 AND HINX<>MAXHIT2
                    ASSIGN/AINX=AINX+1
                    ASSIGN/X3[AINX]=CIR1_1.HIT[HINX].X
                    ASSIGN/Y3[AINX]=CIR1_1.HIT[HINX].Y
                    ASSIGN/Z3[AINX]=CIR1_1.HIT[HINX].Z
                  END_IF/
                UNTIL/HINX==CIR1_1.NUMHITS
                ASSIGN/PRS3=SQRT(X3^2+Y3^2+Z3^2)
                ASSIGN/MAXHIT3=MAXINDEX(PRS3)

  • I just tried it, and I verified that it is picking the correct points using my code example I posted above as well.

    PRS1 = point 8

    PRS2 = point 1

    My array says max order is 8, 1, 6, 2, 5, 4, 7, 3

  •  I

    'm really riding the struggle bus. I show the same thing, that 1 should be PRS2. When I look at my actual data/results, PRS2 should be 7, and PRS3 will be 6. I included a screen shot of the values that are computed for PRS1, this is accurate of my part.

Reply Children
  • If you're trying to hover over the 3 PR variables to see the values, that will confuse you because the variables within the Do/Unitl blocks will only hold the "real" values during execution.

  • Hey Neil, is there any chance you guys could add .PR as a valid expression extension for .HIT? Unless there is a trick I don't know about to report the ACTUAL polar radius without making extra variables.

    I know there's the mathematical shortcuts, and extreme points available, but I think it would be nice to have. 

    I know we can report the location of a feature and get the PR, but I believe the command is something like LOC1.PR.MEAS, but only works if it's part of a dimension.

    Example, if I did 4CR.HIT[5].PR it just shows 0.

    I report the Polar Radius of a single hit 5 and it works just fine

    I were to edit the ".HIT[5..5]" to ".HIT[5]" to trim the extra ..5 that PC-DMIS adds when you click a point in the edit window it says invalid index over and over.

    ASSIGN/V1=4CR.HIT[5].PR
    DIM LOC1= LOCATION OF SET 4CR.HIT[5..5]  UNITS=IN ,$
    GRAPH=OFF  TEXT=OFF  MULT=10.00  OUTPUT=BOTH  HALF ANGLE=NO
    AX       MEAS    NOMINAL       +TOL       -TOL        DEV     OUTTOL
    PR      0.9386     0.9436     0.0000     0.0000    -0.0050     0.0050 <--------
    END OF DIMENSION LOC1

  • Hey Neil, is there any chance you guys could add .PR as a valid expression extension for .HIT? Unless there is a trick I don't know about to report the ACTUAL polar radius without making extra variables.

    We have very limited resources available and I don't think there would be enough business justification to make this a high priority - so probably not.

     I were to edit the ".HIT[5..5]" to ".HIT[5]" to trim the extra ..5 that PC-DMIS adds when you click a point in the edit window it says invalid index over and over.

    That's how it's supposed to work.  You need to use the .HIT[#..#] syntax.

  • If I did 4CR.HIT[5].XYZ it gives me the XYZ of that hit. Is this only because of dimensioning  that it requires a beginning and end index? That actually makes sense, thanks.

  • Generally it's better to use the full syntax everywhere.  There are a few fringe cases (like the one you've found) where omitting the .. may work but I don't know them all and it's not reliable.