Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using std::cin;
- using std::cout;
- double vector_multiplie(double vector_0_x, double vector_0_y,
- double vector_1_x, double vector_1_y) {
- return vector_0_x * vector_1_x + vector_0_y * vector_1_y;
- }
- bool is_vector_apart(double vector_0_x, double vector_0_y,
- double vector_1_x, double vector_1_y) {
- if (vector_0_x * vector_1_x < 0 && vector_0_y * vector_1_y < 0) {
- return 1;
- } else {
- return 0;
- }
- }
- bool point_on_the_segment(double left_x, double left_y,
- double middle_x, double middle_y, double right_x, double right_y) {
- if ((middle_x - left_x) * (right_x - middle_x) > 0
- && (middle_y - left_y) * (right_y - middle_y) > 0) {
- return 1;
- } else {
- return 0;
- }
- }
- struct Ray {
- double axis_0_x, axis_0_y, axis_1_x, axis_1_y;
- double zero_vector_x, zero_vector_y;
- double equation_coefficient_A, equation_coefficient_B, equation_coefficient_C;
- bool is_cross(Ray &other) {
- double cross_x, cross_y;
- if (this -> equation_coefficient_A * other.equation_coefficient_B ==
- this -> equation_coefficient_B * other.equation_coefficient_A) {
- if (this -> equation_coefficient_A * other.axis_0_x
- + this -> equation_coefficient_B * other.axis_0_y
- - this -> equation_coefficient_C == 0
- && !(is_vector_apart(this -> zero_vector_x, this -> zero_vector_y,
- other.zero_vector_x, other.zero_vector_y)
- && point_on_the_segment(other.axis_0_x, other.axis_0_y,
- this -> axis_0_x, this -> axis_0_y,
- this -> axis_1_x, this -> axis_1_y))) {
- return 1;
- } else {
- return 0;
- }
- } else {
- cross_x = -(this -> equation_coefficient_C * other.equation_coefficient_B -
- this -> equation_coefficient_B * other.equation_coefficient_C) /
- (this -> equation_coefficient_A * other.equation_coefficient_B -
- this -> equation_coefficient_B * other.equation_coefficient_A);
- cross_y = -(this -> equation_coefficient_A * other.equation_coefficient_C -
- this -> equation_coefficient_C * other.equation_coefficient_A) /
- (this -> equation_coefficient_A * other.equation_coefficient_B -
- this -> equation_coefficient_B * other.equation_coefficient_A);
- if (vector_multiplie(this -> zero_vector_x, this -> zero_vector_y,
- cross_x - this -> axis_0_x, cross_y - this -> axis_0_y) >= 0
- && vector_multiplie(other.zero_vector_x, other.zero_vector_y,
- cross_x - other.axis_0_x, cross_y - other.axis_0_y) >= 0) {
- return 1;
- } else {
- return 0;
- }
- }
- }
- };
- Ray NewRay() {
- Ray new_ray;
- cin >> new_ray.axis_0_x >> new_ray.axis_0_y >> new_ray.axis_1_x >> new_ray.axis_1_y;
- new_ray.equation_coefficient_A = new_ray.axis_0_y - new_ray.axis_1_y;
- new_ray.equation_coefficient_B = new_ray.axis_1_x - new_ray.axis_0_x;
- new_ray.equation_coefficient_C = new_ray.axis_0_x * new_ray.axis_1_y -
- new_ray.axis_1_x * new_ray.axis_0_y;
- new_ray.zero_vector_x = new_ray.axis_1_x - new_ray.axis_0_x;
- new_ray.zero_vector_y = new_ray.axis_1_y - new_ray.axis_0_y;
- return new_ray;
- }
- int main() {
- Ray ray_first = NewRay(), ray_second = NewRay();
- if (ray_first.is_cross(ray_second) == 0) {
- cout << "NO";
- } else {
- cout << "YES";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement