Friday, May 21, 2021

Published May 21, 2021 by Anonymous with 0 comment

Determine position of two points with respect to a 3D plane

#include <iostream>

using namespace std;

  

void check_position(int a, int b, int c, int d,

                    int x1, int y1, int z1,

                    int x2, int y2, int z2)

{

    

    int value_1 = a * x1 + b * y1 + c * z1 + d;

    int value_2 = a * x2 + b * y2 + c * z2 + d;

  

    

    if ((value_1 > 0 && value_2 > 0)

        || (value_1 < 0 && value_2 < 0))

        cout << "On same side";

  

    

    if ((value_1 > 0 && value_2 < 0)

        || (value_1 < 0 && value_2 > 0))

        cout << "On different sides";

  

    

    if (value_1 == 0 && value_2 == 0)

        cout << "Both on the plane";

  

    

    if (value_1 == 0 && value_2 != 0)

        cout << "Point 1 on the plane";

    if (value_1 != 0 && value_2 == 0)

        cout << "Point 2 on the plane";

}

  

int main()

{

  

    

    int a = 1, b = 2, c = 3, d = 4;

  

    

    int x1 = -2, y1 = -2, z1 = 1;

    int x2 = -4, y2 = 11, z2 = -1;

  

    

    check_position(a, b, c, d,

                   x1, y1, z1,

                   x2, y2, z2);

  

    return 0;

}

Adblock test (Why?)


Original page link

Best Cool Tech Gadgets

Top favorite technology gadgets
      edit

0 comments:

Post a Comment