Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cassert>
- struct Point
- {
- double x;
- double y;
- };
- double distance( Point p1, Point p2)
- {
- double d;
- d = pow( pow( p1.x-p2.x, 2) + pow( p1.y - p2.y, 1/2), 2);
- return d;
- }
- struct Linia
- {
- Point p1;
- Point p2;
- };
- void test_distance()
- {
- {
- Point a {2, 4};
- Point b { 2, 3};
- assert ( distance( a, b)== 1);
- }
- {
- Point a { -1, 5};
- Point b { 2, 9};
- assert ( distance( a, b)==5);
- }
- }
- bool prostopadla( Linia l1, Linia l2)
- {
- int a1, a2;
- a1 = (l1.p2.y-l1.p1.y)/(l1.p2.x-l1.p1.x);
- a2 = (l2.p2.y-l2.p1.y)/(l2.p2.x-l2.p1.x);
- if ( a1 == 0 || a2 == 0)
- {
- if( a1 == 0 && a2 != 0 && l2.p2.x == l2.p1.x)
- {
- return true;
- }
- if( a2 == 0 && a1 != 0 && l1.p2.x == l1.p1.x)
- {
- return true;
- }
- return false;
- }
- else
- {
- if (a1 * a2 == -1) {
- return true;
- }
- return false;
- }
- }
- void test_prostopadla()
- {
- {
- Linia l1 { { 0, 1}, 0, 4}};
- Linia l2 { { 3, 5}, { 3, -2};
- assert ( prostopadla ( l1, l2)==true);
- }
- int main()
- {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment