Я сомневаюсь, что Ваш корпоративный брандмауэр позволяет PING, но другие весь, кажется, одна форма http или другого. В системе Linux можно установить Прокси HTTP как переменную среды, таким образом, в ударе, введите:
export http_proxy=http://www.myproxy.com:3128
существует переменная аналогичной среды для FTP (ftp_proxy).
Others have provided you the formula, but not the work. Here's how you approach a problem like this. You might find this far more valuable than just knowning the answer.
To map [0.5, 1]
to [0, 1]
we will seek a linear map of the form x -> ax + b
. We will require that endpoints are mapped to endpoints and that order is preserved.
Method one: The requirement that endpoints are mapped to endpoints and that order is preserved implies that 0.5
is mapped to 0
and 1
is mapped to 1
a * (0.5) + b = 0 (1)
a * 1 + b = 1 (2)
This is a simultaneous system of linear equations and can be solved by multiplying equation (1)
by -2
and adding equation (1)
to equation (2)
. Upon doing this we obtain b = -1
and substituting this back into equation (2)
we obtain that a = 2
. Thus the map x -> 2x - 1
will do the trick.
Method two: The slope of a line passing through two points (x1, y1)
and (x2, y2)
is
(y2 - y1) / (x2 - x1).
Here we will use the points (0.5, 0)
and (1, 1)
to meet the requirement that endpoints are mapped to endpoints and that the map is order-preserving. Therefore the slope is
m = (1 - 0) / (1 - 0.5) = 1 / 0.5 = 2.
We have that (1, 1)
is a point on the line and therefore by the point-slope form of an equation of a line we have that
y - 1 = 2 * (x - 1) = 2x - 2
so that
y = 2x - 1.
Once again we see that x -> 2x - 1
is a map that will do the trick.
Вычтите 0,5 (что даст вам новый диапазон от 0 до 0,5), затем умножьте на 2.
double normalize( double x )
{
// I'll leave range validation up to you
return (x - 0.5) * 2;
}
Чтобы добавить еще один общий ответ.
Если вы хотите сопоставить линейный диапазон [A..B] с [C..D], вы можете применить следующие шаги:
Сдвиньте диапазон так, чтобы нижняя граница была равна 0. (вычтите A из обеих границ:
[A..B] -> [0..B-A]
Масштабируйте диапазон так, чтобы он составлял [0..1]. (Разделите на верхнюю границу):
[0..B-A] -> [0..1]
Масштабируйте диапазон, чтобы он имеет длину нового диапазона, равного DC. (умножить на DC):
[0..1] -> [0..D-C]
Сдвинуть диапазон так, чтобы нижняя граница была C. (добавьте C к границам):
[0..D-C] -> [C..D]
Объединяя это в одну формулу, мы получаем :
(D-C)*(X-A)
X' = ----------- + C
(B-A)
В вашем случае A = 0,5, B = 1, C = 0, D = 1 вы получите:
(X-0.5)
X' = ------- = 2X-1
(0.5)
Обратите внимание: если вам нужно преобразовать много X в X ', вы можете изменить формулу на :
(D-C) C*B - A*D
X' = ----- * X + ---------
(B-A) (B-A)
Также интересно взглянуть на нелинейные диапазоны. Вы можете предпринять те же шаги, но вам понадобится дополнительный шаг для преобразования линейного диапазона в нелинейный диапазон.