ashertrockman / TouchScale.co

Weigh things on your iPhone in Safari
22 stars 8 forks source link

Understanding of the formula of the relation between grams and force (iOS10) #2

Open ghost opened 5 years ago

ghost commented 5 years ago

According to the explanation of this article, I understand how to reason the previous version of this formula:

weight.innerHTML  = (((force - tareForce) * maxForce) / forceConversions[fcIndex]).toFixed(2) + 'g';

However, the newest version of this formula (support iOS 10) is updated as below:

function weigh(force) {
  
   var tare = force - tareForce;
   var grams = (tare * 405.257 * forceConversions[fcIndex] + 2.056 * forceConversions[fcIndex]);
   if(grams < 12)
   grams -= 2.056 * forceConversions[fcIndex];
   return grams.toFixed(2);
   };

May I know how you got this formula eventually? Re-doing the experiment as that in the first version (written in the article), recording data and then generating this new formula?

What had been updated for 3D touch in iOS 10?

Thank you.

ashertrockman commented 5 years ago

It has been a while since I updated this for iOS 10, and I don't think I made any notes on the process, so I don't have specifics.

I think iOS 10 just involved some API changes for 3D touch, and I tried to improve the formula at the same time (regardless of iOS 10 or new hardware). If I recall correctly, I gathered more data (still on an iPhone 6S), and noticed that the metric was a bit high for lighter weights (thus < 12), and hence removed the intercept (2.056 * forceConversions[fcIndex]) in that case. I believe that I validated that this worked decently well on an iPhone 6S and an iPhone 8.

ghost commented 5 years ago

@ashertrockman Thank you for your reply, I got it right now. The approach that you used is impressive and it inspired me. Thank you.

ashertrockman commented 5 years ago

No problem, and thanks! Good luck with your project.