Авторизация
 Регистрация   Войти   Забыли пароль? 

Подсчёт гипотенузы треугольника и расстояния в декартовых координатах между точками

Обновлённый PHP-Fusion Bogatyr / Free CMS PHP-Fusion 7 Bogatyr / PHP-function for arrays / Подсчёт гипотенузы треугольника и расстояния в декартовых координатах между точками


 Russian

Calculation of the hypotenuse of a triangle and the distance in Cartesian coordinates between points

Обновлённый PHP-Fusion Bogatyr / Free CMS PHP-Fusion 7 Bogatyr / PHP-function for arrays / Calculation of the hypotenuse of a triangle and the distance in Cartesian coordinates between points


 English

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
  1. <?php
  2. // RU: Функция выдаёт абсолютное значения двух чисел в массиве. Первое значение меньше, второе большее
  3. // EN: The function returns the absolute value of two numbers in the array. The first value is less, the second is greater
  4. function abs_min_max( $ar=array('1', '1') ) {
  5.     $ar['0'] = abs($ar['0']); $ar['1'] = abs($ar['1']);
  6.     $af = min($ar['0'], $ar['1']);    $bf = max($ar['0'], $ar['1']);
  7.     return array($af , $bf);
  8. }
  9. // RU:
  10. // Возвращает ГИПОТЕНУЗУ с точностью  $symb='4'
  11. // $ar=array('1', '1') - длина катетов треугольника
  12. // EN:
  13. // Returns the hypotename with the precision $symb='4'
  14. // $ar=array('1', '1') - the length of the triangle's legs
  15. function gipotenuza($ar=array('1', '1'), $symb='4' ) {
  16.    return  round(sqrt( ($ar['0']*$ar['0']) + ($ar['1']*$ar['1']) ), $symb);
  17. }
  18. // RU: вычислить разность
  19. // считает расстояние между двумя точками по -x- и по -y- в декартовых координатах
  20. // две точки (-2;-5) и (-7;5). НУЖНО ВЫЧЕСТЬ ИЗ 1 КООРДИНАТЫ ДРУГУЮ а потом взять абс значение.
  21. // $x = 5 = abs(-2-(-7));  $y = 10 = abs(-5-5));
  22. // EN: Calculate the difference
  23. // finds the distance between two points in -x- and -y- in Cartesian coordinates
  24. // two points (-2; -5) and (-7; 5). It is necessary to deduct from one coordinate and then take the abs value.
  25. // $ x = 5 = abs (-2 - (- 7)); $ Y = 10 = abs (-5-5));
  26. function x_y_raznost($t1=array('-2', '-5'), $t2=array('-7', '5')) {
  27.    $dx = abs($t1['0']-$t2['0']);
  28.    $dy = abs($t1['1']-$t2['1']);
  29.    return  array($dx, $dy);
  30. }
  31. // RU: как посчитать например в декартовых координатах расстояние от данной точки в пределах 3 клеток игрового поля
  32. // EN: How to calculate, for example, in Cartesian coordinates the distance from a given point within 3 within 3 cells of the playing field
  33. $steps_x=3;
  34. $steps_y=3;
  35. $symb=2;
  36. $rasst = array();
  37. $y= -3;
  38. while ($y<=$steps_y) {
  39.     $x= -3;
  40.     echo "<br>";
  41.     while ($x<=$steps_x) {
  42.         $abs_min_max = abs_min_max(array($x, $y));
  43.         $k = implode('_', $abs_min_max );
  44.          // echo "  ".$k." " ;
  45.         if (!isset($rasst[$k])) {
  46.             $rasst[$k] = gipotenuza( $abs_min_max, $symb );
  47.             echo "&nbsp;". $k ."=". $rasst[$k] ."&nbsp; ";
  48.         }
  49.         $x++;
  50.     }
  51.     $y++;
  52. }
  53. echo "<pre>"; print_r($rasst); echo "</pre>";
  54. ?>
Добавить комментарий

Добавить комментарий
Пожалуйста, залогиньтесь для добавления комментария.
Рейтинги
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]

Language: Default
 
Код для PHP-Fusion