Jump to content

Calculate range from negative max and min values


---
 Share

Recommended Posts

---

I've created a Max Result and a Min Result for a set of Y values.  I'm using a Result Element to calculate the range between the Max and Min Results.  As long as the Max is positive and the Min is negative, or both values are positive, the formula, "getActual("Maximum_Pocket Locations").actual- getActual("Minimum_Pocket Locations").actual" works great, but if both values are negative, i.e. Max -.001 and Min -.0015, etc., then the 2 values add.  How would I prevent this?

Link to comment
Share on other sites

---

If both the maximum and minimum results are negative like in the example, the resulting range should come out as max-min=(-0.001)-(-0.0015)=0.0005. The subtraction sign should be distributing into the negative minimum result, turning it into a positive number in the expression.

On that note, if you want to involve the absolute value function, I would apply it to each result, then apply it to the difference. Something like the following below.

 

 

abs(abs(getActual("Maximum_Pocket Locations").actual)- abs(getActual("Minimum_Pocket Locations").actual))

 

Edited
Re-framing the distribution explanation.
  • Like! 1
Link to comment
Share on other sites

---

Please sign in to view this username.

   I tried that but I when I tested it, I used abs(-0.0010 - 0.0015) which produces 0.0025.  Then I realized I needed to do this  abs(-0.001 -(-0.0015))   DOH 

abs("getActual("Maximum_Pocket Locations").actual- getActual("Minimum_Pocket Locations").actual)

It goes in the Result Element formula field.

Thanks for making think harder.

Link to comment
Share on other sites

---
Posted (edited)

Please sign in to view this quote.

Actually, using abs on both messes up the formula if Max is positive and Min is Negative.

Edited
Link to comment
Share on other sites

---

Please sign in to view this quote.

Ran into this same issue, except in a MS excel table with deviation results from Calypso. I was comparing deviation values on features and needed to calculate to total deviation difference between two features. I ended up asking ChatGPT to produce a formula for me to address the issue you are having, the bot gave me what I needed.

  • Like! 1
Link to comment
Share on other sites

---

This is probably dumb, but once you grab the max and min y values, create a max point using y value max, and the min point using the y value min. Then create a line using said points and report the length.

  • Like! 1
Link to comment
Share on other sites

---

MAX(getActual("Maximum_Pocket Locations").actual,getActual("Minimum_Pocket Locations").actual)-MIN(getActual("Maximum_Pocket Locations").actual,getActual("Minimum_Pocket Locations").actual)

Or something similar wouldn't work?

Link to comment
Share on other sites

---

Write a conditional branching statement that tests the value as negative or positive. If you have the negative values *-1 to change to positive values then output the result.

Edited
Link to comment
Share on other sites

---
Posted (edited)

Richard, in all of your test values, you inadvertently filled the Max (absolute) value as val1, so when you calculated the abs(val1 - val2), the math always works. In the first example val1 = -10 and val2 = -5.  However, -5 is greater than -10.

I think Mark might be onto something.

Edited
Link to comment
Share on other sites

---

I have to calculate things like this often, I think conditional branch is necessary and safest way, however I would recommend using

Please sign in to view this username.

 's suggestion as well , creating theoretical points, and output the distance of this line. 

Link to comment
Share on other sites

---

Please sign in to view this quote.

Tom,

There are no issues swapping which one is val1 and which one is val2. 

image.png.6d711321d72a156f0e83f4433948f15c.png

image.png.6ab42ba85b45a6eb734b825a12f5e125.png

  • Like! 2
Link to comment
Share on other sites

---

here is 2 diameters and we are wanting the distance, one diameter is in the negative Y axis and one in the positive Y axis. The first test, we need to check if Circle1 is the diameter that we need to convert to a positive value. The next test is checking if Circle2 is the diameter we need to change to a positive value.
 

Var1 = getActual("Circle1").y

Var2 = getActual("Circle2").y

 

if Var1<0.000 then

Var3 = abs(Var1)

Dist = Var3+ Var2

endif

 

if Var2<0.000 then

Var4 = abs(Var2)

Dist = Var1+ Var4

endif

 

In the Result Element add Dist to the formula

  • Awesome! 1
Link to comment
Share on other sites

---

Please sign in to view this quote.

Sorry for this negative comment, but that is not a good code to be honest.

Please sign in to view this username.

posted a valid code - one-liner to be exact - why a such complicated approach?

Link to comment
Share on other sites

---

Well, it works. 🤷‍♂️

Also Richard’s put in the known value. This one will capture the actual values. You can save this one as a macro too.

Edited
Link to comment
Share on other sites

In the past, I have created alignments that will produce numbers that are consistently either negative or positive to avoid PCM where some CMM's do not have PCM.

This makes math statements easier with basic PCM and result elements.

Link to comment
Share on other sites

 Share

×
×
  • Create New...