Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<math.h>
- using namespace std;
- typedef struct point2D {
- double x;
- double y;
- }
- point2D;
- float distance2D ( point2D t1, point2D t2) {
- return sqrt((t1.x-t2.x)*(t1.x-t2.x)+(t1.y-t2.y)*(t1.y-t2.y));
- }
- typedef struct point3D {
- double x;
- double y;
- double z;
- }
- point3D;
- float distance3D (point3D t1, point3D t2) {
- return sqrt ((t1.x-t2.x)*(t1.x-t2.x)+(t1.y-t2.y)*(t1.y-t2.y)+(t1.z-t2.z)*(t1.z-t2.z));
- }
- int is_collinear(point2D t1, point2D t2, point2D t3) {
- if((t2.y-t1.y)/(t2.x-t1.x)==(t3.y-t2.y)/(t3.x-t2.x))
- return 1;
- else
- return 0;
- }
- int main () {
- float x1, y1, x2, y2;
- cin>>x1,y1;
- cin>>x2,y2;
- point2D t1 = {x1, y1};
- point2D t2 = {x2, y2} ;
- cout<<distance2D(t1,t2)<<'\n';
- float z1, z2;
- cin>>z1,z2;
- point3D t3 = {x1,y1,z1};
- point3D t4 = {x2,y2,z2};
- cout<<distance3D(t3,t4)<<'\n';
- point2D t5= {z1,z2};
- cout<<is_collinear(t1,t2,t5);
- return 0;
- }
Add Comment
Please, Sign In to add comment