Advertisement
Klokova_Sofi

Точки пересечения вертикальной прямой с прямоугольником

Feb 25th, 2022
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. if (((tchk1.y <= rect1.y) and (tchk1.y >= rect2.y) and
  2. (tchk2.y >= rect2.y) and (tchk2.y <= rect1.y)) or
  3. ((tchk1.y >= rect1.y) and (tchk1.y <= rect2.y) and
  4. (tchk2.y <= rect2.y) and (tchk2.y >= rect1.y))) then
  5. begin
  6. cross1.y := tchk1.y;
  7. cross1.x := tchk1.x;
  8. cross2.y := tchk2.y;
  9. cross2.x := tchk2.x;
  10. cross1.existance := true;
  11. cross2.existance := true;
  12. end;
  13.  
  14. if ((tchk1.y <= rect1.y) and (tchk1.y >= rect2.y) and
  15. (tchk2.y <= rect2.y)) or ((tchk1.y >= rect1.y) and
  16. (tchk1.y <= rect2.y) and (tchk2.y >= rect2.y)) then
  17. begin
  18. cross1.y := rect2.y;
  19. cross1.x := rect2.x;
  20. cross2.y := tchk1.y;
  21. cross2.x := tchk1.x;
  22. cross1.existance := true;
  23. cross2.existance := true;
  24. end;
  25.  
  26. if ((tchk2.y <= rect1.y) and (tchk2.y >= rect2.y) and
  27. (tchk1.y >= rect1.y)) or ((tchk2.y >= rect1.y) and
  28. (tchk2.y <= rect2.y) and (tchk1.y <= rect1.y)) then
  29. begin
  30. cross1.y := tchk2.y;
  31. cross1.x := tchk2.x;
  32. cross2.y := rect1.y;
  33. cross2.x := rect1.x;
  34. cross1.existance := true;
  35. cross2.existance := true;
  36. end;
  37.  
  38. if ((tchk2.y >= rect1.y) and (tchk2.y <= rect2.y) and
  39. (tchk1.y >= rect2.y)) or ((tchk2.y <= rect1.y) and
  40. (tchk2.y >= rect2.y) and (tchk1.y <= rect2.y)) then
  41. begin
  42. cross1.y := rect2.y;
  43. cross1.x := rect2.x;
  44. cross2.y := tchk2.y;
  45. cross2.x := tchk2.x;
  46. cross1.existance := true;
  47. cross2.existance := true;
  48. end;
  49.  
  50. if ((tchk1.y <= rect1.y) and (tchk1.y >= rect2.y) and
  51. (tchk2.y >= rect1.y)) or ((tchk1.y >= rect1.y) and
  52. (tchk1.y <= rect2.y) and (tchk2.y <= rect1.y)) then
  53. begin
  54. cross1.y := rect1.y;
  55. cross1.x := rect1.x;
  56. cross2.y := tchk1.y;
  57. cross2.x := tchk1.x;
  58. cross1.existance := true;
  59. cross2.existance := true;
  60. end;
  61.  
  62. if ((tchk1.y >= rect1.y) and (tchk2.y <= rect2.y) and (rect1.y > rect2.y))
  63. or ((tchk1.y >= rect2.y) and (tchk2.y <= rect1.y) and (rect1.y < rect2.y))
  64. or ((tchk1.y <= rect2.y) and (tchk2.y >= rect1.y) and (rect1.y > rect2.y))
  65. or ((tchk1.y <= rect1.y) and (tchk2.y >= rect2.y) and (rect1.y < rect2.y))
  66. then
  67. begin
  68. cross1.y := rect1.y;
  69. cross1.x := rect1.x;
  70. cross2.y := rect2.y;
  71. cross2.x := rect2.x;
  72. cross1.existance := true;
  73. cross2.existance := true;
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement