Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. function XY = task5 (C1, C2)
  2. wrapper = @(x) g(x, C1, C2);
  3. # если они вообще пересекаются
  4. A = -2 * (C2(1) - C1(1));
  5. B = -2 * (C2(2) - C1(2));
  6. C = (C2(1) - C1(1))^2 + (C2(2) - C1(2))^2 + C1(3)^2 - C2(3)^2;
  7. R = C1(3);
  8. D = A^2 + B^2;
  9. hold on;
  10. grid on;
  11. phi = -2*pi():0.01:2*pi();
  12. plot(C1(1) + C1(3) * cos(phi), C1(2) + C1(3) * sin(phi));
  13. plot(C2(1) + C2(3) * cos(phi), C2(2) + C2(3) * sin(phi));
  14. # честно спжно с e-maxx
  15. if (C^2 - R^2 * D <= 0)
  16. # 2 одинаковые точки же не ошибка? типа, потом можно удалить ненужные
  17. XY = [ fsolve(wrapper, [C1(1) - C2(3), C1(2) - C1(3)]); fsolve(wrapper, [C1(1) + C1(3), C1(2) + C1(3)]) ].';
  18.  
  19. plot(XY(1, :), XY(2, :), "p");
  20. endif
  21.  
  22. endfunction
  23.  
  24. function y = g (x, C1, C2)
  25. y(1) = (x(1) - C1(1))^2 + (x(2) - C1(2))^2 - C1(3)^2;
  26. y(2) = (x(1) - C2(1))^2 + (x(2) - C2(2))^2 - C2(3)^2;
  27. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement