Calculate size on different distances

Frans-Jan Wind's icon

Hi,
I'm working on a patch which uses z-axis information (depth) to calculate the size of an object.

For instance an object has a width of 300 units (pixels) at 3000 units (mm) distance. The same object has a width of 400 units as 2000 units distance. With these statics I should be able to calculate the size at 2500 units distance (using a formula). I know for many of you this is basic math, but I just can't figure it out without using too many [scale] objects

And yes, I posted this in MaxMSP on purpose, since this is done without jitter.

Thank you for any lead.

big_pause's icon

It may help you to think of your widths as y's and distances as x's, then use

y = ax + b

given a pair of points, you should find it straightforward to solve for the slope and intercept.

Frans-Jan Wind's icon
Max Patch
Copy patch and select New From Clipboard in Max.

This sure did help me. But sadly it wasn't straightforward but a case of trial and error for me. The following patch after your example gave me an answer (Y=-0.1X+600).

Thank you for the guideline

big_pause's icon
Max Patch
Copy patch and select New From Clipboard in Max.

This patch should guide you on how to do this programatically (bit scruffy but hey)

What you have here essentially is the slope being the change in y/change in x, or (y2-y1)/(x2-x1)

then given that (we'll call that value 'a')

we can use

y1 = a*x1 + b
b = y1 - a*x1

and that's all there is to it.