/* Tarea: construir una estructura para definir un
 * plano y hacer una función para intersectar planos
 */
#include <stdio.h>

typedef struct {
	float x, y;
}Punto;

typedef struct {
	Punto p1, p2;
}Recta;

float pendienteRecta(Recta r){
	float m, d;
	d = r.p2.x - r.p1.x;
	if ( d != 0 ){
		m = (r.p2.y - r.p1.y)/d;
		return m;
	}
	else{
		printf("division por cero\n");
		exit(1);
	}
}

float corteEjeY(Recta r){
	float b;
	b = r.p1.y - pendienteRecta(r)*r.p1.x;
	return b;
}

Punto intersectarRectas(Recta r1, Recta r2){
	Punto p;
	float m1, m2, b1, b2;
	
	m1 = pendienteRecta(r1);
	m2 = pendienteRecta(r2);
	b1 = corteEjeY(r1);
	b2 = corteEjeY(r2);
	p.x = (b2 - b1)/(m1 - m2);
	p.y = m1*p.x + b1;
	return p;
}

int main(){
	Recta r1, r2;
	float m1, m2;
	float b1, b2;
	Punto c;

	r1.p1.x = 2.0;
	r1.p1.y = 2.0;
	r1.p2.x = 1.0;
	r1.p2.y = 1.0;
	r2.p1.x = -2.0;
	r2.p1.y = 2.0;
	r2.p2.x = -1.0;
	r2.p2.y = 1.0;
	c = intersectarRectas(r1, r2);
	printf("%.2f %.2f\n", c.x, c.y);

/*
	m1 = pendienteRecta(r1);
	m2 = pendienteRecta(r2);
	b1 = corteEjeY(r1);
	b2 = corteEjeY(r2);
	printf("%.2f %.2f %.2f %.2f\n", m1,m2,b1,b2);
*/
	return 0;
}
