Re: Math question
Re: Math question
- Subject: Re: Math question
- From: Jens Alfke <email@hidden>
- Date: Tue, 24 Jan 2017 10:55:31 -0800
> On Jan 24, 2017, at 10:45 AM, Eric E. Dolecki <email@hidden> 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 (email@hidden)
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:
This email sent to email@hidden
References: | |
| >Math question (From: "Eric E. Dolecki" <email@hidden>) |