Re: Math question
> On Jan 24, 2017, at 11:36 AM, Eric E. Dolecki wrote: > > Never mind on that one. with a 0-100, it's super simple. But if it's 0 - 15 > that could be quite different. I'll noodle on that. The formula I gave is general purpose for mapping any input range to any output range. —Jens ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Math question
Never mind on that one. with a 0-100, it's super simple. But if it's 0 - 15 that could be quite different. I'll noodle on that. On Tue, Jan 24, 2017 at 1:57 PM Eric E. Dolecki wrote: > Thanks so much, that works perfectly! > > Another quick question. > > distance of 100 = minimum value (say 0) > distance of 200 = maximum value (say 100) > > How can I apply that? I plan on Int for this value. > > > On Tue, Jan 24, 2017 at 1:52 PM Saagar Jha wrote: > > Not completely sure if this is what you want, but I think your “scale” > would be: > > scale = (distance - minDistance) / (maxDistance - minDistance) * (maxScale > - minScale) + minScale > > In this case, > > scale = (distance - 100) / 100 * 2 + 1 > > Saagar Jha > > On Jan 24, 2017, at 10:45 AM, Eric E. Dolecki wrote: > > I have a situation where the distance of an onTouchesBegan in iOS produces > a scale for an object. > > min distance of 100 = scale of 1.0 > max distance of 200 = scale of 3.0 > > So I am looking for a number between 100 and 200 which ends up being > between 1.0 and 3.0. I can get the distance easily enough, but the scale > factor eludes me at the moment. Coffee? Lack of this kind of math for over > 20 years? Heh. > > self.scaleCircle.transform = CGAffineTransform(scaleX: percentage, y: > percentage) > > What math would I apply to get that range? > > Eric > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/saagar%40saagarjha.com > > This email sent to saa...@saagarjha.com > > > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Math question
Thanks so much, that works perfectly! Another quick question. distance of 100 = minimum value (say 0) distance of 200 = maximum value (say 100) How can I apply that? I plan on Int for this value. On Tue, Jan 24, 2017 at 1:52 PM Saagar Jha wrote: > Not completely sure if this is what you want, but I think your “scale” > would be: > > scale = (distance - minDistance) / (maxDistance - minDistance) * (maxScale > - minScale) + minScale > > In this case, > > scale = (distance - 100) / 100 * 2 + 1 > > Saagar Jha > > On Jan 24, 2017, at 10:45 AM, Eric E. Dolecki wrote: > > I have a situation where the distance of an onTouchesBegan in iOS produces > a scale for an object. > > min distance of 100 = scale of 1.0 > max distance of 200 = scale of 3.0 > > So I am looking for a number between 100 and 200 which ends up being > between 1.0 and 3.0. I can get the distance easily enough, but the scale > factor eludes me at the moment. Coffee? Lack of this kind of math for over > 20 years? Heh. > > self.scaleCircle.transform = CGAffineTransform(scaleX: percentage, y: > percentage) > > What math would I apply to get that range? > > Eric > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/saagar%40saagarjha.com > > This email sent to saa...@saagarjha.com > > > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Math question
> On Jan 24, 2017, at 10:45 AM, Eric E. Dolecki wrote: > > So I am looking for a number between 100 and 200 which ends up being > between 1.0 and 3.0. Are you talking about linear interpolation? That would be Set up the constants, as given in your email: let dist0 = 100, dist1 = 200 let scale0 = 1.0, scale1 = 3.0 Then given `dist` you get the matching `scale`: let scale = (dist - dist0) / (dist1 - dist0) * (scale1 - scale0) + scale0 Make sure everything’s converted to double if necessary. If the dist values end up typed as integers in the calculation, you’ll get hella roundoff error! —Jens ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Math question
Not completely sure if this is what you want, but I think your “scale” would be: scale = (distance - minDistance) / (maxDistance - minDistance) * (maxScale - minScale) + minScale In this case, scale = (distance - 100) / 100 * 2 + 1 Saagar Jha > On Jan 24, 2017, at 10:45 AM, Eric E. Dolecki wrote: > > I have a situation where the distance of an onTouchesBegan in iOS produces > a scale for an object. > > min distance of 100 = scale of 1.0 > max distance of 200 = scale of 3.0 > > So I am looking for a number between 100 and 200 which ends up being > between 1.0 and 3.0. I can get the distance easily enough, but the scale > factor eludes me at the moment. Coffee? Lack of this kind of math for over > 20 years? Heh. > > self.scaleCircle.transform = CGAffineTransform(scaleX: percentage, y: > percentage) > > What math would I apply to get that range? > > Eric > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/saagar%40saagarjha.com > > This email sent to saa...@saagarjha.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Math question
I have a situation where the distance of an onTouchesBegan in iOS produces a scale for an object. min distance of 100 = scale of 1.0 max distance of 200 = scale of 3.0 So I am looking for a number between 100 and 200 which ends up being between 1.0 and 3.0. I can get the distance easily enough, but the scale factor eludes me at the moment. Coffee? Lack of this kind of math for over 20 years? Heh. self.scaleCircle.transform = CGAffineTransform(scaleX: percentage, y: percentage) What math would I apply to get that range? Eric ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com