Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. <?php
  2.  
  3. $width = 600;
  4. $height = 600;
  5.  
  6. function demo($im) {
  7.  
  8. $x1 = 124;
  9. $y1 = 253;
  10. imagefilledarc($im, $x1, $y1, 10, 10, 0, 0, 0x000000, 0);
  11. imagestring($im, 2, $x1-30, $y1+10, "x1, y1", 0x000000);
  12.  
  13. $x2 = 445;
  14. $y2 = 428;
  15. imagefilledarc($im, $x2, $y2, 10, 10, 0, 0, 0x000000, 0);
  16. imagestring($im, 2, $x2+0, $y2+10, "x2, y2", 0x000000);
  17.  
  18. imageline($im, $x1, $y1, $x2, $y2, 0x000000);
  19.  
  20. $xc1 = $x1 + 50;
  21. $yc1 = $y1 - 200;
  22. imageline($im, $x1, $y1, $xc1, $yc1, 0x000000);
  23. imagefilledarc($im, $xc1, $yc1, 10, 10, 0, 0, 0x000000, 0);
  24.  
  25. $xc2 = $x2 -5;
  26. $yc2 = $y2 -200;
  27. imageline($im, $x2, $y2, $xc2, $yc2, 0x000000);
  28. imagefilledarc($im, $xc2, $yc2, 10, 10, 0, 0, 0x000000, 0);
  29.  
  30. $d1 = 10 * sqrt( pow($x1-$xc1, 2) + pow($y1-$yc1, 2) );
  31. $ac1 = atan2($yc1-$y1, $xc1-$x1);
  32. $ap1 = $ac1 + pi() / 2.;
  33. $xp1 = $x1 + $d1*cos($ap1);
  34. $yp1 = $y1 + $d1*sin($ap1);
  35. imageline($im, $x1, $y1, $xp1, $yp1, 0x808080);
  36.  
  37. $d2 = 10 * sqrt( pow($x2-$xc2, 2) + pow($y2-$yc2, 2) );
  38. $ac2 = atan2($yc2-$y2, $xc2-$x2);
  39. $ap2 = $ac2 - pi() / 2.;
  40. $xp2 = $x2 + $d2*cos($ap2);
  41. $yp2 = $y2 + $d2*sin($ap2);
  42. imageline($im, $x2, $y2, $xp2, $yp2, 0x808080);
  43.  
  44.  
  45. /** Принудительно задается радиус первой (красной) дуги, что неправильно!!! */
  46. $r1 = 135;
  47. /** Из него вычисляется положение центра красной дуги, обозначен красной точкой. */
  48. $r1x = $x1 + $r1*cos($ap1);
  49. $r1y = $y1 + $r1*sin($ap1);
  50. imagefilledarc($im, $r1x, $r1y, 10, 10, 0, 0, 0xFF0000, 0);
  51. imagestring($im, 2, $r1x-40, $r1y-30, "r1x, r1y", 0x000000);
  52.  
  53. /** Это результат решения уравнения для заданного радиуса красной дуги */
  54. $L = (
  55. 2.*($r1x*$x2 + $r1y*$y2)
  56. - pow($x2, 2)
  57. - pow($y2, 2)
  58. - pow($r1x, 2)
  59. - pow($r1y, 2)
  60. + pow($r1, 2)
  61. ) / 2. / (
  62. cos($ap2)*($x2-$r1x)
  63. + sin($ap2)*($y2-$r1y)
  64. + $r1
  65. );
  66.  
  67. $xl = $x2 + $L*cos($ap2);
  68. $yl = $y2 + $L*sin($ap2);
  69.  
  70. imagefilledarc($im, $xl, $yl, 10, 10, 0, 0, 0x00FF00, 0);
  71.  
  72. $aspl = atan2($r1y-$yl, $r1x-$xl);
  73.  
  74. imagearc($im, $r1x, $r1y, 2*$r1, 2*$r1, rad2deg($ap1)+180, rad2deg($aspl), 0xFF0000);
  75. imagearc($im, $xl, $yl, 2*$L, 2*$L, rad2deg($aspl), rad2deg($ap2)-180, 0x0000FF);
  76.  
  77. }
  78.  
  79. $im = imagecreatetruecolor($width, $height);
  80. imagefilledrectangle($im, 0, 0, $width-1, $height-1, 0xc0c0c0);
  81.  
  82. demo($im);
  83.  
  84. header('Content-Type: image/png');
  85. imagepng($im, null, 9);
  86.  
  87. (Xz-X₁)² + (Yz-Y₁)²
  88. R₁ = 2 ---------------------------
  89. (Xz-X₁)Cosβ + (Yz-Y₁)Sinβ
  90.  
  91. (Xz-X₂)² + (Yz-Y₂)²
  92. R₂ = 2 ---------------------------
  93. (Xz-X₂)Cosγ + (Yz-Y₂)Sinγ
  94.  
  95. Xz - Xr₁ Xz - Xr₂
  96. -------- = --------
  97. Yz - Yr₁ Yz - Yr₂
  98.  
  99. Xz = X₀ + ZCosδ
  100. Yz = Y₀ + ZSinδ
  101. Xr₁ = X₁ + ZCosβ
  102. Yr₁ = Y₁ + ZSinβ
  103. Xr₂ = X₂ + ZCosγ
  104. Yr₂ = Y₂ + ZSinγ
  105.  
  106. (Xz-X₁)² + (Yz-Y₁)²
  107. R₁ = 2 ---------------------------
  108. (Xz-X₁)Cosβ + (Yz-Y₁)Sinβ
  109.  
  110. (Xz-X₂)² + (Yz-Y₂)²
  111. R₂ = 2 ---------------------------
  112. (Xz-X₂)Cosγ + (Yz-Y₂)Sinγ
  113.  
  114. Xz - Xr₁ Xz - Xr₂
  115. -------- = --------
  116. Yz - Yr₁ Yz - Yr₂
  117.  
  118. Xz = X₀ + ZCosδ
  119. Yz = Y₀ + ZSinδ
  120. Xr₁ = X₁ + R₁Cosβ
  121. Yr₁ = Y₁ + R₁Sinβ
  122. Xr₂ = X₂ + R₂Cosγ
  123. Yr₂ = Y₂ + R₂Sinγ
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement