2

Hey I have an equation that I need to figure out it is chart based math where you have two points on the chart and need to get the rest of the values:

I am building a javascript page that takes the takes the two points on a chart but needs to spit out any position on the chart.

It is for extrapolating the sight settings on an archery site based on knowing two distances and sight settings:

Max Setting on sight: Var = 120;

Distances
18M
20M
25M
30M
35M
40M
45M
50M
55M
60M
70M
90M

The user would provide the following via form elements.

Shortest recorded sight setting Yardage and Site setting position E.G. 45M = 50 Longest recorded sight setting Yardage and Site setting position E.G. 70M = 105

Max Setting on site = 120

Distance they would like to get an estimation for (same list as above)

What the equation would do is guess the site setting for the yardage selected as long as they have entered the two previous settings.

For some reason I am lost trying to figure out the math for this.

4

2 回答 2

1

首先,真的很酷的问题!

我通常依赖肯塔基州的风向,但这似乎是一种更精确的方法!

我有一个解决方案,我没有费心创建表单输入,而是创建了一些静态输入。

var max = {"distance" : 70,"sight" : 105};
var min = {"distance" : 45,"sight" : 50};
var calculateSightSetting = function(dist,min,max){
  var distRange,distFactor,sightRange,returnDistance;
  if (dist < min.distance){
      throw "Distance provided must be at least " + min.distance + " M Long";
  }else{
      distRange = max.distance - min.distance;
      distFactor = ((dist-min.distance)/distRange);
      sightRange = max.sight-min.sight;
      returnDistance = min.sight + (sightRange * distFactor);
  }
  return returnDistance;
}                  
console.log(calculateSightSetting(60,min,max));

我还创建了一个 JSFiddle,因此您可以运行它并查看它是否按预期执行。

http://jsfiddle.net/marteljn/rtYRZ/4/

于 2012-05-22T04:52:07.633 回答
0

感谢大家的意见和建议,

我想我已经弄清楚了,您可以在以下位置查看解决方案

http://matthewchitty.com/archery

(请注意它是 javascript,因此您可以查看源代码并查看代码。)

最终变得非常简单,我想出了插值。

于 2012-05-22T16:23:57.277 回答