Вы находитесь на странице: 1из 8

PROYECTO DE COMPUTACION TRIANGULO Realice un programa que grafique el triangulo con su baricentro, ortocentro y el circuncentro y la recta de Euler ingresando

los vrtices\ ANLISIS

1. Datos de entrada Se debe ingresar por teclado los vrtices sea los puntos (en el plano cartesiano) se declaro pax (punto A la coordenada X) pay (punto A la coordenada Y) lo mismo para el punto B y C con sus respectivas coordenadas, 2. Datos de salida El grafico del triangulo con sus alturas, mediatrices y directrices y las coordenadas del ortocentro (interseccin de las alturas) del baricentro (es la interseccin de las medianas) y el circuncentro (es la interseccin de las mediatrices) 3. Constantes Se utiliza todas estas constantes: pax, pay, pbx, pby, pcx, pcy; pabx, paby, pbcx, pbcy, pcax, pcay; ax, ay, bx, by, cx, cy, m1, m2, m3, mab, mbc, mca, Bx, By; H1x, H1y, H2x, H2y, H3x, H3y,mh1,mh2,mh3,Ox,Oy,Cx,Cy; 4. Formulas relevantes Punto Medio

Pendiente

DISEO

SolTriangulo WinAppTriangulo (Windows Aplicacin) frmTriangulo.cs ComponenteFigurasGeometricas Triangulo.cs

IMPLEMENTACIN CODIGO DE LA CLASE TRIANGULO

public class Triangulo { public Triangulo() { } public float Puntomedio(float p1, float p2) { return((p1 + p2) / 2); } public float Pendiente(float y2, float y1, float x2, float x1) { return ((y2 - y1) / (x2 - x1)); } }

CODIGO DEL FORMULARIO TRIANGULO

