Given the two starting points (touches), calculate the distance between them using the Pythagorean theorem. Let this distance be called "initial distance" .
For each subsequent update of points, recalculate the distance between points and let this distance be called "new distance" .
scale = "new distance" / "initial distance".
If someone doesnβt really know ... Pythagoras theorem:
sqrtf(powf(bx - ax, 2.0f) + powf(by - ay, 2.0f))
Itβs easier to understand the scaling formula ... if your fingers are two times apart from each other, as it was when you started pinching, the scale should be 2.0 (2x) - so connect some numbers ... 50 pixels first .. .100px split now = 100/50 = 2
source share