You are on page 1of 3

using

using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Threading.Tasks;
System.Windows.Forms;

namespace Graficar_funciones_trigonomtricas
{
public partial class FrmGraficar : Form
{
public FrmGraficar()
{
InitializeComponent();
}
//Declaramos los lapiz
System.Drawing.Pen mylapiz1 = new System.Drawing.Pen(System.Drawing.Colo
r.Black);
System.Drawing.Pen mylapiz2 = new System.Drawing.Pen(System.Drawing.Colo
r.Red);
string funciones;
private void GraficarFunciones()
{
//declaramos rea de dibujo
System.Drawing.Graphics dibujo = this.pictureBox1.CreateGraphics();
//Declaramos las variable y un arreglo
double[] valores = new double[20000];
double puntoX1 = 0, puntoY1 = 0, puntoX2 = 0, puntoY2 = 0;
int con = 0;
int xcentro = pictureBox1.Width / 2; //calculamos cordenadas central
es
int ycentro = pictureBox1.Height / 2;
dibujo.TranslateTransform(xcentro, ycentro);
dibujo.ScaleTransform(1, -1); //convertimos a coordenadas normales
if (textBox_Coordenada.Text == "")
{
MessageBox.Show("Ingrece un valor", "Valor", MessageBoxButtons.O
K, MessageBoxIcon.Information);
}
else
{
//Clico for que graficara las lineas que recorrern las
//lineas hirizontal y vertical
for (int i = -xcentro; i < xcentro; i+= 8)
{
//Lineas para la lnea Vertical
//Punto -y
dibujo.DrawLine(mylapiz1, 5, i, -5, i);
//Lneas para la lnea horizontal
//Punto x
dibujo.DrawLine(mylapiz1, i, 5, i, -5);
}
//Obtenemos el item seleccionado del comboBox
funciones = ComboBox_Funciones.Text;

if (funciones == "Funciones")
{
MessageBox.Show("Seleccione una funcion", "Funciones", Messa
geBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
con = 0;
//Ciclo que generar los ngulos de las funciones
for (double x = xcentro * -1; x < xcentro *2; x+= 0.1)
{
//Instruccin switch que nos permitir seleccionar la funcin
switch (funciones)
{
case "Cos":
valores[con] = Math.Cos(x);
break;
case "Sin":
valores[con] = Math.Sin(x);
break;
case "Tan":
valores[con] = Math.Tan(x);
break;
}
con = con + 1;
}
con = 1;
//Ciclo for para poder sacar las coordenadas
for (double xx = xcentro * -1 +0.1; xx < xcentro *2; xx+=0.1
)
{
//sacamos coordenadas 1
puntoX1 = (xx - 0.1) * (pictureBox1.Width / (Convert.ToI
nt16(textBox_Coordenada.Text) * 2));
puntoY1 = valores[con - 1] * ycentro;
//sacamos coordenadas 2
puntoX2 = xx * (pictureBox1.Width / (Convert.ToInt16(tex
tBox_Coordenada.Text) * 2));
puntoY2 = valores[con] * ycentro;
dibujo.DrawLine(mylapiz2, Convert.ToSingle(puntoX1), Con
vert.ToSingle(puntoY1), Convert.ToSingle(puntoX2), Convert.ToSingle(puntoY2));
con = con + 1;
}
}
}
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
int xcentro = pictureBox1.Width / 2; //calculamos cordenadas central
es
int ycentro = pictureBox1.Height / 2;
e.Graphics.TranslateTransform(xcentro, ycentro);
e.Graphics.ScaleTransform(1, -1); //convertimos a coordenadas normal
es
//DIBUJAMOS EJES X-Y
//Lnea horizontal
e.Graphics.DrawLine(mylapiz1, xcentro * -1, 0, xcentro * 2, 0); //ej

e X
//lnea vertical
e.Graphics.DrawLine(mylapiz1, 0, ycentro, 0, ycentro * -1); //eje Y
}
private void ComboBox_Funciones_SelectedIndexChanged(object sender, Even
tArgs e)
{
funciones = ComboBox_Funciones.Text;
//Limpiamos el pictureBox cada vez elijamos una funcin
switch (funciones)
{
case "Cos":
pictureBox1.Image = null;
break;
case "Sin":
pictureBox1.Image = null;
break;
case "Tan":
pictureBox1.Image = null;
break;
default:
break;
}
}
private void cmd_dibujar_Click(object sender, EventArgs e)
{
GraficarFunciones();
}
private void Form1_Load(object sender, EventArgs e)
{
LinkLabel1.Links.Add(9, 8, "");
}
private void LinkLabel1_LinkClicked(object sender, LinkLabelLinkClickedE
ventArgs e)
{
System.Diagnostics.Process.Start("www.youtube.com/alexjpz17");
}
private void label3_Click(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
}
}

You might also like