|
PHP |
Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in F:\OpenServer\domains\php-fusion.vveb.ws\includes\bbcodes\mail_bbcode_include.php on line 20
Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in F:\OpenServer\domains\php-fusion.vveb.ws\includes\bbcodes\mail_bbcode_include.php on line 21
Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in F:\OpenServer\domains\php-fusion.vveb.ws\includes\bbcodes\search_bbcode_include.php on line 39
PHP
<?php
// RU: Функция выдаёт абсолютное значения двух чисел в массиве. Первое значение меньше, второе большее
// EN: The function returns the absolute value of two numbers in the array. The first value is less, the second is greater
function abs_min_max( $ar=array('1', '1') ) {
$ar['0'] = abs($ar['0']); $ar['1'] = abs($ar['1']);
$af = min($ar['0'], $ar['1']); $bf = max($ar['0'], $ar['1']);
return array($af , $bf);
}
-
-
-
// RU:
// Возвращает ГИПОТЕНУЗУ с точностью $symb='4'
// $ar=array('1', '1') - длина катетов треугольника
// EN:
// Returns the hypotename with the precision $symb='4'
// $ar=array('1', '1') - the length of the triangle's legs
function gipotenuza($ar=array('1', '1'), $symb='4' ) {
return round(sqrt( ($ar['0']*$ar['0']) + ($ar['1']*$ar['1']) ), $symb);
}
-
-
// RU: вычислить разность
// считает расстояние между двумя точками по -x- и по -y- в декартовых координатах
// две точки (-2;-5) и (-7;5). НУЖНО ВЫЧЕСТЬ ИЗ 1 КООРДИНАТЫ ДРУГУЮ а потом взять абс значение.
// $x = 5 = abs(-2-(-7)); $y = 10 = abs(-5-5));
// EN: Calculate the difference
// finds the distance between two points in -x- and -y- in Cartesian coordinates
// two points (-2; -5) and (-7; 5). It is necessary to deduct from one coordinate and then take the abs value.
// $ x = 5 = abs (-2 - (- 7)); $ Y = 10 = abs (-5-5));
function x_y_raznost($t1=array('-2', '-5'), $t2=array('-7', '5')) {
$dx = abs($t1['0']-$t2['0']);
$dy = abs($t1['1']-$t2['1']);
return array($dx, $dy);
}
-
-
-
// RU: как посчитать например в декартовых координатах расстояние от данной точки в пределах 3 клеток игрового поля
// EN: How to calculate, for example, in Cartesian coordinates the distance from a given point within 3 within 3 cells of the playing field
$steps_x=3;
$steps_y=3;
$symb=2;
$rasst = array();
$y= -3;
while ($y<=$steps_y) {
$x= -3;
echo "<br>";
while ($x<=$steps_x) {
$abs_min_max = abs_min_max(array($x, $y));
$k = implode('_', $abs_min_max );
// echo " ".$k." " ;
if (!isset($rasst[$k])) {
$rasst[$k] = gipotenuza( $abs_min_max, $symb );
echo " ". $k ."=". $rasst[$k] ." ";
}
$x++;
}
$y++;
}
echo "<pre>"; print_r($rasst); echo "</pre>";
?>
|
Добавить комментарий |
Добавить комментарий Пожалуйста, залогиньтесь для добавления комментария.
|
HTML-code and BB-code for blogs and forums |
<a href="https://php-fusion.vveb.ws/php-fusion.php?id=10">Подсчёт гипотенузы треугольника и расстояния в декартовых координатах между точками</a>
[url=https://php-fusion.vveb.ws/php-fusion.php?id=10]Подсчёт гипотенузы треугольника и расстояния в декартовых координатах между точками[/url]
|
|