Beruflich Dokumente
Kultur Dokumente
Contenido
10 APLICACIONES EN WINDOWS FORM................................................................. 825
10.1 EJEMPLO DE APLICACIÓN COMPLETA CON MENUS Y BARRA DE
HERRAMIENTAS ..................................................................................................... 825
10.2 MENU DE MODELADO 2D. ............................................................................. 837
10.3 TEMAS FRACTALES ....................................................................................... 851
La alfombra de Sierpiński...................................................................................... 851
CREACION DE UNA MONTAÑA FRACTAL ........................................................ 853
ARBOLES CON RECURSIVIDAD ........................................................................ 854
El copo de nieve de Koch, .................................................................................... 854
FRACTALES DE MALDEBROT ............................................................................ 863
10.4 MONTAÑA FRACTAL ...................................................................................... 867
10.5 SIMULACION DE POLITICAS DE INVENTARIOS DE CONTROL DE
INVENTARIOS ......................................................................................................... 883
10.6 TRIANGULACION DE DELAUNAY (HECHO CAMBIAR Y MODIFICAR ..... Error!
Bookmark not defined.
10.7 APLICACIÓN DE TRADUCTOR DE ARCHIVOS ............................................. 888
10.8 BUSCADOR MODO FORMUALRIOS .............................................................. 890
10.9 PROBLEMA DE CRUCE .................................................................................. 909
10.10 PROGRAMA DE LOCALIZACION DE LOTES............................................... 912
10.11 MODELADO 3D ................................................. Error! Bookmark not defined.
10.12 MODELADO 3D ( primitivas) REPITIDO ........................................................ 918
10.13 MODELADO 3D (DIBUJO DE MALLAS ) SI ENTRA OPENGL NO
CONSIDERAR ......................................................................................................... 918
10.14 PROBLEMA DE CONDUCCION DE VEHICULOS ( RESUMIR CON OTROS
SIMILARES) ................................................................. Error! Bookmark not defined.
10.15 PROBLEMA DE CONDUCCION DE VEHICULOS USADO BITMAPS LIBRO2
..................................................................................... Error! Bookmark not defined.
10.16 MOVER UN ARCHIVO DE TEXTO ................... Error! Bookmark not defined.
10.17 MADURACION DE UNA FRUTA (ejemplo platanos) ........ Error! Bookmark not
defined.
10.18 JUEGO DEL PACMAN ................................................................................... 929
10.19 GRAFICA DE FUNCIONES EN 2D Y 3D ....................................................... 936
10.20 PROCESAMIENTO DE IMAGNES EN VISUAL BASIC .... Error! Bookmark not
defined.
10.21 JUEGO DE LA SERPIENTE O GUSANO(USO DE AUTOMATAS
CELULARES) ........................................................................................................... 945
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -824-
10,22 DICCIONARIO TRADUCTOR ........................................................................ 949
10.23 DICCIONARIO TRADUCTOR EN MODO CONSOLA. PASAR A MODO
OCNSOLA ................................................................................................................ 952
TRADUCTOR MODIFICADO ( usando cuadros de dialogo) ................................954
10.24 CUADRO CROMATICO ................................................................................. 957
Tarea.- Elaborar Gama de colores o circulo cromático(use el triangulo para cad
color)( Estudiar el cuadro cromaico...................................................................... 958
10.25 EVALUACION DE EXPRESIONES MUY LARGO ......................................... 959
10.26 PROPUESTAS DE TRABAJOS DE INVESTIGACION .................................. 973
10.27 EVALUACION DE ALUACION DE EXPRESIONES PASARLO AL CAPITULO
INTERIRO ................................................................................................................ 974
Desarrollar un juego donde se mueve el fondo de la pantalla .............................. 977
10.28 VER UNA PARTE DE LA PANTALLA REPITIDO ......................................... 977
10.29 DIBUJE EL SIGUIENTE PLANO .................................................................... 985
10.30 TRANSPARENCIAS( Juntarlo con el problema del avion) ............................. 992
10.31 JUEGO DE LA VIDA DE ................................................................................ 995
10.31 La construcción de un brazo Robot articulado. PASA A GRAFICOS .......... 1003
10.33 Problema de objetos usando arreglos(tarea) .............................................. 1005
10.34 APLICACIONES DE 3 COLORES(se observa la mezcla de colores ........... 1012
10.35 Iluminacion ................................................................................................... 1015
10.36 Procesamiento de Imágenes y aplicaciones REPITIDO .............................. 1018
10.37 TAREA. ........................................................................................................ 1030
10.38 APLICACIÓN DEL MODELO EN DETECCION DE MANCHAS DE LANA
REPITIDO .............................................................................................................. 1031
10.39N -30 PROCESAMIENTO DE IMAGNES EN VISUAL BASIC 2012 ........... Error!
Bookmark not defined.
10.40 IMAGEN CON BARRAS DE DEZPLAZAMIENTO ...................................... 1032
ARBOLES ........................................................................................................... 1034
10.42 TRABAJO DE TRAINGULACION CON INTEGRALES ............................... 1035
este progrma obtiene cualquer area de puntos dados ........................................ 1036
1 ................................................................................... Error! Bookmark not defined.
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -825-
10 APLICACIONES EN WINDOWS FORM
Cuando trabajamos con aplicaciones Windows, existen dos tipos de interfaces o formas
de presentar la información en pantalla , éstas son:
1. Interface de Simple Documentos (SDI): Presenta un documento en su propia ventana,
cada ventana es independiente. Por ejemplo se usan SDI, el bloc de notas, el Paint, el
WordPad, Office 2000, etc.
2. Interface de Múltiples Documentos (MDI) : Presenta todos los documentos sobre una
ventana principal (Formulario padre) sobre la cual se muestra cada documento en su
ventana secundaria (Formulario hijo). Por ejemplo , se usan MDI: el Visual Estudio.NET,
SQL Enterprise Manager, Office 97, etc.
El ejemplo trata sobre un Editor de documentos similar al Wordpad , pero con funciones
básicas . Este ejemplo trabaja con dos formularios ; el primero es un formulario MDI
padre que tiene un menú principal , barras de herramientas y barra de estado; el segundo
formulario es la base para crear formularios MDI hijos que representan un documento
donde pueda escribir textos enriquecidos. Formato rtf
Elija DropDownItems
En image escoger
5. Seleccione el control StatusStrip1 y Clic al botón de editar elementos luego añadir tres
paneles y configurar sus propiedades , tal como se muestran en el siguiente cuadro:
Lo mismo puede hacer con toolstrip y automáticamente adiciona los controles estándar
La siguiente aplicación tiene por objeto mostrar , como se realiza un menu de opciones,
y manejo de pinceles brochas , metodos graficos colores y transparencias
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -838-
Menu Edición
Puede también modificar cualquier npropiedad del objeto seleccionado cambiando sus
valores en el dataGridView
El evento mousedows del objeto picture box permite acercar el vértice del objetos
seleccionado al coordenadas del ratón
Imports System.IO
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -841-
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class Form1
Sub MostrarMatrizFormulario(ByVal A(,) As Single, ByVal nf As Integer, ByVal nc As
Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
DataGridView1.Rows(fila).Cells(col).Value = A(fila, col)
Next
Next
End Sub
Sub MostrarMatrizPoligonos(ByVal A(,) As Single, ByVal nf As Integer, ByVal nc As
Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To Ncol1 - 1
DataGridView2.Rows(fila).Cells(col * 2).Value = A(fila, col * 2)
DataGridView2.Rows(fila).Cells(col * 2 + 1).Value = A(fila, col * 2 + 1)
Next
Next
End Sub
Sub IniciarTodo()
Dim col As Integer
DataGridView1.RowCount = Nfilas1
DataGridView1.ColumnCount = 12
For col = 0 To 11 '
DataGridView1.Columns(col).Width = 34
Next col
For fila = 0 To 7
DataGridView1.Rows(fila).HeaderCell.Value = "F" & fila
Next
DataGridView1.Columns(0).HeaderText = "Nro"
DataGridView1.Columns(0).HeaderText = "Nro"
DataGridView1.Columns(1).HeaderText = "Az"
DataGridView1.Columns(2).HeaderText = "Tx"
DataGridView1.Columns(3).HeaderText = "Ty"
DataGridView1.Columns(4).HeaderText = "Ex"
DataGridView1.Columns(5).HeaderText = "Ey"
DataGridView1.Columns(6).HeaderText = "Radio"
DataGridView1.Columns(7).HeaderText = "Nlados"
DataGridView1.Columns(8).HeaderText = "Transparencia"
DataGridView1.Columns(9).HeaderText = "Rojo"
DataGridView1.Columns(10).HeaderText = "Verde"
DataGridView1.Columns(11).HeaderText = "Azul"
End Sub
Sub Coordenadas()
grafico.DrawLine(Pens.Blue, -lim, 0, lim, 0)
grafico.DrawLine(Pens.Blue, 0, -lim, 0, lim)
End Sub
Sub inicio2()
Dim col, fila As Integer
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -842-
DataGridView2.RowCount = 10
DataGridView2.ColumnCount = Ncol1 * 2
DataGridView2.Columns(0).HeaderText = "Punto"
For col = 0 To Ncol1 - 1
DataGridView2.Columns(col * 2).Width = 40
DataGridView2.Columns(col * 2 + 1).Width = 40
DataGridView2.Columns(col * 2).HeaderText = "X" & col
DataGridView2.Columns(col * 2 + 1).HeaderText = "Y" & col
Next
For fila = 0 To nf - 1
DataGridView2.Rows(fila).HeaderCell.Value = "F" & fila
Next
End Sub
Private Sub MnuIniciar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuIniciar.Click
IniciarTodo()
End Sub
Private Sub MenuBorrar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuBorrar.Click
grafico.Clear(Color.Black)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
grafico = PictureBox1.CreateGraphics
pincel = New Pen(Brushes.Red, 1)
brocha = New SolidBrush(Color.Green)
IniciarTodo()
inicio2()
End Sub
Private Sub MenuAbrir(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuAbrirCuad1.Click
OpenFileDialog1.ShowDialog()
NombreArchivo = OpenFileDialog1.FileName
RecuperarDeMatriz(NombreArchivo, A, nf, nc)
MostrarMatrizFormulario(A, nf, nc)
' inicilzalar combobox
ComboBox1.Items.Clear()
For fila = 0 To nf - 1
ComboBox1.Items.Add(fila)
Next
ComboBox1.Text = 1
End Sub
Sub graficarPoligono(ByVal X() As Single, ByVal Y() As Single, ByVal np As Integer)
Dim Puntos(np - 1) As Point
For fila = 0 To np - 1
Puntos(fila).X = X(fila)
Puntos(fila).Y = Y(fila)
Next
grafico.FillPolygon(brocha, Puntos)
grafico.DrawPolygon(pincel, Puntos)
End Sub
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -843-
Sub ObtenerVectoresXY(ByVal nroFila As Integer, ByRef X() As Single, ByRef Y() As
Single, ByVal ne As Integer)
Dim col As Integer
For col = 0 To ne - 1
X(col) = DataGridView2.Rows(nroFila).Cells(col * 2).Value
Y(col) = DataGridView2.Rows(nroFila).Cells(col * 2 + 1).Value
Next
End Sub
Sub GraficarPoligonoNro(ByVal fila As Integer, ByRef X() As Single, ByRef Y() As
Single)
Try
Dim nlados As Integer
grafico.ResetTransform()
AnguloZ = DataGridView1.Rows(fila).Cells(1).Value
tx = DataGridView1.Rows(fila).Cells(2).Value
ty = DataGridView1.Rows(fila).Cells(3).Value
Ex = DataGridView1.Rows(fila).Cells(4).Value
Ey = DataGridView1.Rows(fila).Cells(5).Value
Radio = DataGridView1.Rows(fila).Cells(6).Value
nlados = DataGridView1.Rows(fila).Cells(7).Value
Transparencia = DataGridView1.Rows(fila).Cells(8).Value
rojo = DataGridView1.Rows(fila).Cells(9).Value
verde = DataGridView1.Rows(fila).Cells(10).Value
azul = DataGridView1.Rows(fila).Cells(11).Value
ObtenerVectoresXY(fila, X, Y, nlados)
grafico.TranslateTransform(tx, ty)
grafico.ScaleTransform(Ex, Ey)
grafico.RotateTransform(AnguloZ)
' Coordenadas()
brocha.Color = Color.FromArgb(Transparencia, rojo, verde, azul)
graficarPoligono(X, Y, nlados)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub btnGraficar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuGraficarPoligono1.Click
Dim fila As Integer = 1
For fila = 0 To nf - 1
GraficarPoligonoNro(fila, X, Y)
Next
End Sub
Private Sub txtRotacion_KeyDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txtRotacion.KeyDown
grafico.Clear(Color.Black)
NroObjeto = Val(ComboBox1.Text)
AnguloZ = DataGridView1.Rows(NroObjeto).Cells(1).Value
Select Case e.KeyCode
Case Keys.X, Keys.Right 'X traslacion
AnguloZ = AnguloZ + prot
Case Keys.X, Keys.Right 'X traslacion
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -844-
AnguloZ = AnguloZ - prot
End Select
txtRotacion.Text = ""
DataGridView1.Rows(NroObjeto).Cells(1).Value = AnguloZ
btnGraficar_Click(sender, e)
End Sub
'**************** module 1
Imports System.IO
Module Module1
Public B(maxfilas, MaxCol) As Single
Public Nfilas1 As Integer = 15
Public Ncol1 As Integer = 8
Public rfila As Integer
Public rcol As Integer
Public rdir As Integer
Public A(maxfilas, MaxCol) As Single
Public AnguloZ As Single = 10
Public azul As Integer = 0
Public brocha As SolidBrush
Public Const MaxCol As Integer = 25
Public Const maxfilas As Integer = 10
Public cont As Integer = 0
Public tx As Single = 200
Public ty As Single = 200
Public Ex As Single = 0.1
Public Ey As Single = 0.1
Public grafico As Graphics
Public lim As Integer = 50
Public nc As Integer = 12
Public nf As Integer = 5
Public NombreArchivo As String = "E:\datos\ObjetosXY.txt"
Public NroObjeto As Integer = 0
Public pescaX As Single = 1
Public pescaY As Single = 1
Public pincel As Pen
Public prot As Single = 10
Public ptrasX As Single = 10
Public ptrasY As Single = 10
Public Transparencia As Integer = 123
Public vel As Integer = 10
Public verde As Integer = 0
Public rojo As Integer = 234
Public X(MaxCol) As Single
Public Y(MaxCol) As Single
Public Radio As Single = 20
La alfombra de Sierpiński
es un conjunto fractal descrito por primera vez por Wacław Sierpiński en 1916.1
Constituye una generalización a dos dimensiones del conjunto de Cantor. Comparte con
él muchas propiedades: también es un conjunto compacto, no numerable y de medida
nula. Su dimensión de Hausdorff-Besicovitch es
Construcción
La construcción de la alfombra de Sierpinski se define de forma recursiva:
1. Comenzamos con un cuadrado.
2. El cuadrado se corta en 9 cuadrados congruentes, y eliminamos el cuadrado central.
3. El paso anterior vuelve a aplicarse recursivamente a cada uno de los 8 cuadrados
restantes.
La alfombra de Sierpinski es el límite de este proceso tras un número infinito de
iteraciones.
Construcción de la alfombra de Sierpinski:
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -852-
(ver aplicación)
( ver en la aplicacion)
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -854-
Imports System.Drawing
Module Module1
Public Const dx As Single = 0.6
Public nro As Integer
Public ColorPen As Color = Color.FromArgb(255, 0, 0)
Public ColorBrocha As Color = Color.FromArgb(0, 255, 0)
Public ColorFondo As Color = Color.FromArgb(255, 255, 255)
Public Nombre As String
Public grosor As Integer = 1
''***********
Public ancho As Integer = 500
Public alto As Integer = 500
Public ancho1 As Integer = 400
Public alto1 As Integer = 400
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -856-
Public Cx As Integer = 0
Public Cy As Integer = 0
Public Cx1 As Integer
Public Cy1 As Integer
Public Const alfa As Single = 1.047
Function distancia(ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single,
ByVal y2 As Single)
distancia = Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2))
End Function
End Module
Imports System.Drawing
Public Class Form1
Private Sub GrosorDeLineaToolStripMenuItem_Click(sender As Object, e As
EventArgs) Handles GrosorDeLineaToolStripMenuItem.Click
grosor = InputBox("Ingrese grosor de linea", "Tamaño Linea", 2)
End Sub
Private Sub MnuAlfombraDeSierpinski_Click(sender As Object, e As EventArgs)
Handles MnuAlfombraDeSierpinski.Click
nro = nro + 1
Nombre = "Alfombra de Sierpiński "
FrmAlfombra.MdiParent = Me
FrmAlfombra.Text = Nombre & nro.ToString
FrmAlfombra.Show()
End Sub
Private Sub MnuTriánguloDeSierpinski_Click(sender As Object, e As EventArgs)
Handles MnuTriánguloDeSierpinski.Click
nro = nro + 1
Nombre = "Alfombra de Sierpiński "
frmTriangulo.MdiParent = Me
frmTriangulo.Text = Nombre & nro.ToString
frmTriangulo.Show()
End Sub
Private Sub MnuMontañaFractal_Click(sender As Object, e As EventArgs) Handles
MnuMontañaFractal.Click
nro = nro + 1
Nombre = "Montaña Fractal "
frmMontaña.MdiParent = Me
frmMontaña.Text = Nombre & nro.ToString
frmMontaña.Show()
End Sub
Sub Fractal(ByVal px1 As Single, ByVal py1 As Single, ByVal px2 As Single, ByVal
py2 As Single)
Dim ax As Single, ay As Single
Dim x1 As Single, y1 As Single, x2 As Single, y2 As Single, x3 As Single, y3 As
Single, rx As Single, ry As Single
ax = (px2 - px1) / 3.0
ay = (py2 - py1) / 3.0
pen5.Color = colorPen5
grafico5.DrawLine(pen5, Cx + px1, Cy + py1, Cx + px2, Cy + py2)
x1 = Cx + px1 + ax
y1 = Cy + py1 + ay
rx = ax * Math.Cos(alfa) - ay * Math.Sin(alfa)
ry = ax * Math.Sin(alfa) + ay * Math.Cos(alfa)
x2 = x1 + rx
y2 = y1 + ry
x3 = Cx + px1 + 2 * ax
y3 = Cy + py1 + 2 * ay
grafico5.DrawLine(pen5, x1, y1, x2, y2)
grafico5.DrawLine(pen5, x2, y2, x3, y3)
pen5.Color = ColorFondo5
grafico5.DrawLine(pen5, x1, y1, x3, y3)
' System.Threading.Thread.Sleep(vel) ' 1 segundo
If distancia(px1, py1, px2, py2) > 10 Then
Fractal(px1 + ax, py1 + ay, px1 + ax + rx, py1 + ay + ry)
Fractal(px1 + ax + rx, py1 + ay + ry, px1 + 2 * ax, py1 + 2 * ay)
Fractal(px1, py1, px1 + ax, py1 + ay)
Fractal(px1 + 2 * ax, py1 + 2 * ay, px2, py2)
End If
End Sub
FRACTALES DE MALDEBROT
Module Module1
Public brocha As SolidBrush
Public Const limite As Integer = 200
Public Grafico As Graphics
Public nc As Integer = 5
Public nf As Integer = 6 '6
Public Pen As Pen
Public vel As Integer = 10
Public nx As Integer = 100
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -864-
Public ny As Integer = 100
Public MaxIter As Integer = 10
Option Explicit On
Option Strict On
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class Form1
Dim Pen As Pen
Dim Grafico As Graphics
Dim brocha As SolidBrush
Sub plotPoint(ByVal zx As Single, ByVal zy As Single)
Grafico.FillRectangle(brocha, Cx + zx * Ex, cy + zy * Ey, 4, 4)
End Sub
DataGridView1.Rows(4).Cells(0).Value = "Cy"
DataGridView1.Rows(4).Cells(1).Value = Cy
DataGridView1.Rows(5).Cells(0).Value = "Ex"
DataGridView1.Rows(5).Cells(1).Value = Ex
DataGridView1.Rows(6).Cells(0).Value = "Ey"
DataGridView1.Rows(6).Cells(1).Value = Ey
End Sub
Private Sub btnIniciarTodo_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnIniciarTodo.Click
nx = CInt(DataGridView1.Rows(0).Cells(1).Value)
ny = CInt(DataGridView1.Rows(1).Cells(1).Value)
MaxIter = CInt(DataGridView1.Rows(2).Cells(1).Value)
Cx = CSng(DataGridView1.Rows(3).Cells(1).Value)
cy = CSng(DataGridView1.Rows(4).Cells(1).Value)
Ex = CSng(DataGridView1.Rows(5).Cells(1).Value)
Ey = CSng(DataGridView1.Rows(6).Cells(1).Value)
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnBorrar.Click
Grafico.Clear(Color.White)
End Sub
End Class
Imports System.IO
Module Module1
Public Structure Puntos
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -868-
Public nro As Integer
Public X As Single
Public Y As Single
Public Z As Single
Public Rela As Integer
End Structure
Public modelo As Integer = 0
Public AnguloX As Integer = 0
Public AnguloY As Integer = 0
Public AnguloZ As Integer = 0
Public Const limite As Integer = 100
Public vel As Integer = 10
Public Const maximo As Integer = 7000
Public P(maximo) As Puntos
Public P1(maximo) As Puntos
Public Grafico As Graphics
Public ColorFondo As Color = Color.FromArgb(255, 255, 255)
Public pincel As Pen
Public Brocha As SolidBrush
Public valor As Single = 100 ' mas alto la monta
Public factor As Single = 0.5 ' 0.5 ' se relaciona con el valor factor proyeccion
Public ancho As Integer = 700
Public alto As Integer = 500
Public Ndivisiones As Integer = 5
Public ContPuntos As Integer
Public MiFuente As New Font("Verdana", 24, FontStyle.Bold)
Public Tx As Single = 0
Public Ty As Single = 0
Public tz As Single = 0
Public Ex As Single = 1
Public Ey As Single = 1
Public Ez As Single = 1
Public VEx As Single = 0.1
Public VEy As Single = 0.1
Public VEz As Single = 0.1
Public CARAS(maximo, 4) As Integer
Public Normales(maximo, 4) As Single
Public D As Single = 1000
Public contcaras As Integer
Public ver1 As Integer, ver2 As Integer, ver3 As Integer, ver4 As Integer
Public Modo As Integer = 0
Public NombreArchivoPuntos = "E:\datos\puntos4x28.txt"
Public NombreArchivoCaras = "E:\datos\caras4x28.txt"
Sub RotacionXYZ(P() As Puntos, ByVal AnguloX As Single, ByVal AnguloY As
Single, ByVal anguloZ As Single, np As Integer)
Dim x1 As Single, y1 As Single, z1 As Single
Dim x2 As Single, y2 As Single, z2 As Single
Dim fila As Integer = 0
Dim arx = AnguloX * Math.PI / 180
For fila = 0 To np - 1
x1 = P(fila).X
y1 = P(fila).Y
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -869-
z1 = P(fila).Z
x2 = x1
y2 = CSng(y1 * Math.Cos(arx) - z1 * Math.Sin(arx))
z2 = CSng(y1 * Math.Sin(arx) + z1 * Math.Cos(arx))
P(fila).X = x2
P(fila).Y = y2
P(fila).Z = z2
Next
Dim ary = AnguloY * Math.PI / 180
For fila = 0 To np - 1
x1 = P(fila).X
y1 = P(fila).Y
z1 = P(fila).Z
x2 = CSng(x1 * Math.Cos(ary) - z1 * Math.Sin(ary))
y2 = y1
z2 = CSng(-x1 * Math.Sin(ary) + z1 * Math.Cos(ary))
P(fila).X = x2
P(fila).Y = y2
P(fila).Z = z2
Next
REM rotacion Z
Dim arz = anguloZ * Math.PI / 180
For fila = 0 To np - 1
x1 = P(fila).X
y1 = P(fila).Y
z1 = P(fila).Z
x2 = CSng(x1 * Math.Cos(arz) - y1 * Math.Sin(arz))
y2 = CSng(x1 * Math.Sin(arz) + y1 * Math.Cos(arz))
z2 = z1
P(fila).X = x2
P(fila).Y = y2
P(fila).Z = z2
Next
End Sub
Sub TraslacionXYZ(P() As Puntos, ByVal tx As Single, ByVal ty As Single, ByVal tz
As Single, nf As Integer)
Dim fila As Integer
For fila = 0 To nf - 1
P(fila).X = P(fila).X + tx
P(fila).Y = P(fila).Y + ty
P(fila).Z = P(fila).Z + tz
Next
End Sub
Sub EscaladoXYZ(P() As Puntos, ByVal tx As Single, ByVal ty As Single, ByVal tz As
Single, nf As Integer)
Dim fila As Integer
For fila = 0 To nf - 1
P(fila).X = P(fila).X * ex
P(fila).Y = P(fila).Y * ey
P(fila).Z = P(fila).Z * ez
Next
End Sub
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -870-
Sub CopiarVector(ByVal A() As Puntos, ByRef B() As Puntos, ByVal n As Integer)
Dim fila As Integer
For fila = 0 To n
B(fila) = A(fila)
Next
End Sub
Sub ObtenerNormales()
Dim Pe As Single, R As Single
Dim AX As Single, Ay As Single, Az As Single, Bx As Single, By As Single, Bz As
Single
Dim NX As Single, Ny As Single, Nz As Single, Nx1 As Single, Ny1 As Single, Nz1
As Single
Dim x1 As Single, y1 As Single, z1 As Single
Dim x2 As Single, y2 As Single, z2 As Single
Dim x3 As Single, y3 As Single, z3 As Single
Form1.ListBox1.Items.Add("Normales")
For fila = 0 To contcaras - 1
x1 = P1(CARAS(fila, 0)).X
y1 = P1(CARAS(fila, 0)).Y
z1 = P1(CARAS(fila, 0)).Z
x2 = P1(CARAS(fila, 1)).X
y2 = P1(CARAS(fila, 1)).Y
z2 = P1(CARAS(fila, 1)).Z
x3 = P1(CARAS(fila, 2)).X
y3 = P1(CARAS(fila, 2)).Y
z3 = P1(CARAS(fila, 2)).Z
AX = x2 - x1
Ay = y2 - y1
Az = z2 - z1
Bx = x3 - x2
By = y3 - y2
Bz = z3 - z2
NX = Ay * Bz - Az * By
Ny = AX * Bz - Az * Bx
Nz = AX * By - Ay * Bx
'PRODUCTO(CRUZ)
R = Math.Sqrt(NX * NX + Ny * Ny + Nz * Nz)
If R > 0 Then
Nx1 = NX / R
Else
Nx1 = 1000
End If
If R > 0 Then
Ny1 = Ny / R
Else
Ny1 = 1000
End If
If R > 0 Then
Nz1 = Nz / R
Else
Nz1 = 1000
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -871-
End If
Pe = Nx1 * 0 + Ny1 * 0 + Nz1 * D
Normales(fila, 0) = Nx1
Normales(fila, 1) = Ny1
Normales(fila, 2) = Nz1
Normales(fila, 3) = Pe
Form1.ListBox1.Items.Add("normal" & Normales(fila, 2))
Next
End Sub
Sub RecuperarPuntos(ByVal nombrearchivo As String, P() As Puntos, ByRef nf As
Integer)
Dim srLector As StreamReader
srLector = New StreamReader(nombrearchivo)
Dim fila As Integer = 0, col As Integer
Dim cadena As String = ""
Dim subcadena As String
Dim pos As Integer = 0
Dim inicio As Integer = 1
cadena = srLector.ReadLine()
Do While Not (cadena Is Nothing)
cadena = cadena & Chr(9)
inicio = 1
For col = 0 To 4
pos = InStr(inicio, cadena, Chr(9))
subcadena = Mid(cadena, inicio, pos - inicio)
Select Case col
Case 0 : P(fila).nro = CInt(subcadena)
Case 1 : P(fila).X = CSng(subcadena)
Case 2 : P(fila).Y = CSng(subcadena)
Case 3 : P(fila).Z = CSng(subcadena)
Case 4 : P(fila).Rela = CInt(subcadena)
P(fila).nro = subcadena
End Select
inicio = pos + 1
Next
fila = fila + 1
cadena = srLector.ReadLine()
Loop
nf = fila - 1
Console.WriteLine("Archivo {0} leido satisfactoriamente", nombrearchivo)
srLector.Close()
End Sub
Option Explicit On
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class Form1
Sub Iniciar()
DataGridView1.ColumnCount = 6
DataGridView1.RowCount = 5
Dim fila As Integer
For fila = 1 To 5
DataGridView1.Columns(fila).Width = 50
Next
For fila = 0 To DataGridView1.RowCount - 1
DataGridView1.Rows(fila).HeaderCell.Value = fila.ToString
Next
DataGridView1.Columns(0).HeaderText = "PARAMETROS"
DataGridView1.Columns(1).HeaderText = "UNIDAD"
DataGridView1.Columns(2).HeaderText = "EjeX"
DataGridView1.Columns(3).HeaderText = "Eje Y"
DataGridView1.Columns(4).HeaderText = "Eje Z"
DataGridView1.Columns(5).HeaderText = "D o W"
End Sub
Sub Rectangulo(ByVal px1 As Single, ByVal py1 As Single, ByVal pz1 As Single, _
ByVal px2 As Single, ByVal py2 As Single, ByVal pz2 As Single, _
ByVal px3 As Single, ByVal py3 As Single, ByVal pz3 As Single, _
ByVal px4 As Single, ByVal py4 As Single, ByVal pz4 As Single, _
ByVal ndivisiones As Integer, ByVal valor As Single, _
ByVal ver1 As Integer, ByVal ver2 As Integer, ByVal ver3 As Integer, ByVal ver4
As Integer)
Dim v1 As Integer, v2 As Integer, v3 As Integer, v4 As Integer
Dim v12 As Integer, v23 As Integer, v34 As Integer, v14 As Integer
Dim vmedio As Integer
Dim px12 As Single, py12 As Single, pz12 As Single
Dim px23 As Single, py23 As Single, pz23 As Single
Dim px34 As Single, py34 As Single, pz34 As Single
Dim px14 As Single, py14 As Single, pz14 As Single
Dim xmed As Single, ymed As Single, zmed As Single
Dim puntocentral As Integer
If (ndivisiones > 1) Then
xmed = (px1 + px2 + px3 + px4) / 4.0
ymed = (py1 + py2 + py3 + py4) / 4.0
'zmed = (pz1 + pz2 + pz3 + pz4) / 4.0 + Int(Rnd() * valor)
zmed = (pz1 + pz2 + pz3 + pz4) / 4.0 - valor + Int(Rnd() * 2 * valor)
ContPuntos = ContPuntos + 1
puntocentral = ContPuntos
P(ContPuntos).nro = ContPuntos
P(ContPuntos).X = xmed
P(ContPuntos).Y = ymed
P(ContPuntos).Z = zmed
P(ContPuntos).Rela = puntocentral
vmedio = puntocentral
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -874-
px12 = (px1 + px2) / 2.0
px23 = (px2 + px3) / 2.0
px34 = (px3 + px4) / 2.0
px14 = (px1 + px4) / 2.0
ContPuntos = ContPuntos + 1
P(ContPuntos).nro = ContPuntos
P(ContPuntos).X = px34
P(ContPuntos).Y = py34
P(ContPuntos).Z = pz34
P(ContPuntos).Rela = puntocentral
' CARAS(ContCaras).P3 = P(ContPuntos).nro
v34 = ContPuntos
ContPuntos = ContPuntos + 1
P(ContPuntos).nro = ContPuntos
P(ContPuntos).X = px14
P(ContPuntos).Y = py14
P(ContPuntos).Z = pz14
P(ContPuntos).Rela = puntocentral
v14 = ContPuntos
v1 = ver1
v2 = ver2
v3 = ver3
v4 = ver4
Rectangulo(px1, py1, pz1, px12, py12, pz12, xmed, ymed, zmed, px14, py14,
pz14, ndivisiones - 1, valor * factor, v1, v12, vmedio, v14)
Rectangulo(px12, py12, pz12, px2, py2, pz2, px23, py23, pz23, xmed, ymed,
zmed, ndivisiones - 1, valor * factor, v12, v2, v23, vmedio)
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -875-
Rectangulo(xmed, ymed, zmed, px23, py23, pz23, px3, py3, pz3, px34, py34,
pz34, ndivisiones - 1, valor * factor, vmedio, v23, v3, v34)
Rectangulo(px14, py14, pz14, xmed, ymed, zmed, px34, py34, pz34, px4, py4,
pz4, ndivisiones - 1, valor * factor, v14, vmedio, v34, v4)
Else
If ndivisiones = 1 Then
CARAS(contcaras, 0) = ver1
CARAS(contcaras, 1) = ver2
CARAS(contcaras, 2) = ver3
CARAS(contcaras, 3) = ver4
contcaras = contcaras + 1
End If
End If
End Sub
Sub graficarCara(ByVal contcaras As Integer)
Dim X1 As Single, y1 As Single, z1 As Single
Dim X2 As Single, y2 As Single, z2 As Single
Dim px1 As Single, py1 As Single
Dim px2 As Single, py2 As Single
Dim Figura(3) As Point
Dim col As Integer
Dim color1 As Integer
For fila = 0 To contcaras - 1
For col = 0 To 2
X1 = P1(CARAS(fila, col)).X
y1 = P1(CARAS(fila, col)).Y
z1 = P1(CARAS(fila, col)).Z
X2 = P1(CARAS(fila, col + 1)).X
y2 = P1(CARAS(fila, col + 1)).Y
z2 = P1(CARAS(fila, col + 1)).Z
px1 = (X1 * D) / (D + z1)
py1 = (y1 * D) / (D + z1)
px2 = (X2 * D) / (D + z2)
py2 = (y2 * D) / (D + z2)
Figura(col).X = px1
Figura(col).Y = py1
Next
Figura(3).X = px2
Figura(3).Y = py2
If Normales(fila, 2) > 0 Then 'solo dibuja si el normal es mayor que 0
Select Case Modo
Case 0
Grafico.DrawPolygon(pincel, Figura)
Case 1
color1 = Normales(fila, 2) * 255
Select Case modelo
Case 0 ' gris
Brocha.Color = Color.FromArgb(color1, color1, color1)
Case 1 ' rojo
Brocha.Color = Color.FromArgb(color1, 0, 0)
Case 2 ' verde
Brocha.Color = Color.FromArgb(0, color1, 0)
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -876-
Case 3 ' azul
Brocha.Color = Color.FromArgb(0, 0, color1)
Case 4 ' rojo-verde
Brocha.Color = Color.FromArgb(255 - color1, color1, 0)
Case 5 ' verde-rojo
Brocha.Color = Color.FromArgb(color1, 255 - color1, 0)
Case 6 ' amarillo -azul
Brocha.Color = Color.FromArgb(color1, color1, 255 - color1)
Case 7 ' amarillo -azul
Brocha.Color = Color.FromArgb(255 - color1, 255 - color1, 255 - color1)
End Select
Grafico.FillPolygon(Brocha, Figura, FillMode.Alternate)
Case 2
color1 = Normales(fila, 2) * 255
Select Case modelo
Case 0 ' gris
Brocha.Color = Color.FromArgb(color1, color1, color1)
Case 1 ' rojo
Brocha.Color = Color.FromArgb(color1, 0, 0)
Case 2 ' verde
Brocha.Color = Color.FromArgb(0, color1, 0)
Case 3 ' azul
Brocha.Color = Color.FromArgb(0, 0, color1)
Case 4 ' rojo-verde
Brocha.Color = Color.FromArgb(255 - color1, color1, 0)
Case 5 ' verde-rojo
Brocha.Color = Color.FromArgb(color1, 255 - color1, 0)
Case 6 ' amarillo -azul
Brocha.Color = Color.FromArgb(color1, color1, 255 - color1)
Case 7 ' amarillo -azul
Brocha.Color = Color.FromArgb(255 - color1, 255 - color1, 255 - color1)
End Select
Grafico.FillPolygon(Brocha, Figura, FillMode.Alternate)
Grafico.DrawPolygon(pincel, Figura)
End Select
End If
' Grafico.DrawLine(pincel, px1, py1, px2, py2)
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim col As Integer
PictureBox1.Width = ancho + 10
PictureBox1.Height = alto + 10
PictureBox1.BackColor = ColorFondo
Grafico = PictureBox1.CreateGraphics
MiFuente = New Font("arial", 11, FontStyle.Bold)
Brocha = New SolidBrush(Color.Red)
pincel = New Pen(Color.Blue, 1)
Iniciar()
DataGridView2.ColumnCount = 5
DataGridView2.RowCount = 1
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -877-
For col = 0 To 4
DataGridView2.Columns(col).Width = 60
Next
End Sub
Private Sub MnuMontaña_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnMontaña.Click
Dim i, j As Integer
Grafico.Clear(Color.Black)
Randomize()
Dim Px1 As Integer = 100, py1 As Integer = 100, pz1 As Integer = 10
Dim px2 As Integer = 600, py2 As Integer = 100, pz2 As Integer = 10
Dim px3 As Integer = 600, py3 As Integer = 400, pz3 As Integer = 10
Dim px4 As Integer = 100, py4 As Integer = 400, pz4 As Integer = 10
contcaras = 0
ver1 = 0
ver2 = 1
ver3 = 2
ver4 = 3
P(0).nro = 0 : P(0).X = Px1 : P(0).Y = py1 : P(0).Z = pz1 : P(0).Rela = 1
P(1).nro = 1 : P(1).X = px2 : P(1).Y = py2 : P(1).Z = pz2 : P(1).Rela = 2
P(2).nro = 2 : P(2).X = px3 : P(2).Y = py3 : P(2).Z = pz3 : P(2).Rela = 3
P(3).nro = 3 : P(3).X = px4 : P(3).Y = py4 : P(3).Z = pz4 : P(3).Rela = 0
ContPuntos = 3
ListBox1.Items.Clear()
ListBox1.Items.Add("CANTIDAD de divisiones " & Ndivisiones)
Randomize()
Rectangulo(Px1, py1, pz1, px2, py2, pz2, px3, py3, pz3, px4, py4, pz4,
Ndivisiones, valor, ver1, ver2, ver3, ver4)
ListBox1.Items.Add("CANTIDAD DE Caras " & contcaras)
ListBox1.Items.Add("CANTIDAD DE puntos " & ContPuntos)
For i = 0 To ContPuntos
ListBox1.Items.Add("Punto Nro" & P(i).nro & " X " & P(i).X & " Y " & P(i).Y & " Z "
& P(i).Z & "rela " & P(i).Rela)
Next
pincel.Color = Color.Red
Dim swEscritor As StreamWriter
swEscritor = New StreamWriter("E:\DATOS\FRACTAL.txt")
For i = 0 To ContPuntos
swEscritor.WriteLine("{0}{1}{2}{3}{4}{5}{6}{7}{8}", P(i).nro, Chr(9), P(i).X, Chr(9),
P(i).Y, Chr(9), P(i).Z, Chr(9), P(i).Rela)
Next
swEscritor.Close()
swEscritor = New StreamWriter("E:\DATOS\CARAS.txt")
For i = 0 To contcaras
For j = 0 To 3
swEscritor.Write("{0} {1}", CARAS(i, j), Chr(9))
Next
swEscritor.WriteLine()
Next
swEscritor.Close()
CopiarVector(P, P1, ContPuntos)
ObtenerNormales()
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -878-
graficarCara(contcaras)
End Sub
Private Sub MnGraficar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnMontaña.Click
graficarCara(contcaras)
End Sub
Tx = DataGridView1.Rows(1).Cells(2).Value
Ty = DataGridView1.Rows(1).Cells(3).Value
tz = DataGridView1.Rows(1).Cells(4).Value
D = DataGridView1.Rows(1).Cells(5).Value
Ex = DataGridView1.Rows(2).Cells(2).Value
Ey = DataGridView1.Rows(2).Cells(3).Value
Ez = DataGridView1.Rows(2).Cells(4).Value
Modo = DataGridView1.Rows(3).Cells(2).Value
vel = DataGridView1.Rows(3).Cells(3).Value
modelo = DataGridView1.Rows(3).Cells(4).Value
Ndivisiones = DataGridView1.Rows(3).Cells(5).Value
x P(x) acum L 2
1 5,00 5 Q 10
2 20,00 25 C1 0,1
3 40,00 65 C3 5
4 25,00 90 Z 10
5 10,00 100 z 4
SUMA 100
Imports System.Drawing
Public Class Form1
Dim Grafico As Graphics
Dim ColorFondo As Color = Color.FromArgb(255, 255, 255)
Dim pen As Pen
Dim pen2 As Pen
Dim pen3 As Pen
Dim valor As Integer = 10
Dim ancho = 600, alto = 400
Dim BrochaSolida As SolidBrush
Sub mostrar(ByVal vector() As Single, ByVal n As Integer)
Dim i As Integer
For i = 0 To n - 1
ListBox1.Items.Add(i & " " & vector(i))
Next
End Sub
Sub MostrarMatriz(ByRef A(,) As Single, ByVal nf As Integer, ByVal nc As Integer)
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -884-
Dim fila As Integer, col As Integer
For col = 0 To nc - 1
DataGridView1.Columns(col).Width = 50
Next
DataGridView1.ColumnCount = 10
For fila = 0 To nf - 1
For col = 0 To nc - 1
DataGridView1.Rows(fila).Cells(col).Value = A(fila, col)
Next
Console.WriteLine()
Next
End Sub
Imports System.IO
Module Module1
Public Const maxfilas As Integer = 365
Public Const nprob As Integer = 10
Public ncol As Integer = 10
Public nfilas As Integer = maxfilas
Public vector(maxfilas) As Single
Public nro(nprob) As Single
Public p(nprob) As Single
Public A(nfilas, ncol) As Single
Public C1 As Single = 0.1
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -886-
Public C3 As Single = 5
Public Z1 As Single = 10
Public z2 As Single = 4
Public demora As Single = 2 'L
Public hizopedido As Integer = 0
Public Cx As Single = 100
Public Cy As Single = 200
Public ex As Single = 10
Public ey As Single = -10
Public CAcum As Single = 0
Sub RellenarMatriz(ByRef A(,) As Single, ByVal nro() As Single, ByVal vector() As
Single, ByVal np As Integer)
Dim fila As Integer
Dim I1 As Single = 8, I2 As Single, r As Integer
Dim t As Single = 0
Dim pedido As Single
Dim cmantenimiento As Single = 0, caprovisionamiento As Single = 0
Dim Ctotal As Single = 0
fila = 0
' primero inicializamos
A(fila, 0) = nro(fila)
A(fila, 1) = Z1
A(fila, 2) = vector(fila)
I2 = A(fila, 1) - vector(0)
A(fila, 3) = I2
A(fila, 4) = pedido
cmantenimiento = C1 * A(fila, 1)
A(fila, 6) = cmantenimiento
A(fila, 7) = caprovisionamiento
Ctotal = cmantenimiento + caprovisionamiento
A(fila, 8) = Ctotal
CAcum = Ctotal
A(fila, 9) = Ctotal
A(fila, 0) = fila
For fila = 1 To nfilas - 1
r = vector(fila)
A(fila, 0) = fila
I1 = A(fila - 1, 3)
A(fila, 5) = 0
If t >= demora Then ' llega el pedido
I1 = I1 + pedido
A(fila - 1, 5) = pedido
t=0
pedido = 0
hizopedido = 0
Else
t=t+1
End If
A(fila, 1) = I1
A(fila, 2) = vector(fila)
I2 = I1 - r
A(fila, 3) = I2
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -887-
A(fila, 4) = 0
If (I2 < z2) Then
If hizopedido = 0 Then ' solo aumenta cuando no se hizo pedido
pedido = Z1 - I2
A(fila, 4) = pedido
t=0
hizopedido = 1
End If
End If
' calculo de costos
A(fila, 6) = 0
A(fila, 7) = 0
If A(fila, 1) > 0 Then
cmantenimiento = C1 * A(fila, 1)
A(fila, 6) = cmantenimiento
End If
If A(fila, 4) > 0 Then
caprovisionamiento = C3
Else
caprovisionamiento = 0
End If
A(fila, 7) = caprovisionamiento
Ctotal = cmantenimiento + caprovisionamiento
A(fila, 8) = Ctotal
CAcum = CAcum + Ctotal
A(fila, 9) = CAcum
Next
End Sub
Sub GrabarMatriz(ByVal A(,) As Single, ByVal nf As Integer, ByVal nc As Integer)
Dim swEscritor = New StreamWriter("E:\DATOS\Invent5x30.txt")
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
swEscritor.Write("{0}{1} ", A(fila, col), Chr(9))
Next
swEscritor.WriteLine()
Next
swEscritor.Close()
End Sub
Function generar(ByVal nro() As Single, ByVal p() As Single, ByVal n As Integer) As
Integer
Dim r As Integer, ng As Integer, i As Integer
r = Int(Rnd() * 100)
For i = 0 To n - 1
If (p(i) > r) Then
ng = nro(i)
Exit For
End If
Next
Return ng
End Function
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -888-
Sub rellenar(ByVal vector() As Single, ByVal nro() As Single, ByVal p() As Single,
ByVal nprob As Integer, ByVal nper As Integer)
Dim i As Integer
Randomize()
For i = 0 To nper - 1
vector(i) = generar(nro, p, nprob)
Next
End Sub
Sub Iniciar()
nro(0) = 1 : nro(1) = 2 : nro(2) = 3 : nro(3) = 4 : nro(4) = 5
p(0) = 5
p(1) = 25
p(2) = 65
p(3) = 90 : p(4) = 100
End Sub
End Module
Imports System.IO
Module Module1
Public srLector As StreamReader
Public A(10) As String
Public B(10) As String
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -889-
End Module
Imports System.IO
Public Class Form1
Public srLector1 As StreamReader
Public srLector2 As StreamReader
Public swEscritor As StreamWriter
Public A(200) As String
Public B(200) As String
Public nterminos As Integer = 0
Public Linea As String
Public texto As String = ""
Public texto2 As String = ""
Public ContadorLin As Integer = 1
Dim fila As Integer
Private Sub btnCargar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCargar.Click
srLector1 = New StreamReader("e:\datos\datos1.txt")
Linea = srLector1.ReadLine()
Do While Not (Linea Is Nothing)
ContadorLin += 1
texto = texto & Linea & vbCrLf
Linea = srLector1.ReadLine()
Loop
TextBox1.Text = texto
Me.Text = ContadorLin
srLector1.Close()
Console.ReadLine()
End Sub
Private Sub btnCambiar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCambiar.Click
Dim nombre1 As String
Dim nombre2 As String
texto2 = texto
For fila = 0 To nterminos
nombre1 = A(fila)
nombre2 = B(fila)
texto2 = Replace(texto2, nombre1, nombre2)
Next
TextBox1.Text = texto
TextBox2.Text = texto2
End Sub
Private Sub btnTerminos_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnTerminos.Click
srLector2 = New StreamReader("E:\datos\terminos1.txt")
Dim cadena As String = ""
Dim subcadena1 As String
Dim subcadena2 As String
Dim cont As Integer = 0
cadena = srLector2.ReadLine()
Dim pos As Integer = 0
Do While Not (cadena Is Nothing)
pos = InStr(1, cadena, Chr(9))
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -890-
pos = InStr(1, cadena, Chr(9))
subcadena1 = Mid(cadena, 1, pos - 1)
A(cont) = subcadena1
subcadena2 = Mid(cadena, pos + 1, Len(cadena) - pos)
B(cont) = subcadena2
cadena = srLector2.ReadLine()
cont += 1
Loop
Me.Text = "term" & cont
srLector2.Close()
ListBox1.Items.Clear()
ListBox2.Items.Clear()
nterminos = cont
For i = 0 To nterminos - 1
ListBox1.Items.Add(A(i))
ListBox2.Items.Add(B(i))
Next
End Sub
Se tiene el siguiente diseño (puede usted variar los diseños )en excel encontrar los
puntos deseados si no los encuentra que la computadora muestre un mensaje de que
no se encontro, si la encuentra muestra en que fila y columna se encontro la meta y
cuantos movimiento hizo, y ademas la trayectoria recorrida
Buscador en modo consola grabe la matri con el nombre de 40x20
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -891-
Buscador en modo formulario
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
8 8 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 8
8 8 8 0 0 0 0 0 0 8 8 8 8 8 8 8 0 8 0 8 8 8 8 8 0 0 8 8 0 0 0 0 8 8 8 8 8 0 8 8
8 0 0 0 0 0 0 0 0 8 0 0 0 0 8 8 0 8 0 0 8 8 8 0 0 0 8 8 0 0 0 0 0 0 8 0 8 0 8 8
8 8 8 0 0 0 0 0 0 8 0 8 8 8 8 8 0 8 8 0 8 8 8 0 8 0 8 8 0 0 8 8 8 0 8 0 8 0 8 8
8 8 8 0 8 8 0 8 0 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 0 8 8 0 0 8 0 8 0 8 0 8 0 8 8
8 8 8 0 0 0 0 0 0 8 8 8 8 8 8 8 8 8 8 8 8 8 0 8 8 0 8 8 0 0 8 0 8 0 0 0 8 0 8 8
8 8 8 0 8 8 0 8 0 8 8 8 8 8 8 8 8 8 8 8 8 8 0 8 8 0 8 8 0 8 8 0 8 8 8 8 8 0 8 8
8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 8
8 8 8 0 8 8 8 8 0 8 8 8 8 8 8 8 0 8 8 8 8 8 8 8 8 0 8 8 8 8 8 8 8 8 8 8 8 0 8 8
8 8 8 0 8 8 8 8 0 8 8 8 8 8 8 8 0 8 8 8 8 8 8 8 8 0 8 8 8 8 8 8 8 8 8 8 8 0 8 8
8 8 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 8
8 8 8 0 8 8 8 8 0 8 8 8 0 8 8 8 0 8 8 8 8 8 8 8 8 0 8 8 8 8 0 8 8 8 8 8 8 0 8 8
8 8 8 0 8 8 8 8 0 8 8 8 0 8 8 8 0 8 0 0 0 0 0 0 8 0 8 0 0 0 0 0 0 0 8 0 0 0 0 8
8 8 8 0 8 8 8 8 0 8 8 8 0 8 8 8 0 8 0 8 8 8 8 0 8 0 8 8 8 8 8 8 8 8 8 0 8 8 0 8
8 8 8 0 8 8 8 8 0 0 0 0 0 0 0 0 0 8 0 8 8 0 8 0 8 0 0 0 0 0 0 0 0 0 0 0 8 8 0 8
8 8 8 0 8 8 8 8 0 0 0 0 0 0 0 0 0 8 0 0 0 0 8 0 8 0 0 0 0 0 0 8 8 0 0 0 0 0 0 8
8 8 8 0 0 0 0 0 0 0 8 8 8 8 8 8 0 8 8 8 8 8 8 0 8 8 8 8 8 8 0 8 8 0 8 8 8 8 8 8
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 0 0 0 0 0 0 0 0 8 8 8 8 8 8 0 0 0 0 8 8 8 8 8 8
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
Imports System.Drawing
Public Class Form1
Dim resultado, fila, col As Integer
Sub MostrarMatrizFormulario(A(,) As Integer, nf As Integer, nc As Integer)
Dim fila, col As Integer
Dim Cadena As String
For fila = 0 To nf - 1
Cadena = ""
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -892-
For col = 0 To nc - 1
Cadena = Cadena & Str(A(fila, col) & vbTab)
Next
ListBox1.Items.Add(Cadena)
Next
End Sub
Sub Iniciar()
DataGridView1.ColumnCount = 3
DataGridView1.RowCount = 4
DataGridView1.Columns(0).Width = 60
DataGridView1.Columns(1).Width = 34
DataGridView1.Columns(2).Width = 34
DataGridView1.Columns(0).HeaderText = "Propiedad"
DataGridView1.Columns(1).HeaderText = "X"
DataGridView1.Columns(2).HeaderText = "Y"
DataGridView1.Rows(0).Cells(0).Value = "PosBuscador"
DataGridView1.Rows(0).Cells(1).Value = xbusca
DataGridView1.Rows(0).Cells(2).Value = ybusca
DataGridView1.Rows(1).Cells(0).Value = "PosMeta"
DataGridView1.Rows(1).Cells(1).Value = xmeta
DataGridView1.Rows(1).Cells(2).Value = ymeta
DataGridView1.Rows(2).Cells(0).Value = "Escalas"
DataGridView1.Rows(2).Cells(1).Value = Ex
DataGridView1.Rows(2).Cells(2).Value = Ey
DataGridView1.Rows(3).Cells(0).Value = "velocidad"
DataGridView1.Rows(3).Cells(1).Value = vel
End Sub
Imports System.IO
Module Module1
Sub MAIN()
Dim resultado, fila, col As Integer
Dim menor1, Dir As Integer
Dir = 1
RecuperarMatriz(NombreArchivo, Matriz, nfilas, ncol)
' encuentra la meta
CopiarMatriz(Matriz, MatrizW, nfilas, ncol)
VerMatriz(MatrizW, nfilas, ncol, cx, cy)
px1 = xbusca
py1 = ybusca
px2 = xmeta
py2 = ymeta
'VerMatriz(MatrizW, nfilas, ncol, cx, cy)
IniciarDistancias(MatrizW, VX1, VY1, VX2, VY2, px1, py1, px2, py2, meta)
'VerMatriz(MatrizW, nfilas, ncol, cx, cy)
resultado = bUSCAR(MatrizW, VX1, VY1, VX2, VY2, px1, py1, Cont, ContMov)
'VerMatriz(MatrizW, nfilas, ncol, cx, cy)
If resultado >= 0 Then
ne1 = Cont
DejarCamino(MatrizW, VX1, VY1, ne1, busca1)
'VerMatriz(MatrizW, nfilas, ncol, cx, cy)
px1 = VX1(ne1)
py1 = VY1(ne1)
Console.WriteLine("meta encontrada X={0} y {1} con {2} ne1 {3} cont mov ",
px1, py1, ne1, ContMov)
' Exit Sub
End If
' ne2 = Cont
'VerMatriz(MatrizW, nfilas, ncol, cx, cy)
bUSCARCruces(MatrizW, VX1, VY1, VA1, VL2, ne1, ne2, busca1, Camino)
'insertar el primer elemento
Console.WriteLine()
For col = ne2 To 1 Step -1
VL2(col) = VL2(col - 1)
Next
VL2(0) = 0
VL2(ne2 + 1) = ne1
ne2 = ne2 + 2
'Mostrar3Vectores(VA1, VL2, VL2, ne2)
' ENCONTRAR DISTANCIAS
Console.Clear()
For fila = 0 To ne2 - 1
For col = 0 To ne2 - 1
px1 = VX1(VL2(fila))
py1 = VY1(VL2(fila))
px2 = VX1(VL2(col))
py2 = VY1(VL2(col))
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -899-
menor1 = DistanciaMenorPuntos(px1, py1, px2, py2, VXMenor, VYMenor, meta)
MatrizD(fila, col) = menor1
MatrizDIR(fila, col) = Dir
'Console.WriteLine("fila {0} col {1} distmenor {2} dir {3} ", fila, col, menor1, Dir)
Next
Next
' Console.Clear()
Console.WriteLine("MATRIZ DISTANCIA")
MostrarMatriz(MatrizD, ne2, ne2)
Console.WriteLine("MATRIZ DIRECCION")
MostrarMatriz(MatrizDIR, ne2, ne2)
' GrabarMatriz(NombreArchivoMatriz, MatrizD, ne3, ne3)
' ''' PROCESO DE FLYD
Console.WriteLine("MATRIZ S")
ObtenerS(S, ne2, ne2)
MostrarMatriz(S, ne2, ne2)
floyd(MatrizD, S, ne2)
Console.WriteLine(" RESULTADOS despues de FLOYD")
Console.WriteLine(" matriz D")
MostrarMatriz(MatrizD, ne2, ne2)
Console.WriteLine(" matriz S")
MostrarMatriz(S, ne2, ne2)
'Console.Write(" ingrese nodo inicial de 0 a {0} ", ne3 - 1)
'nodoi = Console.ReadLine
'Console.Write("ingrese nodo final de 0 a {0} ", ne3 - 1)
'nodof = Console.ReadLine
nodoi = 0
nodof = ne2 - 1
dist = RutaMinima(MatrizD, S, Ruta, nodoi, nodof, Cont)
' Console.WriteLine(" la distancia total es {0}", dist)
'obtener trayectoria de la ruta en un vector
For col = 0 To ne2 - 1
Ruta1(col) = Ruta(ne2 - 1 - col)
Next
Console.Clear()
For col = 1 To ne2 - 1
lugar1 = Ruta1(col - 1)
lugar2 = Ruta1(col)
px1 = VX1(VL2(lugar1))
py1 = VY1(VL2(lugar1))
px2 = VX1(VL2(lugar2))
py2 = VY1(VL2(lugar2))
menor1 = DistanciaMenorPuntos(px1, py1, px2, py2, VXMenor, VYMenor, meta)
menorTotal = adicionar(VXMenorTotal, VYMenorTotal, menorTotal, VXMenor,
VYMenor, menor1)
Next
' Console.Clear()
VerMatriz(MatrizW, nfilas, ncol, cx, cy)
trazarRuta(VXMenorTotal, VYMenorTotal, menorTotal, cx, cy, color)
Console.ReadLine()
End Sub
End Module
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -900-
Imports System.IO
Module Module2
Sub ObtenerS(S(,) As Integer, Nfilas As Integer, Ncol As Integer)
Dim fila, col As Integer
For fila = 0 To Nfilas
For col = 0 To Ncol
If (fila = col) Then
S(fila, col) = -1
Else
S(fila, col) = col
End If
Next
Next
End Sub
Sub floyd(ByRef D(,) As Integer, ByRef S(,) As Integer, n As Integer)
Dim i, j, k As Integer
For k = 0 To n - 1
For i = 0 To n - 1
For j = 0 To n - 1
If (D(i, k) + D(k, j)) < D(i, j) Then
If i <> j And j <> k And i <> k Then
D(i, j) = D(i, k) + D(k, j)
S(i, j) = k
End If
End If
Next
Next
'Console.WriteLine(" ITER {0}", k)
'MostrarMatrizReal(D, nfilas, ncol)
'Console.WriteLine(" matriz S")
'MostrarMatrizE(S, nfilas, ncol)
Next
End Sub
Function RutaMinima(D(,) As Integer, S(,) As Integer, Ruta() As Integer, _
nodoi As Integer, nodof As Integer, ByRef cont As Integer) As Single
Dim valor = 0, col As Integer
Dim Dist, suma As Single
cont = 0
Ruta(0) = nodof
Dim control As Boolean = False
While (control = False)
valor = S(nodoi, nodof)
cont = cont + 1
If (valor = nodof) Then
control = True
Else
Ruta(cont) = valor
nodof = valor
End If
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -901-
End While
Ruta(cont) = nodoi
Console.WriteLine(" la ruta es ")
For col = cont To 0 Step -1
Console.Write(" ==>{0} ", Ruta(col))
Next
Console.WriteLine("Distancias")
For col = cont To 1 Step -1
Dist = D(Ruta(col), Ruta(col - 1))
suma = suma + Dist
Console.Write(" ==> {0}", Dist)
Next
Return suma
End Function
Sub CopiarMatriz(A(,) As Integer, B(,) As Integer, nf As Integer, nc As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
B(fila, col) = A(fila, col)
Next
Next
End Sub
Function ContarLetra(Cadena As String, letra As Char)
Dim LARGO As Integer = Len(Cadena)
Dim cont, cant As Integer
For cont = 0 To LARGO - 1
If Cadena(cont) = letra Then
cant = cant + 1
End If
Next
Return cant + 1
End Function
Sub RecuperarMatriz(ByVal nombrearchivo As String, ByRef A(,) As Integer, ByRef
nf As Integer, ByRef nc As Integer)
Dim srLector As StreamReader
srLector = New StreamReader(nombrearchivo)
Dim fila As Integer, col As Integer
Dim cadena As String = ""
Dim subcadena As String
Dim pos As Integer = 0
Dim inicio As Integer = 1
cadena = srLector.ReadLine()
nc = ContarLetra(cadena, vbTab)
Do While Not (cadena = "")
cadena = cadena & vbTab
inicio = 1
For col = 0 To nc - 1
pos = InStr(inicio, cadena, Chr(9))
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, col) = Val(subcadena)
inicio = pos + 1
Next
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -902-
fila = fila + 1
cadena = srLector.ReadLine()
Loop
nf = fila
Console.WriteLine("Archivo leido satisfactoriamente")
srLector.Close()
End Sub
Sub VerMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer, ByVal
cx As Integer, ByVal cy As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
If A(fila, col) <= 15 Then
Console.SetCursorPosition(cx + col, cy + fila)
' Console.BackgroundColor = CType(A(fila, col), ConsoleColor)
Console.ForegroundColor = A(fila, col) + 5
Console.Write("{0}", A(fila, col))
End If
Next
Next
End Sub
Sub GrabarMatriz(NombreArchivo As String, A(,) As Integer, nf As Integer, nc As
Integer)
Dim fila, col As Integer
Dim Archivo As New StreamWriter(NombreArchivo)
For fila = 0 To nf - 1
For col = 0 To nc - 1
Archivo.Write("{0} {1}", A(fila, col), vbTab)
Next
Archivo.WriteLine()
Next
Archivo.Close()
MsgBox("archivo " & NombreArchivo & "grabado")
End Sub
Sub MostrarMatriz(A(,) As Integer, nf As Integer, nc As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Console.Write("{0} {1}", A(fila, col), vbTab)
Next
Console.WriteLine()
Next
End Sub
Function encontrarcamino(A(,) As Integer, px As Integer, py As Integer, ByRef
camino As Integer, meta As Integer) As Integer
Dim resultado As Integer = -1
'VerMatriz(A, nfilas, ncol, cx, cy)
If px <= 0 Or py <= 0 Then Return -1
If A(py, px + 1) = meta Or A(py + 1, px) = meta Or A(py, px - 1) = meta Or A(py - 1,
px) = meta Then
Return 8
End If
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -903-
Imports System.Drawing
Module Module3
Public pluma As Pen
Public brocha As SolidBrush
Public grafico As Graphics
Public menorTotal As Integer = 0
Public lugar1 As Integer = 0
Public lugar2 As Integer = 0
Public ne1 As Integer = 0 ' nro de elmento del vector tod el vecto
Public ne2 As Integer = 0 ' nro de elmento del vector de cruces
Public Cont As Integer
VXMenor(menor - 1) = px1
Vymenor(menor - 1) = py1
VXMenor(menor) = px2
Vymenor(menor) = py2
End If
End If
Return menor
End Function
End Module
Se ingresas 4 puntos ( puntos inicial y final de dos rectas) determiner si esos puntos se
Cruzan o no se Cruzan
Module Module1
Sub Main()
Dim resultado1 As Integer = 0 ' " 0 no hay cruce 1 hay cruce
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -910-
RecuperarPuntos(X, Y, np)
Console.WriteLine(" vector X")
Imprimir(X, np)
Console.WriteLine(" vector Y")
Imprimir(Y, np)
resultado1 = Interseccion(X, Y)
Console.WriteLine()
If resultado1 = 1 Then
Console.WriteLine(" EL valor es =={0} HAY CRUCE ", resultado1)
Else
Console.WriteLine(" EL valor es =={0} no hay cruce ", resultado1)
End If
Console.ReadLine()
End Sub
End Module
Imports System.IO
Module Module2
Public X(4) As Single
Public Y(4) As Single
Public np As Integer = 4
Public Sub RecuperarPuntos(ByVal X() As Single, ByVal Y() As Single, ByVal nf As
Integer)
Dim fila As Integer
Dim cadena As String
Dim pos As Integer
Dim srLector = New StreamReader("E:\datos\Puntos2x4.txt")
For fila = 0 To nf - 1
cadena = srLector.ReadLine()
pos = InStr(1, cadena, Chr(9))
X(fila) = Mid(cadena, 1, pos - 1)
Y(fila) = Mid(cadena, pos + 1, Len(cadena))
Next
srLector.Close()
End Sub
Function Interseccion(ByVal X() As Single, ByVal Y() As Single) As Integer
Dim resultado As Integer
Dim XA(4) As Single
Dim YA(4) As Single
Dim xmin As Single
Dim ymin As Single
Dim xmax As Single
Dim ymax As Single
Dim px As Single
Dim py As Single
copiar(X, XA, 4)
limites(XA, xmin, xmax)
REM Console.WriteLine(" valores de xmin {0} xmax {1} ", xmin, xmax)
copiar(Y, YA, 4)
limites(YA, ymin, ymax)
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -911-
If (X(0) = X(2) And Y(0) = Y(2)) Or (X(1) = X(3) And Y(1) = Y(3)) Then
resultado = 0
Else
px = ((X(0) * Y(1) - Y(0) * X(1)) * (X(2) - X(3)) - (X(0) - X(1)) * (X(2) * Y(3) - Y(2) *
X(3))) / ((X(0) - X(1)) * (Y(2) - Y(3)) - (Y(0) - Y(1)) * (X(2) - X(3)))
py = ((X(0) * Y(1) - Y(0) * X(1)) * (Y(2) - Y(3)) - (Y(0) - Y(1)) * (X(2) * Y(3) - Y(2) *
X(3))) / ((X(0) - X(1)) * (Y(2) - Y(3)) - (Y(0) - Y(1)) * (X(2) - X(3)))
If px >= xmin And px <= xmax And py >= ymin And py <= ymax Then
resultado = 1
Else
resultado = 0
End If
End If
Return resultado
End Function
Option Explicit On
Imports System.Drawing
Public Class Form1
Dim px1 As Integer
Dim py1 As Integer
Dim Grafico As Graphics
Dim ColorFondo As Color = Color.FromArgb(255, 255, 255)
Dim pen1 As Pen
Dim pen2 As Pen
Dim X(maxfilas) As Single
Dim Y(maxfilas) As Single
Dim Cx As Integer = 100
Dim Cy As Integer = 300
Dim ex As Single = 1
Dim ey As Single = -1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Grafico = PictureBox1.CreateGraphics
pen1 = New Pen(Color.FromArgb(255, 0, 0), 2)
pen2 = New Pen(Color.FromArgb(0, 0, 255), 3)
End Sub
Private Sub BtnBorrar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnBorrar.Click
Grafico.Clear(Color.White)
End Sub
Private Sub Btndibujar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Btndibujar.Click
Dim fila As Integer
Dim resultado1 As Integer = 0
Dim cadena1 As String
Dim cadenaPos As String
Dim psx As Integer
Dim psy As Integer
Dim pos As Integer
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -914-
Dim px1 As Integer = 16
Dim py1 As Integer = 6
Dim valor As Integer = 0
Grafico.DrawLine(pen1, 0, Cy, Cx * 2, Cy)
Grafico.DrawLine(pen1, Cx, 0, Cx, Cy * 2)
RecuperarTabla(Tabla, nreg, ncampos)
MostrarTabla(Tabla, nreg, ncampos)
For fila = 0 To nreg - 1
cadena1 = Tabla(fila, 2)
np = Tabla(fila, 1)
cadenaPos = Tabla(fila, 3)
pos = InStr(1, cadenaPos, ";")
psx = Mid(cadenaPos, 1, pos - 1)
psy = Mid(cadenaPos, pos + 1, Len(cadenaPos))
ObtenerVectores(X, Y, np, cadena1)
graficar(X, Y, Cx, Cy, ex, ey, np)
Next
End Sub
Sub graficar(ByVal X() As Single, ByVal Y() As Single, ByVal Cx As Integer, ByVal cy
As Integer, ByVal ex As Single, ByVal ey As Single, ByVal np As Integer)
Dim fila As Integer
For fila = 1 To np
Grafico.DrawLine(pen2, Cx + X(fila - 1) * ex, cy + Y(fila - 1) * ey, Cx + X(fila) *
ex, cy + Y(fila) * ey)
Next
End Sub
Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
ListBox1.Items.Clear()
Dim informe As String
Dim retorno As Integer = 0
Dim fila As Integer
Dim resultado1 As Integer = 0
Dim valor As Integer = 0
Dim psx As Integer
Dim psy As Integer
Dim pos As Integer
Dim cadena1 As String
Dim cadenaPos As String
Me.Text = "X = " & e.X & " Y = " & e.Y
px1 = e.X - Cx
py1 = -(e.Y - Cy)
txtX.Text = px1
txtY.Text = py1
X1(0) = px1
Y1(0) = py1
fila = 1
For fila = 0 To nreg - 1
cadena1 = Tabla(fila, 2)
np = Tabla(fila, 1)
cadenaPos = Tabla(fila, 3)
pos = InStr(1, cadenaPos, ";")
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -915-
psx = Mid(cadenaPos, 1, pos - 1)
psy = Mid(cadenaPos, pos + 1, Len(cadenaPos))
ObtenerVectores(X, Y, np, cadena1)
X1(1) = psx
Y1(1) = psy
valor = 0
For k = 1 To np
X1(2) = X(k - 1) : Y1(2) = Y(k - 1)
X1(3) = X(k) : Y1(3) = Y(k)
resultado1 = Interseccion(X1, Y1)
If resultado1 = 1 Then
valor = 1
Exit For
End If
Next
ListBox1.Items.Add(" EL valor es == " & valor)
If valor = 0 Then
informe = Tabla(fila, 4)
Exit For
End If
Next
If valor = 0 Then
TextBox1.Text = informe
Else
TextBox1.Text = "FUERA"
End If
End Sub
End Class
Imports System.IO
Module Module2
Public cadena As String
Public Const maxfilas As Integer = 20
Public Const maxcol As Integer = 20
Public resultado As Integer = 0
Public Tabla(maxfilas, maxfilas) As String
Public X1(maxfilas) As Single
Public Y1(maxfilas) As Single
Public XA(maxfilas) As Single
Public YA(maxfilas) As Single
Public xmin As Single
Public xmax As Single
Public ymin As Single
Public ymax As Single
Public nreg As Integer = 4
Public ncampos As Integer = 5
Public nf As Integer = maxfilas, nc As Integer = maxcol
Public np As Integer
Public Ser As Integer = 1
Public espacio As Integer = 0
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -916-
Sub limites(ByRef A() As Single, ByRef xmin As Single, ByRef xmax As Single)
Dim fila As Integer
Dim col As Integer
REM primero ordenamos
Dim temp As Single
For fila = 0 To 2
For col = fila + 1 To 3
If (A(col) < A(fila)) Then
temp = A(fila)
A(fila) = A(col)
A(col) = temp
End If
Next col
Next fila
xmin = A(1)
xmax = A(2)
End Sub
GRAFICACION DE CURVAS
Se tiene los siguientes puntos hechos en Excel graficar Elaborar la grafica de los
puntos escaneados en visual Basic
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -919-
Imports System.Drawing
Imports System.IO
Module Module1
Public Const limitetx As Integer = 500
Public Const limitety As Integer = 500
Public Const limitetz As Integer = 500
Public Const limiteex As Integer = 100
Public Const limiteey As Integer = 100
Public Const limiteez As Integer = 100
Public varAngulo As Single = 1
Public varTras As Single = 1
Public varEscalado As Single = 1
pX = x2 - x1
py = y2 - y1
pz = z2 - z1
Qx = x3 - x1
Qy = y3 - y1
Qz = z3 - z1
NX = py * Qz - pz * Qy
Ny = pz * Qx - pX * Qz
Nz = pX * Qy - py * Qx
'PRODUCTO(CRUZ)
R = Math.Sqrt(NX * NX + Ny * Ny + Nz * Nz)
If R > 0 Then
Nx1 = NX / R
Else
Nx1 = 0
End If
If R > 0 Then
Ny1 = Ny / R
Else
Ny1 = 0
End If
If R > 0 Then
Nz1 = Nz / R
Else
Nz1 = 0
End If
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -921-
Pe = Nx1 * 0 + Ny1 * 0 + Nz1 * D
Normales(0) = Nx1
Normales(1) = Ny1
Normales(2) = Nz1
If Nz1 > mayor Then mayor = Nz1
Normales(3) = Pe
r1 = Math.Sqrt(Nx1 * Nx1 + Ny1 * Ny1 + Nz1 * Nz1)
Return r1
End Function
Function ContarLetra(Cadena As String, letra As Char)
Dim LARGO As Integer = Len(Cadena)
Dim cont, cant As Integer
For cont = 0 To LARGO - 1
If Cadena(cont) = letra Then
cant = cant + 1
End If
Next
Return cant + 1
End Function
Sub MAIN()
RecuperarMatriz(NombreArchivo, A, nfilas, ncol)
MostrarMatriz(A, nfilas, ncol)
Console.ReadLine()
End Sub
Sub RecuperarMatriz(ByVal nombrearchivo As String, ByRef A(,) As Single, ByRef nf
As Integer, ByRef nc As Integer)
Dim srLector As StreamReader
srLector = New StreamReader(nombrearchivo)
Dim fila As Integer, col As Integer
Dim cadena As String = ""
Dim subcadena As String
Dim pos As Integer = 0
Dim inicio As Integer = 1
cadena = srLector.ReadLine()
nc = ContarLetra(cadena, vbTab)
Do While Not (cadena = "")
cadena = cadena & vbTab
inicio = 1
For col = 0 To nc - 1
pos = InStr(inicio, cadena, Chr(9))
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, col) = Val(subcadena)
inicio = pos + 1
Next
fila = fila + 1
cadena = srLector.ReadLine()
Loop
nf = fila
Console.WriteLine("Archivo leido satisfactoriamente")
srLector.Close()
End Sub
Sub MostrarMatriz(A(,) As Single, nf As Integer, nc As Integer)
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -922-
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Console.Write("{0} {1}", A(fila, col), vbTab)
Next
Console.WriteLine()
Next
End Sub
Imports System.Drawing
Imports System.Windows.Forms
Public Class Form1
Sub MostrarMatrizFormulario(A(,) As Single, nf As Integer, nc As Integer)
Dim fila, col As Integer
DataGridView2.RowCount = nfilas
DataGridView2.ColumnCount = ncol
For col = 0 To ncol - 1
DataGridView2.Columns(col).Width = 30
DataGridView2.Columns(col).HeaderText = col
Next
For fila = 0 To nf - 1
For col = 0 To nc - 1
DataGridView2.Rows(fila).Cells(col).Value = A(fila, col)
Next
Next
End Sub
Sub Figura(X() As Single, Y() As Single, Z() As Single)
Dim Puntos(3) As Point
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -924-
Dim Rnormal As Single
Dim Normales(4) As Single
Dim verde As Integer
Puntos(0).X = (X(0) * D) / (D + Z(0))
Puntos(0).Y = (Y(0) * D) / (D + Z(0))
Puntos(1).X = (X(1) * D) / (D + Z(1))
Puntos(1).Y = (Y(1) * D) / (D + Z(1))
Puntos(2).X = (X(2) * D) / (D + Z(2))
Puntos(2).Y = (Y(2) * D) / (D + Z(2))
Puntos(3).X = (X(3) * D) / (D + Z(3))
Puntos(3).Y = (Y(3) * D) / (D + Z(3))
RNormal = ObtenerNormales(X, Y, Z, Normales)
If Normales(2) >= 0 Then
'verde = 255 * Normales(2)
verde = 255 * Normales(2)
btnProcesar_Click(sender, e)
txtRotacion.Text = ""
End Sub
Private Sub BtnIniciar_Click(sender As Object, e As EventArgs) Handles
BtnIniciar.Click
Dim col As Integer
DataGridView1.RowCount = 4
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -926-
DataGridView1.ColumnCount = 5
For col = 0 To 4
DataGridView1.Columns(col).Width = 30
Next
DataGridView1.Columns(0).HeaderText = "Parametro"
DataGridView1.Columns(1).HeaderText = "X"
DataGridView1.Columns(2).HeaderText = "Y"
DataGridView1.Columns(3).HeaderText = "Z"
DataGridView1.Columns(4).HeaderText = "Var"
DataGridView1.Rows(0).Cells(0).Value = "Angulo"
DataGridView1.Rows(0).Cells(1).Value = AnguloX
DataGridView1.Rows(0).Cells(2).Value = AnguloY
DataGridView1.Rows(0).Cells(3).Value = AnguloZ
DataGridView1.Rows(0).Cells(4).Value = VarAngulo
DataGridView1.Rows(1).Cells(0).Value = "Traslac"
DataGridView1.Rows(1).Cells(1).Value = tx
DataGridView1.Rows(1).Cells(2).Value = ty
DataGridView1.Rows(1).Cells(3).Value = tz
DataGridView1.Rows(1).Cells(4).Value = varTras
DataGridView1.Rows(2).Cells(0).Value = "Escalado"
DataGridView1.Rows(2).Cells(1).Value = ex
DataGridView1.Rows(2).Cells(2).Value = ey
DataGridView1.Rows(2).Cells(3).Value = ez
DataGridView1.Rows(2).Cells(4).Value = varEscalado
DataGridView1.Rows(3).Cells(0).Value = "D"
DataGridView1.Rows(3).Cells(1).Value = D
End Sub
Sub Proceso(A(,) As Single, Xcol As Integer, Yfila As Integer, _
anguloX As Single, anguloY As Single, anguloZ As Single, _
tx As Single, ty As Single, tz As Single, _
ex As Single, ey As Single, ez As Single)
http://www.paisdelosjuegos.pe/juegos/pacman
Option Explicit On
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -930-
Dim fila, col As Integer
DataGridView1.RowCount = nf
DataGridView1.ColumnCount = nc
For col = 0 To nc - 1
DataGridView1.Columns(col).Width = 24
DataGridView1.Columns(col).HeaderText = col
Next
For fila = 0 To nf - 1
DataGridView1.Rows(fila).HeaderCell.Value = fila.ToString
Next
RecuperarMatriz(NombreArchivo, Matriz, nf, nc)
Matriz(pmy, pmx) = 3
MostrarMatriz(Matriz, nf, nc)
txtPorcentaje.Text = contar(Matriz, nf, nc) * 100
DataGridView1.Focus()
End Sub
Private Sub BtnRecuperar_Click(sender As Object, e As EventArgs) Handles
BtnRecuperar.Click
RecuperarMatriz(NombreArchivo, Matriz, nf, nc)
End Sub
Private Sub BtnMostrar_Click(sender As Object, e As EventArgs) Handles
BtnMostrar.Click
MostrarMatriz(Matriz, nf, nc)
End Sub
Private Sub DataGridView1_CellEnter(sender As Object, e As
DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
col = DataGridView1.CurrentCellAddress.X
fila = DataGridView1.CurrentCellAddress.Y
'DataGridView1.CurrentCell.Style.BackColor = Color.FromArgb(255, 0, 0)
TextBox1.Text = "F " & fila & "C" & col
ValorActual = DataGridView1.CurrentCell.Value
txtAnterior.Text = ValorAnterior
txtActual.Text = ValorActual
TextBox2.Text = cont
Select Case ValorActual
Case camino ' entre a la celda de color blanco
If ValorAnterior = relleno Then ' la celda anterior era verde
cont = 0 ' comienza a llenar al vector
' encuentra la fila columna inicial
X(cont) = col
Y(cont) = fila
xini = col
yini = fila
ListBox1.Items.Clear()
ListBox1.Items.Add("Xini " & xini & " Yini " & yini)
ListBox1.Items.Add("Yfin " & xfin & " Yfin " & yfin)
DataGridView1.CurrentCell.Value = relleno ' ahora la celda es de color verde
Matriz(fila, col) = relleno
Else ' la celda anterior no era verde sigue incrementando contador
cont = cont + 1
X(cont) = col
Y(cont) = fila
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -931-
DataGridView1.CurrentCell.Value = relleno ' ahora la celda es de color verde
Matriz(fila, col) = relleno
End If
Case relleno ' entre a la celda de color verde
If ValorAnterior = relleno Then ' la celda anterior era verde
' no hace nada
Else ' la celda anterior era blanco ' termina la salida
xfin = col
yfin = fila
Y(cont) = fila
X(cont) = col
ListBox1.Items.Clear()
ListBox1.Items.Add("Xini " & xini & " Yini " & yini)
ListBox1.Items.Add("Yfin " & xfin & " Yfin " & yfin)
If cont > 2 Then
nelem = cont
cx = (xini + xfin) / 2
cy = (yini + yfin) / 2
' MostrarMatriz(Matriz, nf, nc)
Centroide(X, Y, nelem, centrox, centroy)
'DataGridView1.Rows(cy).Cells(cx).Value = 3
'DataGridView1.Rows(centroy).Cells(centrox).Value = 4
' CENTRO PROMEDIO
If Matriz(cy, cx) = camino Then
Rellenar(cx, cy)
End If
If Matriz(centroy, centrox) = camino Then
Rellenar(centrox, centroy)
End If
MostrarMatriz(Matriz, nf, nc)
txtPorcentaje.Text = contar(Matriz, nf, nc) * 100
End If
End If
End Select
ValorAnterior = ValorActual
End Sub
Private Sub btnVector_Click(sender As Object, e As EventArgs) Handles
btnVector.Click
nelem = cont
MostrarVector(X, Y, nelem)
End Sub
Private Sub btnRellenar_Click(sender As Object, e As EventArgs) Handles
btnRellenar.Click
Rellenar(cx, cy)
End Sub
Private Sub BtnIniciar_Click(sender As Object, e As EventArgs) Handles
BtnIniciar.Click
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
DataGridView1.Rows(fila).Cells(col).Value = 0
Matriz(fila, col) = 0
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -932-
Next
Next
End Sub
Sub jugar()
Dim pmx1 As Single = pmx
Dim pmy1 As Single = pmy
Dim dist, distmenor
dist = distancia(col, fila, pmx, pmy)
distmenor = dist
Matriz(pmy, pmx) = camino
pmx1 = pmx
pmy1 = pmy
dist = distancia(col, fila, pmx + 1, pmy)
If dist < distmenor And Matriz(pmy, pmx + 1) = camino Then
distmenor = dist
pmx1 = pmx + 1
End If
dist = distancia(col, fila, pmx - 1, pmy)
If dist < distmenor And Matriz(pmy, pmx - 1) = camino Then
distmenor = dist
pmx1 = pmx - 1
End If
dist = distancia(col, fila, pmx, pmy + 1)
If dist < distmenor And Matriz(pmy + 1, pmx) = camino Then
distmenor = dist
pmy1 = pmy + 1
End If
dist = distancia(col, fila, pmx, pmy - 1)
If dist < distmenor And Matriz(pmy - 1, pmx) = camino Then
distmenor = dist
pmy1 = pmy - 1
End If
If pmx1 = pmx And pmy1 = pmy Then
While (1)
pmx = Int(Rnd() * nc)
pmy = Int(Rnd() * nf)
If (Matriz(pmy, pmx) = camino) Then Exit While
End While
Else
pmy = pmy1
pmx = pmx1
End If
vecinos = Contavecinos(Matriz, nf, nc, col, fila)
Matriz(pmy, pmx) = 3
MostrarMatriz(Matriz, nf, nc)
If distmenor < 2 Then
If vecinos < 4 Then
txtvecinos.Text = " muerto"
Timer1.Enabled = False
Else
txtvecinos.Text = " VIVO"
End If
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -933-
Exit Sub
End If
txtdistancia.Text = distmenor
txtvecinos.Text = vecinos
DataGridView1.Focus()
End Sub
Private Sub btnJugar_Click(sender As Object, e As EventArgs) Handles
btnJugar.Click
Timer1.Interval = 50
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
jugar()
End Sub
End Class
Imports System.IO
Module module2
'/*** declaraciones
Public NombreArchivo As String = "E:\DATOS\MATRIZ20X20.txt"
Public Const maxfilas As Integer = 20, maxcol As Integer = 20
Public Matriz(maxfilas, maxcol) As Integer
Public maxelem As Integer = 1000
Public X(maxelem) As Integer ' vector de coordenadas x
Public Y(maxelem) As Integer ' vector de coordenadas y
Public cont As Integer = 0
Public nf As Integer = 20
Public nc As Integer = 20
Public px As Integer = 2 ' objeto identifico
Public py As Integer = 2
Public ser As Integer = 1
Public relleno As Integer = 2
Public camino As Integer = 0
Public nelem As Integer
Public cx As Integer = 0 ' centro dela figura
Public cy As Integer = 0
Public ValorAnterior As Integer = 2 ' verde
Public ValorActual As Integer = 0
Public xini As Integer = 0
Public yini As Integer = 0
Public xfin As Integer = 0
Public yfin As Integer = 0
Public centrox As Integer
Public centroy As Integer
Public cpromx As Integer
Public cpromY As Integer
Public pmx As Integer = 10
Public pmy As Integer = 10
Public pacman As Integer = 3
Public fila As Integer ' fila del pacman
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -934-
Public col As Integer
Public vecinos As Integer = 0
Module Module1
Public Structure Puntos
Public nro As Integer
Public X As Single
Public Y As Single
Public Z As Single
Public Rela As Integer
End Structure
Imports System.IO
Public Class Form1
Private Sub btnIniciar_Click(sender As Object, e As EventArgs) Handles
btnIniciar.Click
DataGridView1.RowCount = 8
DataGridView1.ColumnCount = 4
DataGridView1.Columns(0).HeaderText = "PARAMETROS"
DataGridView1.Columns(1).HeaderText = "X (min)"
DataGridView1.Columns(2).HeaderText = "Y (Max)"
DataGridView1.Columns(3).HeaderText = "Z"
DataGridView1.Columns(0).Width = 100
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -939-
DataGridView1.Columns(1).Width = 40
DataGridView1.Columns(2).Width = 40
DataGridView1.Columns(3).Width = 40
Cx = DataGridView1.Rows(3).Cells(1).Value
Cy = DataGridView1.Rows(3).Cells(2).Value
Cz = DataGridView1.Rows(3).Cells(3).Value
Ex = DataGridView1.Rows(4).Cells(1).Value
Ey = DataGridView1.Rows(4).Cells(2).Value
Ez = DataGridView1.Rows(4).Cells(3).Value
Gradosx = DataGridView1.Rows(5).Cells(1).Value
Gradosy = DataGridView1.Rows(5).Cells(2).Value
Gradosz = DataGridView1.Rows(5).Cells(3).Value
GPencil = DataGridView1.Rows(6).Cells(1).Value
Indice = DataGridView1.Rows(6).Cells(2).Value
modo = DataGridView1.Rows(6).Cells(3).Value
dx = (lsx - lix) / nc
dy = (lsy - liy) / nf
DataGridView1.Rows(7).Cells(1).Value = dx
DataGridView1.Rows(7).Cells(2).Value = dy
dx = DataGridView1.Rows(7).Cells(1).Value
dy = DataGridView1.Rows(7).Cells(2).Value
vel = DataGridView1.Rows(7).Cells(3).Value
DataGridView2.RowCount = nf + 1
DataGridView2.ColumnCount = 2
DataGridView2.Columns(0).Width = 40
DataGridView2.Columns(1).Width = 50
DataGridView2.Columns(0).HeaderText = "X"
DataGridView2.Columns(1).HeaderText = "Y"
For fila = 0 To DataGridView2.RowCount - 1
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -941-
DataGridView2.Rows(fila).HeaderCell.Value = fila.ToString
Next
GenerarGrabar(sender, e)
escalar(Ex, Ey, Ez)
rotar(Gradosx, Gradosy, Gradosz)
grafico3d()
End Sub
Private Sub btnGraficar_Click(sender As Object, e As EventArgs) Handles
btnGraficar.Click
Dim x1, y1, x2, y2 As Single
Pen.Width = GPencil
With DataGridView2
For col = 0 To nc - 2
x1 = CSng(.Rows(col).Cells(0).Value)
y1 = CSng(.Rows(col).Cells(1).Value)
x2 = CSng(.Rows(col + 1).Cells(0).Value)
y2 = CSng(.Rows(col + 1).Cells(1).Value)
Grafico.DrawLine(Pen, Cx + x1 * Ex, Cy + y1 * Ey, Cx + x2 * Ex, Cy + y2 * Ey)
Next
End With
End Sub
Private Sub BtnBorrar_Click(sender As Object, e As EventArgs) Handles
BtnBorrar.Click
Grafico.Clear(Color.White)
End Sub
' rotacion z
Az = gradosz * Math.PI / 180
For fila = 0 To nf - 1
For col = 0 To nc - 1
x1 = MP1(fila, col).X
y1 = MP1(fila, col).Y
z1 = MP1(fila, col).Z
x2 = x1 * Math.Cos(Az) - y1 * Math.Sin(Az)
y2 = x1 * Math.Sin(Az) + y1 * Math.Cos(Az)
z2 = z1
MP1(fila, col).X = x2
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -945-
MP1(fila, col).Y = y2
MP1(fila, col).Z = z2
Next
Next
End Sub
Private Sub btnVerDatos_Click(sender As Object, e As EventArgs) Handles
btnVerosDatos.Click
Form2.DataGridView1.ColumnCount = nc + 1
Form2.DataGridView1.RowCount = nf + 1
For col = 0 To nc
Form2.DataGridView1.Columns(col).Width = 70
Next
For fila = 0 To nf - 1
For col = 0 To nc - 1
Form2.DataGridView1.Rows(fila).Cells(col).Value = MP1(fila, col).Z
Next
Next
Form2.Show()
End Sub
Private Sub TextBox1_KeyDown_1(sender As Object, e As KeyEventArgs) Handles
TextBox1.KeyDown
Select Case e.KeyCode
Case Keys.Left
Gradosx = Gradosx - 1
Case Keys.Right
Gradosx = Gradosx + 1
Case Keys.Up
Gradosy = Gradosy - 1
Case Keys.Down
Gradosy = Gradosy + 1
Case 90 'Z
Gradosz = Gradosz + 1
Case 87 'W
Gradosz = Gradosz - 1
End Select
DataGridView1.Rows(5).Cells(1).Value = Gradosx
DataGridView1.Rows(5).Cells(2).Value = Gradosy
DataGridView1.Rows(5).Cells(3).Value = Gradosz
BtnBorrar_Click(sender, e)
BtnIniciarTodo_Click(sender, e)
TextBox1.Text = ""
End Sub
End Class
Imports System.IO
Module Module1
Public A(25000, 2) As String
Public nf As Integer
Sub LeerArchivo(A(,) As String, ByRef nf As Integer)
Dim srLector As StreamReader = New StreamReader("e:\DATOS\DIC1.txt")
Dim Linea As String
Dim cont As Integer = 0
Dim pos As Integer
Linea = srLector.ReadLine()
Do While Not (Linea Is Nothing)
pos = InStr(1, Linea, Chr(9))
A(cont, 0) = Mid(Linea, 1, pos - 1)
A(cont, 1) = Mid(Linea, pos + 1, Len(Linea))
cont = cont + 1
Linea = srLector.ReadLine()
Loop
nf = cont
End Sub
End Module
Imports System.IO
Module Module1
Public A(25000, 2) As String
Public nf As Integer
Sub LeerArchivo(A(,) As String, ByRef nf As Integer)
Dim srLector As StreamReader = New StreamReader("e:\DATOS\DIC1.txt")
Dim Linea As String
Dim cont As Integer = 0
Dim pos As Integer
Linea = srLector.ReadLine()
Do While Not (Linea Is Nothing)
pos = InStr(1, Linea, Chr(9))
A(cont, 0) = Mid(Linea, 1, pos - 1)
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -953-
A(cont, 1) = Mid(Linea, pos + 1, Len(Linea))
cont = cont + 1
Linea = srLector.ReadLine()
Loop
nf = cont
End Sub
Sub BuscarInglesCastellano(A(,) As String, Ingles As String, nf As Integer)
Dim i As Integer
Dim largo As Integer
Dim cont1 As Integer = 0
For i = 0 To nf - 1
largo = InStr(A(i, 0), Ingles)
If largo > 0 Then
Console.WriteLine(" {0}===> {1} ====>{2}", cont1, A(i, 0), A(i, 1))
cont1 = cont1 + 1
End If
Next
Console.WriteLine("Palabras encontradas{0}", cont1)
End Sub
Sub BuscarCastellanoIngles(A(,) As String, Castellano As String, nf As Integer)
Dim i As Integer
Dim largo As Integer
Dim cont1 As Integer = 0
For i = 0 To nf - 1
largo = InStr(A(i, 1), Castellano)
If largo > 0 Then
Console.WriteLine(" {0}===> {1} ====>{2}", cont1, A(i, 1), A(i, 0))
cont1 = cont1 + 1
End If
Next
Console.WriteLine("Palabras encontradas{0}", cont1)
End Sub
Sub Main()
LeerArchivo(A, nf)
Dim opcion As Integer
Dim Ingles, Castellano As String
Do
Console.WriteLine("1. Ingles castellano 2. Castellano Ingles 3.Salir ")
Console.Write("ingrese opcion ")
opcion = Console.ReadLine()
Select Case opcion
Case 1
Console.WriteLine("Ingrese palabra en Inglés ")
Ingles = Console.ReadLine
BuscarInglesCastellano(A, Ingles, nf)
Case 2
Console.WriteLine("Ingrese palabra en Castellano ")
Castellano = Console.ReadLine
BuscarCastellanoIngles(A, Castellano, nf)
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -954-
End Select
Loop While opcion <> 3
End Sub
End Module
Imports System.IO
Public Class Form1
Const Maximo As Integer = 25000
Public A(Maximo) As String
Public B(Maximo) As String
Dim fuente As Font
Dim Color As Color
Dim camino As Path
Dim nterminos As Integer = 2
Dim Texto As String = ""
Private Sub InglesEspañol(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnInglesEspañol.Click
Dim fila1 As Integer
Dim nombre1 As String
Dim nombre2 As String
Texto = txtFuente.Text
For fila1 = 0 To nterminos - 1
nombre1 = A(fila1) ' INGLES
nombre2 = B(fila1) ' ESPAÑOL
Texto = Replace(Texto, nombre1, nombre2)
Next
txtDestino.Text = Texto
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -955-
End Sub
End Sub
Imports System.Drawing
Public Class Form1
Dim Pen As Pen
Dim Grafico As Graphics
Dim brocha As SolidBrush
Dim ancho As Integer = 255
Dim alto As Integer = 255
Dim color1 As Color
Private Sub btnCromatico_Click(sender As Object, e As EventArgs) Handles
btnCromatico.Click
Dim fila, col As Integer
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -958-
For fila = 0 To alto - 1
For col = 0 To ancho - 1
brocha.Color = Color.FromArgb(fila, col, 0)
Grafico.FillRectangle(brocha, fila, col, 1, 1)
Next
Next
End Sub
Tarea.- Elaborar Gama de colores o circulo cromático(use el triangulo para cad color)(
Estudiar el cuadro cromaico
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -959-
10.25 EVALUACION DE EXPRESIONES MUY LARGO
Module Module1
Public EvalRes As Boolean ' Resultado de la evaluacion
Public CadA, CadB, CadC, CadD, CadE, CadX As String
Public CadenaEcuacion As String
Public Cadena As String = "XXXX"
Public VSignos As String = "^*/"
Public CadSigno As String = ""
Public CadenaExpresion As String
Public nelem As Integer = 0
Public CadNumeros As String = "0123456789.+-*/^() "
Public suma As Single
Public ck As Single = 0.279
' **************
Public x1 As Single = 1
Public Li As Single = -5
Public Ls As Single = 5
Public Dx As Single = 1
Public Ndiv As Integer = 10
Public cx As Integer = 200
Public cy As Integer = 200
Public ex As Integer = 10
Public ey As Integer = 10
Public A As Single = 0
Public B As Single = 0
Public C As Single = 1
Public D As Single = 0
Public vE As Single = 0
Public Umbral As Single = 2
Function PotMultiDivi(cadena As String, tipo As Integer) As String
Dim Signo1, signo2, signo3, cadsigno As String
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -960-
Dim cad1, cad2, cad3 As String
Dim Cadena1, Cadena2, Cadena3 As String
Dim CadA, CadB As String
Dim pos1, pos2, pos3, posini As Integer
Dim R As Single
Dim fila As Integer
cadena = " " + cadena + " "
cadsigno = ""
Select Case tipo
Case 1 ' si son potencias
For fila = 0 To Len(cadena) - 1
If cadena(fila) = "^" Then
cadsigno = cadena(fila)
pos2 = fila
Exit For
End If
Next
Case 2
'multiplicaciones y divisiones tienen igual prioridad
For fila = 0 To Len(cadena) - 1
If cadena(fila) = "*" Or cadena(fila) = "/" Then
cadsigno = cadena(fila)
pos2 = fila
Exit For
End If
Next
End Select
' primero buscamos si son las potencias
CadA = Extrae(cadena, 0, pos2 - 1)
CadB = Extrae(cadena, pos2 + 1, Len(cadena) - 1)
' la cadena anterior
For fila = pos2 - 1 To 0 Step -1
If cadena(fila) = "+" Or cadena(fila) = "-" Or cadena(fila) = "*" Or cadena(fila) =
"/" Or cadena(fila) = "^" Then
pos1 = fila
Exit For
Else
cad1 = cadena(fila) + cad1
End If
Next
' busca hacia adelante
pos3 = pos2
' si el primer signo + o - entonces si cuenta 2o
If CadB(0) = "+" Or CadB(0) = "-" Then
posini = pos2 + 2
cad3 = CadB(0)
Else
cad3 = ""
posini = pos2 + 1
End If
pos3 = Len(cadena) - 1
For fila = posini To Len(cadena) - 1
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -961-
' cadsigno = cadena(fila)
If cadena(fila) = "+" Or cadena(fila) = "-" Or _
cadena(fila) = "*" Or cadena(fila) = "/" Or cadena(fila) = "^" Or fila >
Len(cadena) - 1 Then
pos3 = fila
Exit For
Else
cad3 = cad3 + cadena(fila)
End If
Next
Select Case cadsigno
Case "^" : R = Val(cad1) ^ Val(cad3) 'tiene mayor prioridad
Case "*" : R = Val(cad1) * Val(cad3)
Case "/" : R = Val(cad1) / Val(cad3)
End Select
'reemplazamos el resultado de la multiplicacion
Cadena1 = Extrae(cadena, 0, pos1)
Cadena3 = Extrae(cadena, pos3, Len(cadena) - 1)
' juntamos la cadena
Cadena2 = Str(R)
' Console.WriteLine(" la cadena 1 es {0} ", Cadena1)
' Console.WriteLine(" la cadena 2 es {0} ", Cadena2)
' Console.WriteLine(" la cadena 3 es {0} ", Cadena3)
Signo1 = Cadena1(Len(Cadena1) - 1)
signo2 = Cadena2(0)
Select Case Signo1
Case "+"
Select Case signo2
Case "+" : signo3 = "+"
Case " " : signo3 = "+"
Case "-" : signo3 = "-"
End Select
Case "-"
Select Case signo2
Case "+" : signo3 = "-"
Case " " : signo3 = "-"
Case "-" : signo3 = "+"
End Select
Case "*"
signo3 = Signo1
Case "/"
signo3 = Signo1
End Select
Cadena1 = Extrae(Cadena1, 0, Len(Cadena1) - 2)
Cadena2 = Extrae(Cadena2, 1, Len(Cadena2) - 1)
cadena = Cadena1 + signo3 + Cadena2 + Cadena3
Return cadena
End Function
DataGridView1.Rows(12).Cells(0).Value = "EX"
DataGridView1.Rows(12).Cells(1).Value = ex
DataGridView1.Rows(13).Cells(0).Value = "EY"
DataGridView1.Rows(13).Cells(1).Value = ey
DataGridView1.Rows(14).Cells(0).Value = "CK"
DataGridView1.Rows(14).Cells(1).Value = ck
End Sub
Sub ObtenerCadenas()
CadenaEcuacion = txtEcuacion.Text
CadA = DataGridView1.Rows(6).Cells(1).Value
CadB = DataGridView1.Rows(7).Cells(1).Value
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -968-
CadC = DataGridView1.Rows(8).Cells(1).Value
CadD = DataGridView1.Rows(9).Cells(1).Value
CadE = DataGridView1.Rows(10).Cells(1).Value
CadX = DataGridView1.Rows(11).Cells(1).Value
End Sub
Function Sumasrestas(cadena As String) As Single
Dim suma As Single
Dim signo1, signo2, subcadena As String
Dim psigno1, psigno2, possigno As Integer
Dim cont1, cont2, largo As Integer
largo = Len(cadena)
' buscar el primer signo si es mas o menos
psigno1 = Encontrar(cadena, "+", 0)
psigno2 = Encontrar(cadena, "-", 0)
If psigno1 < psigno2 Then
possigno = psigno1
Else
possigno = psigno2
End If
cont1 = possigno + 1
cont2 = possigno + 1
signo1 = cadena(possigno)
' sumas y restas
suma = 0
While (cont2 < largo)
signo2 = cadena(cont2)
If signo2 = "-" Or signo2 = "+" Or cont2 >= largo - 1 Then
subcadena = Extrae(cadena, cont1, cont2 - 1)
' Console.WriteLine("subcadena {0} ", subcadena)
Select Case signo1
Case "+" : suma = suma + Val(subcadena)
Case "-" : suma = suma - Val(subcadena)
End Select
signo1 = signo2
cont2 = cont2 + 1
cont1 = cont2
' Console.WriteLine("la suma es {0}", suma)
Else
cont2 = cont2 + 1
End If
End While
Return suma
End Function
Function Encontrado(SIGNO As String) As Boolean
Dim fila As Integer
Dim valor As Boolean = False
For fila = 0 To Len(CadNumeros) - 1
If CadNumeros(fila) = SIGNO Then
valor = True
Exit For
End If
Next
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -969-
Return valor
End Function
y = EvaluarExpresion(CadTemporal)
x2 = cx + x * ex
y2 = cy + y * (ey * -1)
Grafico.DrawLine(pen, x1, y1, x2, y2)
x1 = x2
y1 = y2
'Grafico.FillRectangle(Brushes.Blue, x2, y2, ex, ey)
ListBox1.Items.Add(x & " " & y)
Next
End Sub
Private Sub btnVarXA_Click(sender As Object, e As EventArgs) Handles
btnVarXC.Click
Dim CadTemporal1, CadTemporal2 As String
Dim x1, y1, x2, y2, x, y As Single
Dim vc As Single
CadenaEcuacion = txtEcuacion.Text
ObtenerValores()
ObtenerCadenas()
CadC = "C"
CadX = "X"
CadenaExpresion = ObtenerEcuacion(CadenaEcuacion, CadA, CadB, CadC,
CadD, CadE, CadX)
CadenaExpresion = " " + CadenaExpresion + " "
TxtExpresion.Text = CadenaExpresion
coordenadas(cx, cy)
Dx = (Ls - Li) / Ndiv
DataGridView1.Rows(5).Cells(1).Value = Dx
For vc = Li To Ls Step Dx
CadTemporal1 = Reemplazar(CadenaExpresion, "C", vc)
x = Li
CadTemporal2 = Reemplazar(CadTemporal1, "X", x)
CadTemporal2 = " " + CadTemporal2 + " "
y = EvaluarExpresion(CadTemporal2)
x1 = cx + x * ex
y1 = cy + y * (ey * -1)
For x = Li + Dx To Ls Step Dx
CadTemporal2 = Reemplazar(CadTemporal1, "X", x)
y = EvaluarExpresion(CadTemporal2)
x2 = cx + x * ex
y2 = cy + y * (ey * -1)
Grafico.DrawLine(pen, x1, y1, x2, y2)
x1 = x2
y1 = y2
Next
Next
End Sub
Private Sub BtnXd_Click(sender As Object, e As EventArgs) Handles BtnXd.Click
Dim CadTemporal1, CadTemporal2 As String
Dim x1, y1, x2, y2, x, y As Single
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -971-
Dim vd As Single
CadenaEcuacion = txtEcuacion.Text
ObtenerValores()
ObtenerCadenas()
CadD = "D"
CadX = "X"
CadenaExpresion = ObtenerEcuacion(CadenaEcuacion, CadA, CadB, CadC,
CadD, CadE, CadX)
CadenaExpresion = " " + CadenaExpresion + " "
TxtExpresion.Text = CadenaExpresion
coordenadas(cx, cy)
Dx = (Ls - Li) / Ndiv
DataGridView1.Rows(5).Cells(1).Value = Dx
For vd = Li To Ls Step Dx
CadTemporal1 = Reemplazar(CadenaExpresion, "D", vd)
x = Li
CadTemporal2 = Reemplazar(CadTemporal1, "X", x)
CadTemporal2 = " " + CadTemporal2 + " "
y = EvaluarExpresion(CadTemporal2)
x1 = cx + x * ex
y1 = cy + y * (ey * -1)
For x = Li + Dx To Ls Step Dx
CadTemporal2 = Reemplazar(CadTemporal1, "X", x)
y = EvaluarExpresion(CadTemporal2)
x2 = cx + x * ex
y2 = cy + y * (ey * -1)
Grafico.DrawLine(pen, x1, y1, x2, y2)
x1 = x2
y1 = y2
Next
Next
End Sub
Private Sub BtnVarXE_Click(sender As Object, e As EventArgs) Handles
BtnVarXE.Click
Dim CadTemporal1, CadTemporal2 As String
Dim x1, y1, x2, y2, x, y As Single
Dim ve As Single
CadenaEcuacion = txtEcuacion.Text
ObtenerValores()
ObtenerCadenas()
CadE = "E"
CadX = "X"
CadenaExpresion = ObtenerEcuacion(CadenaEcuacion, CadA, CadB, CadC,
CadD, CadE, CadX)
CadenaExpresion = " " + CadenaExpresion + " "
TxtExpresion.Text = CadenaExpresion
coordenadas(cx, cy)
Dx = (Ls - Li) / Ndiv
DataGridView1.Rows(5).Cells(1).Value = Dx
For ve = Li To Ls Step Dx
CadTemporal1 = Reemplazar(CadenaExpresion, "E", ve)
x = Li
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -972-
CadTemporal2 = Reemplazar(CadTemporal1, "X", x)
CadTemporal2 = " " + CadTemporal2 + " "
y = EvaluarExpresion(CadTemporal2)
x1 = cx + x * ex
y1 = cy + y * (ey * -1)
For x = Li + Dx To Ls Step Dx
CadTemporal2 = Reemplazar(CadTemporal1, "X", x)
y = EvaluarExpresion(CadTemporal2)
x2 = cx + x * ex
y2 = cy + y * (ey * -1)
Grafico.DrawLine(pen, x1, y1, x2, y2)
x1 = x2
y1 = y2
Next
Next
End Sub
Private Sub BtnBorra_Click(sender As Object, e As EventArgs) Handles
BtnBorra.Click
Grafico.Clear(Color.Black)
End Sub
Private Sub btnCX_Click(sender As Object, e As EventArgs) Handles btnCX.Click
Dim CadTemporal1, CadTemporal2 As String
Dim x1, y1, x2, y2, x, y As Single
Dim vc As Single
CadenaEcuacion = txtEcuacion.Text
ObtenerValores()
ObtenerCadenas()
CadC = "C"
CadX = "X"
CadenaExpresion = ObtenerEcuacion(CadenaEcuacion, CadA, CadB, CadC,
CadD, CadE, CadX)
CadenaExpresion = " " + CadenaExpresion + " "
TxtExpresion.Text = CadenaExpresion
coordenadas(cx, cy)
Dx = (Ls - Li) / Ndiv
DataGridView1.Rows(5).Cells(1).Value = Dx
For x = Li + Dx To Ls Step Dx
CadTemporal1 = Reemplazar(CadenaExpresion, "X", x)
'BtnBorra_Click(sender, e)
System.Threading.Thread.Sleep(50) ' 1 segundo
Application.DoEvents()
Grafico.Clear(Color.Black)
vc = Li
CadTemporal2 = Reemplazar(CadTemporal1, "C", vc)
y = EvaluarExpresion(CadTemporal2)
x1 = cx + vc * ex
y2 = cy + y * (ey * -1)
For vc = Li + Dx To Ls Step Dx
CadTemporal2 = Reemplazar(CadTemporal1, "C", vc)
y = EvaluarExpresion(CadTemporal2)
x2 = cx + vc * ex
y2 = cy + y * (ey * -1)
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -973-
Grafico.DrawLine(pen, x1, y1, x2, y2)
x1 = x2
y1 = y2
Next
Next
End Sub
Private Sub BtnFractal_Click(sender As Object, e As EventArgs) Handles
BtnFractal.Click
Dim brocha As SolidBrush
brocha = New SolidBrush(Color.FromArgb(255, 0, 0))
Dim cadena1 As String
Dim Resultado As Single
Dim cont As Integer = 0
CadenaEcuacion = txtEcuacion.Text
ObtenerValores()
ObtenerCadenas()
CadenaExpresion = ObtenerEcuacion(CadenaEcuacion, CadA, CadB, CadC,
CadD, CadE, CadX)
TxtExpresion.Text = CadenaExpresion
ListBox1.Items.Clear()
Dx = (Ls - Li) / Ndiv
For fila = Li To Ls Step Dx
cadena1 = ""
Resultado = Fractal(fila, cadena1)
' Console.WriteLine("cont {0} X {1} Y {2} {3} ", cont, fila, Resultado, cadena)
ListBox1.Items.Add(" cont " & cont & " fila " & fila & "res " & Resultado & " cad "
& cadena1)
cont = cont + 1
Grafico.FillRectangle(brocha, cx + fila * ex, cy + Resultado * ey * (-1), ex, ey)
Next
' Console.ReadLine()
End Sub
Los trabajos tienen que ser en modo visual . se deben presentar en grupos de 3
1. Aplicación de fractales y recursividad ejemplo modelización de terrenos
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -974-
2. Aplicación de autómatas celulares y computación universal. Juego de la vida en 2d y
3D
3. Aplicación del programa del buscador en optimización en modo grafico
4. Manejo del puerto USB
5. Programación de ADN manejo de secuencias cadenas
6. Programación genérica plantillas ( Templates)
7. Base de datos biológica
8. Aplicación 3d en opengl y visual estudio 2010, Simulación 3D
9. Aplicaciones Web Lenguaje HTML, Java, etc. y su importancia
10. Temas de inteligencia artificial como programación evolutiva , redes neuronales,etc
11. Sistemas de información en Office Excel
12. My sql
13. Automatización industrial plc, sensores,
14. Aplicaciones de sistemas de información para optimización
15. Simulación 3d, ejemplo simio.etc
16. Programación en Windows. Uso de otros controles como por ejemplo el Microsoft char
17. Programación genérica plantillas ( Templates)
18. Seguridad de base de datos en sqlserver
19. Otros temas relacionados al curso de sistemas de información
20. usando recursividad encuentre la posicion de cada objeto y cuantos elementos tiene
cada uno
Module Module2
Public Signo As Integer
Function Evaluar(ByVal Txt As String) As String
Dim i As Integer, oNB As Integer, fNB As Integer
Dim P1 As Integer, P2 As Integer
Dim Buff As String
' Dim T As String
'Para los calculos es necesario un punto en lugar de la coma
Txt = Replace(Txt, ",", ".")
'Ver si hay (
For i = 1 To Len(Txt)
If Mid(Txt, i, 1) = "(" Then oNB = oNB + 1
Next i
'Si hay ( (abiertos), ver si concuerdan) (cerrados)
If oNB > 0 Then
For i = 1 To Len(Txt)
If Mid(Txt, i, 1) = ")" Then fNB = fNB + 1
Next i
Else
'No hay parentesis, Evalua directamente el calculo
Evaluar = EvaluaExpresion(Txt)
Exit Function
End If
If oNB <> fNB Then
'Los parentesis no concuerdan, mostrar mensaje de error de parentesis
Return "ERROR"
Exit Function
End If
Module Module1
Sub TestCalcul()
Dim A As String
Dim Ret As String
A = "(((3*(12.223+ 15)) - 7)*21)/7"
Ret = Evaluar(A)
'Debug.Print Ret
'= 224.007
A = "((123.32/2.67)*6)+2127.34"
Ret = Evaluar(A)
'=2404.46359550562
'Debug.Print Ret
End Sub
Sub Main()
TestCalcul()
Console.ReadLine()
End Sub
End Module
Imports System.IO
Module Module2
Public Const maxfilas As Integer = 31
Public Const maxcol As Integer = 6
Public A(maxfilas, maxcol) As String
Public Objetos(maxfilas, maxcol) As String
Public Nfilas As Integer = 30
Public Ncol As Integer = 7
Public NfObjetos As Integer = 8
Public NcObjetos As Integer = 4
Module Module1
Dim cadena As String = "ABCEFG"
Sub main()
Dim fila, col, posletra As Integer
RecuperarMatriz(NombreArchivoObjetos, Objetos, NfObjetos, NcObjetos)
MostrarMatriz(Objetos, NfObjetos, NcObjetos)
RecuperarMatriz(NombreArchivo, A, Nfilas, Ncol) ' recupera la matriz A
' MostrarMatriz(A, Nfilas, Ncol)
' For fila = 0 To NfObjetos - 1
Dim sumaX, sumaY As Single
Dim npuntos As Integer
For fila = 0 To 0
sumaX = 0
sumaY = 0
npuntos = Len(cadena)
Console.WriteLine("datos de la fila {0} ={1}", fila, Objetos(fila, 2))
cadena = Objetos(fila, 2)
For col = 0 To npuntos - 1
' Console.WriteLine("{0}", cadena(col))
posletra = BuscarCadena(A, Nfilas, cadena(col))
Console.WriteLine("posletra {0}", posletra)
Console.WriteLine("datos de la fila {0}", posletra)
If posletra >= 0 Then
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -988-
sumaX = sumaX + A(posletra, 1)
sumaY = sumaY + A(posletra, 2)
End If
Next
Console.WriteLine("suma x {0} ", sumaX / npuntos)
Console.WriteLine("suma Y {0} ", sumaY / npuntos)
Next
Console.ReadLine()
End Sub
End Module
Imports System.Drawing
Public Class Form1
Dim grafico As Graphics
Dim lapiz1 As Pen
Dim lapiz2 As Pen
Dim lapiz As Pen
Dim ex As Single = 40
Dim ey As Single = 40
Dim brocha1 As SolidBrush
Dim brocha2 As SolidBrush
Dim brocha3 As SolidBrush
End Sub
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0
0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -996-
Imports System.Drawing
Public Class form1
End Select
grafico.DrawRectangle(pluma, cx + col * ex, cy + fila * ey, ex, ey)
Next
Next
End Sub
'******************modulo 1
Module Module1
Sub Main()
Console.WriteLine("juego de la vida de wonway")
Console.WriteLine("Diseño escenarioen Excel y grabe archivo con bloque de
notas ")
Console.WriteLine("juego de la vida de Connway")
RecuperarMatriz(NombreArchivo, Modelo, nf, nc)
CopiarMatriz(Modelo, A, nc, nf)
VerPantalla(10, 4, A, nf, nc)
Console.ReadLine()
While (1)
'For i = 0 To ng
JuegoVida(A, B, nf, nc)
VerPantalla(10, 4, A, nf, nc)
'System.Threading.Thread.Sleep(10) ' 1 segundo
'Next
End While
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -1000-
Console.ReadLine()
End Sub
End Module
'**************** modulo 2
Imports System.IO
Module Module2
Public NombreArchivo As String = "E:\datos\modelo40x30.txt"
Public Const maxfilas As Integer = 30
Public Const maxcol As Integer = 40
Public srLector As StreamReader
Public forma As Integer = 1
Public A(maxfilas, maxcol) As Integer
Public B(maxfilas, maxcol) As Integer
Public Modelo(maxfilas, maxcol) As Integer
Public nf As Integer = 40
Public nc As Integer = 40
Public ng As Integer = 200
Public pluma As Pen
Public grafico As Graphics
Public brochamuerte As SolidBrush
Public brochavida As SolidBrush
Public ex As Single = 14
Public ey As Single = 14
Public cx As Integer = 10
Public cy As Integer = 10
Public cont As Integer = 0
Public velocidad As Integer = 10
Esta sección analiza un programa que crea un brazo robot articulado con dos o más
segmentos. El brazo debe estar conectado con puntos de giro en el hombro, codo u otras
articulaciones. La Figura muestra un único conjunto de tal brazo.
Figura.
Puede utilizar un cubo escalado como un segmento del brazo robot, pero primero debe
llamar a las transformaciones de modelado adecuado para orientar a cada segmento.
Dado que el origen del sistema de coordenadas local está inicialmente en el centro del
cubo, necesita mover el sistema de coordenadas local a un borde del cubo. De lo
contrario, el cubo rota sobre su centro en lugar de hacerlo en el punto de giro.
Imports System.Drawing.Drawing2D
Public Class Form1
Dim Grafico As Graphics
Dim pen1 As Pen
Dim pen2 As Pen
Dim brocha1 As SolidBrush
Dim brocha2 As SolidBrush
DataGridView1.Columns(1).HeaderText = "RotZ"
DataGridView1.Columns(2).HeaderText = "Tx"
DataGridView1.Columns(3).HeaderText = "Ty"
DataGridView1.Columns(4).HeaderText = "Ex"
DataGridView1.Columns(5).HeaderText = "Ey"
DataGridView1.Columns(6).HeaderText = "CentroX"
DataGridView1.Columns(7).HeaderText = "CentroY"
DataGridView1.Columns(8).HeaderText = "Ancho"
DataGridView1.Columns(9).HeaderText = "Alto"
DataGridView1.Columns(10).HeaderText = "Transparencia"
DataGridView1.Columns(11).HeaderText = "Rojo"
DataGridView1.Columns(12).HeaderText = "Verde"
DataGridView1.Columns(13).HeaderText = "Azul"
DataGridView1.Columns(14).HeaderText = "Paso"
For i = 1 To nc - 1
DataGridView1.Columns(i).Width = 50
Next
For i = 0 To nfilas - 1
DataGridView1.Rows(i).HeaderCell.Value = i.ToString
Next
End Sub
Sub Obtener(nfila As Integer)
Rotz = DataGridView1.Rows(nfila).Cells(1).Value
tx = DataGridView1.Rows(nfila).Cells(2).Value
ty = DataGridView1.Rows(nfila).Cells(3).Value
Ex = DataGridView1.Rows(nfila).Cells(4).Value
Ey = DataGridView1.Rows(nfila).Cells(5).Value
CentroX = DataGridView1.Rows(nfila).Cells(6).Value
CentroY = DataGridView1.Rows(nfila).Cells(7).Value
ancho = DataGridView1.Rows(nfila).Cells(8).Value
alto = DataGridView1.Rows(nfila).Cells(9).Value
Transparencia = DataGridView1.Rows(nfila).Cells(10).Value
rojo = DataGridView1.Rows(nfila).Cells(11).Value
verde = DataGridView1.Rows(nfila).Cells(12).Value
azul = DataGridView1.Rows(nfila).Cells(13).Value
paso = DataGridView1.Rows(nfila).Cells(14).Value
End Sub
Sub Figura(centrox As Single, centroy As Single, ancho As Single, alto As Single,
brocha As SolidBrush)
grafico.FillEllipse(brocha, centrox - (ancho / 2), centroy - (alto / 2), ancho, alto)
grafico.DrawEllipse(pluma, centrox - (ancho / 2), centroy - (alto / 2), ancho, alto)
End Sub
Sub coordenadas(centrox As Single, centroy As Single, ancho As Single, alto As
Single)
grafico.DrawLine(Pens.Blue, centrox - ancho / 2, centroy, centrox + ancho / 2,
centroy)
grafico.DrawLine(Pens.Blue, centrox, centroy - alto / 2, centrox, centroy + alto / 2)
End Sub
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -1007-
Sub GraficarFigura(centrox As Single, centroy As Single, ancho As Single, alto As
Single, brocha1 As SolidBrush)
' brocha.Color = Color.Yellow
Figura(centrox, centroy, ancho, alto, brocha1)
' la nariz
brocha.Color = Color.Orange
Figura(centrox, centroy - alto * 0.16, ancho * 0.16, alto * 0.14, brocha)
' mas los ojos
brocha.Color = Color.White
Figura(centrox - ancho * 0.12, centroy - alto * 0.43, ancho * 0.16, alto * 0.43,
brocha)
Figura(centrox + ancho * 0.12, centroy - alto * 0.43, ancho * 0.16, alto * 0.43,
brocha)
brocha.Color = Color.Blue
Figura(centrox - ancho * 0.12, centroy - alto * 0.43, ancho * 0.08, alto * 0.2,
brocha)
Figura(centrox + ancho * 0.12, centroy - alto * 0.43, ancho * 0.08, alto * 0.2,
brocha)
brocha.Color = Color.Black
Figura(centrox - ancho * 0.12, centroy - alto * 0.43, ancho * 0.04, alto * 0.1,
brocha)
Figura(centrox + ancho * 0.12, centroy - alto * 0.43, ancho * 0.04, alto * 0.1,
brocha)
' coordenadas(CentroX, CentroY, ancho, alto)
Dim x1, y1, x2, y2 As Integer
x1 = CInt(centrox - ancho * 0.4)
y1 = CInt(centroy - alto * 0.2)
x2 = CInt(ancho * 0.8)
y2 = CInt(alto * 0.4)
Dim Trayecto1 As New GraphicsPath()
Trayecto1.AddArc(x1, y1, x2, y2, 0, 180)
x1 = CInt(centrox - ancho * 0.3)
y1 = CInt(centroy - alto * 0.3)
x2 = CInt(ancho * 0.6)
y2 = CInt(alto * 0.6)
Dim Trayecto2 As New GraphicsPath()
Trayecto2.AddArc(x1, y1, x2, y2, 0, 180)
Dim Región1 As New Region(Trayecto1) 'Creamos un objeto Region
Dim Región2 As New Region(Trayecto2) 'Creamos un objeto Region
Región2.Exclude(Región1)
grafico.FillRegion(brocha, Región2)
grafico.DrawPath(pluma, Trayecto1)
grafico.DrawPath(pluma, Trayecto2)
Trayecto1.Dispose()
Trayecto2.Dispose()
End Sub
'*******************************
Imports System.IO
Module Module1
Public Rotz As Single
Public tx As Single
Public ty As Single
Public Ex As Single
Public Ey As Single
Sub Graficar(Cx1 As Integer, cy1 As Integer, Cx2 As Integer, cy2 As Integer, Cx3 As
Integer, cy3 As Integer)
Dim fila, col As Integer
Dim MapaBits1 As New Bitmap(AnchoBitmaps, AltoBitmaps)
Dim MapaBits2 As New Bitmap(AnchoBitmaps, AltoBitmaps)
Dim MapaBits3 As New Bitmap(AnchoBitmaps, AltoBitmaps)
Dim MapaBits4 As New Bitmap(AnchoBitmaps, AltoBitmaps)
Dim grafico1 As Graphics = Graphics.FromImage(MapaBits1)
Dim grafico2 As Graphics = Graphics.FromImage(MapaBits2)
Dim grafico3 As Graphics = Graphics.FromImage(MapaBits3)
Dim grafico4 As Graphics = Graphics.FromImage(MapaBits4)
10.35 Iluminacion
con un foco ( el foco puede variar de color ,tamaño, el grado de oscuridad tambien
varia) en el ejemplo se ve con foco de color blaco
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -1016-
Imports System.Drawing
Public Class Form1
Inherits Form
Dim paso As Integer = 10
Dim dradio As Single = 1
Dim dfactor As Single = 0.1
Dim grafico1 As Graphics
Dim grafico2 As Graphics
Dim grafico3 As Graphics
Dim factorluz As Single = 0.5 ' 0.8 '
Dim Cx1 As Single = 20
Dim Cy1 As Single = 20
Dim radio As Integer = 30
Dim AnchoBitmaps As Integer = 183
Dim AltoBitmaps As Integer = 275
Dim brocha As SolidBrush
Sub Graficar(Cx1 As Integer, cy1 As Integer, Radio As Single, factorluz As Single)
Dim fila, col As Integer
Dim MapaBits2 As New Bitmap("E:\datos\UNSA2.jpg")
AnchoBitmaps = MapaBits2.Width
AltoBitmaps = MapaBits2.Height
Dim MapaBits1 As New Bitmap(AnchoBitmaps, AltoBitmaps)
EJERCICIO DE BITMAPS
El siguiente Ejercicio permite detectar manchas en una superficie puede ser lana, tela,
papel, maquinas, etc., con algunas mejoras puede detectar firmas, huellas digitales,
reconocer rostros, figuras, etc.
Abrir. Permite seleccionar y abrir la foto tomada de la imagen a procesar (la foto
puede tener máximo 600x500 pixeles se puede aumentar más de acuerdo a la
capacidad de la computadora)
Procesar. Procesa los pixeles de la foto (en este caso es un bitmaps) obtiene los
colores rojo, verde, azul en tres matrices, también obtiene la matriz de grises y matriz
de blanco y negro que se usara para determinar la ubicación, tamaño y la cantidad de
las manchas.
Luego muestra el resultado en un cuadro de imagen con escalas Ex e dadas ósea
puede ser más grande o más pequeño, En este caso la escala es Ex=2 y EY = 2
Ver Todo.- Muestra los componentes rojo, verde y azul de la figura (o sea la figura
original)
Imports System.Drawing
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
txtEx.Text = ex
txtEy.Text = ey
txtLimite.Text = limite
Grafico = PictureBox2.CreateGraphics
brocha1 = New SolidBrush(Drawing.Color.Red)
End Sub
Sub MostrarMatriz(ByVal cx As Integer, ByVal cy As Integer, ByVal nf As Integer,
ByVal nc As Integer, ByVal ex As Single, ByVal ey As Single)
Dim fila As Integer, col As Integer
Dim Rojo, Verde, Azul As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Rojo = Rojos(fila, col)
Verde = Verdes(fila, col)
Azul = Azules(fila, col)
brocha1.Color = Color.FromArgb(Rojo, Verde, Azul)
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -1025-
Grafico.FillRectangle(brocha1, cx + ex * col, cy + ey * fila, ex, ey)
Next
Next
End Sub
Private Sub BtnMostrar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnMostrar.Click
ex = txtEx.Text
ey = txtEy.Text
limite = txtLimite.Text
MostrarMatriz(0, 0, nf, nc, ex, ey)
End Sub
Private Sub btnBorrar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles
btnBorrar.Click
Grafico.Clear(Drawing.Color.Black)
ListBox2.Items.Clear()
End Sub
Private Sub btnProcesar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnProcesar.Click
Dim fila, col As Integer
Dim gris As Byte
For fila = 0 To nf - 1
For col = 0 To nc - 1
Color1 = Pict1.GetPixel(col, fila)
Rojos(fila, col) = Color1.R
Verdes(fila, col) = Color1.G
Azules(fila, col) = Color1.B
gris = CByte(Color1.R * 0.33 + Color1.G * 0.33 + Color1.B * 0.33)
'If gris > 255 Then gris = 255
'If gris < 0 Then gris = 0
Grises(fila, col) = gris
If Grises(fila, col) > limite Then
BN(fila, col) = 1
Else
BN(fila, col) = 0
End If
Next
Next
End Sub
Imports System.Drawing
Module Module1
Public brocha1 As SolidBrush
Public Grafico As Graphics
Public graficoTodo As Graphics
Public graficoRojo As Graphics
Public graficoVerde As Graphics
Public graficoAzul As Graphics
Public graficoGris As Graphics
Public graficoBN As Graphics
Public limite As Byte = 180 ' 128
Public Color1 As Color
Public Pict1 As Bitmap
Public Const maxfilas As Integer = 500
Public maxcol As Integer = 600
Public ex As Integer = 2
Public ey As Integer = 2
Public nf As Integer = 40
Public nc As Integer = 40
Public Rojos(maxfilas, maxcol) As Byte
Public Verdes(maxfilas, maxcol) As Byte
Public Azules(maxfilas, maxcol) As Byte
Public Grises(maxfilas, maxcol) As Byte
Public BN(maxfilas, maxcol) As Byte
' Public Matriz(maxfilas, maxcol) As Integer
'*******************
Public px As Integer = 2
Public py As Integer = 2
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -1029-
Public Cont1 As Integer = 0 ' contador de puntos iniciales
Public Cont2 As Integer = 0 ' contador de puntos en la mancha
Public mancha As Byte = 0
Public blanco As Byte = 1
Dim control1 As Byte = 0 ' control para determinar si no hay mas manchas
Sub main()
RecuperarMatriz("E:\datos\matriz8x8.txt", BN, nf, nc)
MostrarMatriz(BN, nf, nc)
Cont1 = 0
Do
control1 = UbicarPunto(BN, nf, nc, px, py, mancha)
If control1 = 1 Then
'Matriz(py, px) = blanco
Console.WriteLine("cont1 = {0} px = {1} py = {2} ", Cont1, px, py)
Cont2 = 0
ContarTamaño(BN, px, py, mancha)
Console.WriteLine("tamaño= {0} ", Cont2)
Cont1 = Cont1 + 1
Else
Console.WriteLine("Punto no encontrado ")
End If
Loop While control1 = 1
Console.WriteLine("Cantidad de puntos {0} ", Cont1)
Console.ReadLine()
End Sub
End Module
Imports System.IO
Module Module2
Sub RecuperarMatriz(ByVal nombrearchivo As String, ByRef A(,) As Byte, ByVal nf
As Integer, ByVal nc As Integer)
Dim srLector As StreamReader
srLector = New StreamReader(nombrearchivo)
Dim fila As Integer, col As Integer
Dim cadena As String = ""
Dim subcadena As String
Dim pos As Integer = 0
Dim inicio As Integer = 1
For fila = 0 To nf - 1
cadena = srLector.ReadLine()
cadena = cadena & Chr(9)
inicio = 1
For col = 0 To nc - 1
pos = InStr(inicio, cadena, Chr(9))
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, col) = CInt(CSng(Val(subcadena)))
inicio = pos + 1
Next
Next
Console.WriteLine("Archivo leido satisfactoriamente")
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -1030-
srLector.Close()
End Sub
Sub MostrarMatriz(ByVal A(,) As Byte, ByVal nf As Integer, ByVal nc As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Console.Write("{0} {1}", A(fila, col), vbTab)
Next
Console.WriteLine()
Next
End Sub
10.37 TAREA.
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -1031-
Mejore el programa para detectar bordes, transparencias, etc. (para detectar bordes
consulte el capítulo 11 del libro de Visual Basic)
Aplique el programa mejorado
1. Para detectar huellas dactilares
2. Para detectar manchas en telas, papel, ropa, etc.
3. Para ver reconocer el estado de maduración de una fruta por cambio de color y
aparición de color por ejemplo el plátano
4. Reconocer una firma
5. Reconocer una figura para usar en el CNC ( ejemplo una plantilla)
6. Reconocer el número de ojos que tiene una papa y otras características por
ejemplo color tamaño y de acuerdo a ello comparando con la base de datos decir
que tipo de papa es
7. Reconocer un rostro
8. Reconocer figuras ,por forma(triangulo, cuadrado, circulo ,etc.) ,color, área, y
Otras características
9. Reconocer una hoja y de acuerdo a ello que tipo de planta es
10. Se tiene semillas de quinua de diferentes colores determinar cuántas semillas de
cada color hay tomando una foto
11. tomar una foto de una semilla y determinar qué tipo de semilla es si es arroz, trigo,
maíz , habas, manzana,etc
12. de acuerdo a la foto la computadora debe identificar un producto por ejemplo un,
lapicero, lápiz, plumón, llaves, etc.
13. Tomando fotografía donde la cámara gira alrededor del objeto y el objeto gira
alrededor de la cámara, obtenga una imagen 3D
14. Escanea una foto a colores y de acuerdo a ello calcular la cantidad de colores rojo,
verde y azul que se necesitara para imprimir o pintar
15. implementar otras aplicaciones por ejemplo en automatización (con leds RGB)
ARBOLES
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -1035-
Imports System.Drawing
Public Class Form1
Dim Pen As Pen
Dim Grafico As Graphics
Dim brocha As SolidBrush
Dim np As Integer = 6
Dim MiFuente As New Font("Verdana", 12, FontStyle.Bold)
Sub GraficarPoligono(cx As Integer, cy As Integer, X() As Single, Y() As Single,
ex As Single, ey As Single, np As Integer)
Dim fila As Integer
Dim Puntos(np - 1) As Point
For fila = 0 To np - 1
Puntos(fila).X = cx + CInt(X(fila) * ex)
Puntos(fila).Y = cy + CInt(Y(fila) * ey)
Next
Grafico.FillPolygon(brocha, Puntos)
Grafico.DrawPolygon(Pen, Puntos)
End Sub
Module module1
Const tam As Integer = 20
Sub main()
Dim area As Single
RecuperarVectoresXY(NombreArchivo, VX1, VY1, nfilas, ncol)
MostrarVectoresXY(VX1, VY1, nfilas)
Console.WriteLine("METODO TRAPECIAL")
area = Trapecial(VX1, VY1, nfilas)
Console.WriteLine(" EL AREA es {0}", area)
Console.ReadLine()
End Sub
End Module
Imports System.IO
Module Module2
Public NombreArchivo As String = "C:\datos\TRI1.txt"
Programacion y Metodos numéricos 2019a \10 Aplicaciones Windows Forms \Ismael Véliz Vilca -1038-
Public Const limite As Integer = 10
Public VX1(limite) As Single
Public VY1(limite) As Single
Public nfilas, ncol As Integer
Public tx As Single = 10
Public ty As Single = 200
Public ex As Single = 50
Public ey As Single = -50
10 9
7 6
10 7
9 1
4 -6
-1 8
6 -5
6 5
-7 -4
3 -4
1 7
-5 0
2 3
-7 -3
-8 1
-8 -2
-6 2
3 5
-9 7
-4 -8