public partial class frmTriangulo : Form { private Triangulo A = new Triangulo(); private float pax, pay, pbx, pby, pcx, pcy; private float pabx, paby, pbcx, pbcy, pcax, pcay; private float ax, ay, bx, by, cx, cy, m1, m2, m3, mab, mbc, mca, Bx, By; private float H1x, H1y, H2x, H2y, H3x, H3y,mh1,mh2,mh3,Ox,Oy,Cx,Cy; public frmTriangulo() { InitializeComponent(); } private void InicializarDatos() { txtPAX.Text = ""; txtPCX.Text = ""; txtPAY.Text = ""; txtPCY.Text = ""; txtPBX.Text = ""; txtHX.Text = ""; txtPBY.Text = ""; txtHY.Text = "";

txtCEX.Text = ""; txtCEY.Text = ""; txtCIX.Text = ""; txtCIY.Text = ""; pax = 0; pay = 0; pbx = 0; pby = 0; pcx = 0; pcy = 0; pabx = 0; paby = 0; pbcx = 0; pbcy=0; pcax=0; pcay=0; m1 = 0; m2 = 0; m3 = 0;

mab = 0; mbc = 0; mca = 0; H1x = 0; H1y = 0; H2x=0; H2y=0; H3x=0; H3y=0; Bx = 0; By = 0; Ox = 0; Oy = 0; mh1 = 0; mh2 = 0; mh3 = 0; Ox = 0; Oy = 0; picTRIANGULO.Refresh();

} private void LeerDatos() { try { pax = float.Parse(txtPAX.Text); pay = float.Parse(txtPAY.Text); pbx = float.Parse(txtPBX.Text); pby = float.Parse(txtPBY.Text); pcx = float.Parse(txtPCX.Text); pcy = float.Parse(txtPCY.Text); } catch (Exception caught) { MessageBox.Show("Error en el ingreso de datos....." + caught, "Mensaje de error", MessageBoxButtons.OK, MessageBoxIcon.Error); InicializarDatos(); } } private void frmTriangulo_Load(object sender, EventArgs e) { }

private void Escala() { ax = 200+(float)pax ; ay = 200-(float)pay ; bx = 200+(float)pbx ; by = 200-(float)pby ; cx = 200+(float)pcx ; cy = 200-(float)pcy ; } private void btnPicTriangulo_Click(object sender, EventArgs e) { // System.Drawing.Graphics G; Graphics G,H; // G = this.picGrafico.CreateGraphics(); G = picTRIANGULO.CreateGraphics(); Pen Pluma = new Pen(Color.Black); G.DrawLine(Pluma, 0, 200, 400, 200); G.DrawLine(Pluma, 200, 0, 200, 400); LeerDatos(); Escala(); H = picTRIANGULO.CreateGraphics(); Pen tri = new Pen(Color.Blue); H.DrawLine(tri, ax, ay, bx, by); H.DrawLine(tri, bx, by, cx, cy); H.DrawLine(tri, cx, cy, ax, ay); //G.DrawEllipse(Pluma, 325 - radio / 2, 250 - radio / 2, radio, radio); } private void btnResetear_Click(object sender, EventArgs e) { InicializarDatos(); } private void btnSalir_Click(object sender, EventArgs e) { Close(); } private void btnPicMediana_Click(object sender, EventArgs e) { LeerDatos(); Escala(); pabx = A.Puntomedio(ax, bx); paby = A.Puntomedio(ay, by); pbcx = A.Puntomedio(bx, cx); pbcy = A.Puntomedio(by, cy);

pcax = A.Puntomedio(cx, ax); pcay = A.Puntomedio(cy, ay); Graphics g; g = picTRIANGULO.CreateGraphics(); Pen tri = new Pen(Color.Red); g.DrawLine(tri, pabx, paby, cx, cy); g.DrawLine(tri, pbcx, pbcy, ax, ay); g.DrawLine(tri, pcax, pcay, bx, by); } private void Baricentro() { LeerDatos(); Escala(); m1 = A.Pendiente(pbcy, ay, pbcx, ax); m2 = A.Pendiente(pcay, by, pcax, bx); m3 = A.Pendiente(paby, cy, pabx, cx); Bx = (((ay - by) - (m1 * ax) - (m2 * bx)) / (m2 - m1)); By = ((m2 * Bx) - (m2 * bx) + by); } private void btnCooBaricentro_Click(object sender, EventArgs e) { Baricentro(); txtCEX.Text = 150+Bx.ToString(); txtCEY.Text = -250+By.ToString(); } private void ortocentro() { LeerDatos(); Escala(); mab = A.Pendiente(by, ay, bx, ax); mbc = A.Pendiente(cy, by, cx, bx); mca = A.Pendiente(ay, cy, ax, cx); m1 = -1 / mbc; m2 = -1 / mca; m3 = -1 / mab; H1x = (((ay - by) + (mbc * bx) - (m1 * ax)) / (mbc - m1)); H1y = ((m1 * H1x) - (m1 * ax) + ay); H2x = (((by - cy) + (mca * cx) - (m2 * bx)) / (mca - m2)); H2y = ((m2 * H2x) - (m2 * bx) + by); H3x = (((by - ay) + (mab * ax) - (m3 * cx)) / (mab - m3)); H3y = ((m3 * H3x) - (m3 * cx) + cy); }

private void btnPicAltura_Click(object sender, EventArgs e) { LeerDatos(); Escala(); ortocentro(); Graphics O; O = picTRIANGULO.CreateGraphics(); Pen tri = new Pen(Color.Green); O.DrawLine(tri, H3x, H3y, cx, cy); O.DrawLine(tri, H1x, H1y, ax, ay); O.DrawLine(tri, H2x, H2y, bx, by); } private void btnCooOrtocentro_Click(object sender, EventArgs e) { LeerDatos(); Escala(); ortocentro(); mh1 = A.Pendiente(H1y, ay, H1x, ax); mh2 = A.Pendiente(H2y, by, H2x, bx); mh3 = A.Pendiente(H3y, cy, H3x, cx); Ox = (((ay - by) - (mh1 * ax) - (mh2 * bx)) / (mh2 - mh1)); Oy = ((mh2 * Bx) - (mh2 * bx) + by); txtHX.Text = Ox.ToString(); txtHY.Text = Oy.ToString(); } private void Circuncentro() { LeerDatos(); Escala(); pabx = A.Puntomedio(ax, bx); paby = A.Puntomedio(ay, by); pbcx = A.Puntomedio(bx, cx); pbcy = A.Puntomedio(by, cy); pcax = A.Puntomedio(cx, ax); pcay = A.Puntomedio(cy, ay); mab = A.Pendiente(by, ay, bx, ax); mbc = A.Pendiente(cy, by, cx, bx); mca = A.Pendiente(ay, cy, ax, cx); m1 = -1 / mbc; m2 = -1 / mca; m3 = -1 / mab;

Cx = (((pbcy - by) + (m3 * pabx) - (m1 * pbcx)) / (m3 - m1)); Cy = ((m1 * Ox) - (m1 * pbcx) + pbcy); } private void btnCooCircuncentro_Click(object sender, EventArgs e) { Circuncentro(); txtCIX.Text = Cx.ToString(); txtCIY.Text = Cy.ToString(); } private void btnPicMediatrices_Click(object sender, EventArgs e) { Circuncentro(); Graphics C; C = picTRIANGULO.CreateGraphics(); Pen tri = new Pen(Color.Black); C.DrawLine(tri, pabx, paby, Cx, Cy); C.DrawLine(tri, pbcx, pbcy, Cx, Cy); C.DrawLine(tri, pcax, pcay, Cx, Cy); } } CORRIDA DEL PROGRAMA

Вам также может понравиться