You are on page 1of 9

Public Class Form2

Dim O As Integer = -1
Dim Mt As Integer
Dim Nt As Integer
Dim pi As Double = 3.1415926535897931
Dim C As Integer
Dim Xx() As Double
Dim Yy() As Double
Dim M() As Double
Dim i() As Double
Dim j() As Double
Dim Ee() As Double
Dim Aa() As Double
Dim Ii() As Double

Private Sub Coordenadas_RowPostPaint(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles
dataGridView1.RowPostPaint
Try
'Captura el numero de filas del datagridview
Dim RowsNumber As String = (e.RowIndex + 1).ToString
While RowsNumber.Length < dataGridView1.RowCount.ToString.Length
RowsNumber = "0" & RowsNumber
End While
Dim size As SizeF = e.Graphics.MeasureString(RowsNumber, Me.Font)
If dataGridView1.RowHeadersWidth < CInt(size.Width + 20) Then
dataGridView1.RowHeadersWidth = CInt(size.Width + 20)
End If
Dim ob As Brush = SystemBrushes.ControlText
e.Graphics.DrawString(RowsNumber, Me.Font, ob, e.RowBounds.Location.X + 15,
e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
Catch ex As Exception
MessageBox.Show(ex.Message, "vb.net", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub

Private Sub Restricciones_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As


System.EventArgs) Handles Restricciones.CurrentCellDirtyStateChanged

End Sub

Private Sub Restricciones_RowPostPaint(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles
Restricciones.RowPostPaint
Try
'Captura el numero de filas del datagridview
Dim RowsNumber As String = (e.RowIndex + 1).ToString
While RowsNumber.Length < Restricciones.RowCount.ToString.Length
RowsNumber = "0" & RowsNumber
End While
Dim size As SizeF = e.Graphics.MeasureString(RowsNumber, Me.Font)
If Restricciones.RowHeadersWidth < CInt(size.Width + 20) Then
Restricciones.RowHeadersWidth = CInt(size.Width + 20)
End If
Dim ob As Brush = SystemBrushes.ControlText
e.Graphics.DrawString(RowsNumber, Me.Font, ob, e.RowBounds.Location.X + 15,
e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
Catch ex As Exception
MessageBox.Show(ex.Message, "vb.net", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub Cargas_RowPostPaint(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles Cargas.RowPostPaint
Try
'Captura el numero de filas del datagridview
Dim RowsNumber As String = (e.RowIndex + 1).ToString
While RowsNumber.Length < Cargas.RowCount.ToString.Length
RowsNumber = "0" & RowsNumber
End While
Dim size As SizeF = e.Graphics.MeasureString(RowsNumber, Me.Font)
If Cargas.RowHeadersWidth < CInt(size.Width + 20) Then
Cargas.RowHeadersWidth = CInt(size.Width + 20)
End If
Dim ob As Brush = SystemBrushes.ControlText
e.Graphics.DrawString(RowsNumber, Me.Font, ob, e.RowBounds.Location.X + 15,
e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
Catch ex As Exception
MessageBox.Show(ex.Message, "vb.net", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub

Private Sub Coordenadas_RowsAdded(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewRowsAddedEventArgs) Handles dataGridView1.RowsAdded
O=O+1
End Sub

Private Sub CoordenadasToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles CoordenadasToolStripMenuItem.Click
dataGridView1.Columns(0).HeaderText = "X"
dataGridView1.Columns(1).HeaderText = "Y"
C=0

End Sub

Private Sub DefinicionDeMiembrosToolStripMenuItem_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles DefinicionDeMiembrosToolStripMenuItem.Click
dataGridView1.Columns(0).HeaderText = "i"
dataGridView1.Columns(1).HeaderText = "j"
C=1
Me.dataGridView1.CurrentCell = Me.dataGridView1(0, O)
Dim im, jm As Integer
For im = 0 To O
For jm = 0 To 1
dataGridView1.Rows(im).Cells(jm).Value = ""
Next
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
If (C = 0) Then
Dim im, jm As Integer
Nt = 0
For im = 0 To O
If (dataGridView1.Rows(im).Cells(0).Value <> "") Then
Nt = Nt + 1
End If
Next

ReDim Xx(Nt)
ReDim Yy(Nt)
For jm = 1 To Nt
Xx(jm) = dataGridView1.Rows(jm - 1).Cells(0).Value
Yy(jm) = dataGridView1.Rows(jm - 1).Cells(1).Value
Next

ElseIf (C = 1) Then
Dim im, jm As Integer
Mt = 0
For im = 0 To O
If (dataGridView1.Rows(im).Cells(0).Value <> "") Then
Mt = Mt + 1
End If
Next

ReDim M(Mt)
ReDim i(Mt)
ReDim j(Mt)
For jm = 1 To Mt
If (dataGridView1.Rows(jm - 1).Cells(0).Value < dataGridView1.Rows(jm -
1).Cells(1).Value) Then
i(jm) = dataGridView1.Rows(jm - 1).Cells(0).Value
j(jm) = dataGridView1.Rows(jm - 1).Cells(1).Value

Else
i(jm) = dataGridView1.Rows(jm - 1).Cells(1).Value
j(jm) = dataGridView1.Rows(jm - 1).Cells(0).Value

End If
Next
ElseIf (C = 2) Then
Dim im As Integer
ReDim Ee(Mt)
For im = 1 To Mt
Ee(im) = dataGridView1.Rows(im - 1).Cells(0).Value
Next
ElseIf (C = 3) Then
Dim im As Integer
ReDim Ii(Mt)
ReDim Aa(Mt)
For im = 1 To Mt
Dim D As Double
D = dataGridView1.Rows(im - 1).Cells(0).Value
Aa(im) = D ^ 2 * pi / 4
Ii(im) = D ^ 4 * pi / 64
Next
ElseIf (C = 4) Then
Dim im As Integer
ReDim Ii(Mt)
ReDim Aa(Mt)
For im = 1 To Mt
Dim Base, Altura As Double
Base = dataGridView1.Rows(im - 1).Cells(0).Value
Altura = dataGridView1.Rows(im - 1).Cells(1).Value
Aa(im) = Base * Altura
Ii(im) = Base * Altura ^ 3 / 12
Next
End If
End Sub

Private Sub CALCULAR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles CALCULAR.Click
Dim KD(6 * Mt - 1, 6 * Mt - 1) As Double
Dim ckd As Integer = 0
Dim im As Integer
'Matriz de rotacion del elemento'
For im = 1 To Mt
Dim ang, formula As Double
Dim R(5, 5) As Double
Dim Rt(5, 5) As Double
formula = ((Xx(j(im))) - (Xx(i(im)))) / ((((Xx(j(im))) - (Xx(i(im)))) ^ 2 + ((Yy(j(im))) -
(Yy(i(im)))) ^ 2) ^ 0.5)
ang = Math.Acos(formula)
If ((Yy(j(im))) - (Yy(i(im))) < 0) Then
ang = 2 * pi - ang
End If

'VERIFICACION'
MsgBox("ANG(" & (im) & ")" & ang)

R(0, 0) = Math.Cos(ang)
R(0, 1) = -Math.Sin(ang)

R(1, 0) = Math.Sin(ang)
R(1, 1) = Math.Cos(ang)
R(2, 2) = 1
R(3, 3) = Math.Cos(ang)
R(3, 4) = -Math.Sin(ang)
R(4, 3) = Math.Sin(ang)
R(4, 4) = Math.Cos(ang)
R(5, 5) = 1
Rt(0, 0) = Math.Cos(ang)
Rt(0, 1) = -Math.Sin(ang)
Rt(1, 0) = Math.Sin(ang)
Rt(1, 1) = Math.Cos(ang)
Rt(2, 2) = 1
Rt(3, 3) = Math.Cos(ang)
Rt(3, 4) = -Math.Sin(ang)
Rt(4, 3) = Math.Sin(ang)
Rt(4, 4) = Math.Cos(ang)
Rt(5, 5) = 1
'Matriz transpuesta de rotacion del elemento'
Dim irot, jrot As Integer
Dim Crot As Integer = 0
Dim Drot As Double
For irot = 0 To 5
For jrot = Crot To 5
Drot = Rt(irot, jrot)
Rt(irot, jrot) = Rt(jrot, irot)
Rt(jrot, irot) = Drot
Next
Crot = Crot + 1
Next

'Obtencion matriz de rigidez del elemnto '


Dim ke(5, 5) As Double
Dim L As Double
L = (((Xx(j(im))) - (Xx(i(im)))) ^ 2 + ((Yy(j(im))) - (Yy(i(im)))) ^ 2) ^ 0.5
'VERIFICACION'
MsgBox("L(" & (im) & ")" & L)
ke(0, 0) = Ee(im) * Aa(im) / L
ke(0, 3) = -Ee(im) * Aa(im) / L
ke(1, 1) = 12 * Ee(im) * Ii(im) / L ^ 3
ke(1, 2) = 6 * Ee(im) * Ii(im) / L ^ 2
ke(1, 4) = -12 * Ee(im) * Ii(im) / L ^ 3
ke(1, 5) = 6 * Ee(im) * Ii(im) / L ^ 2
ke(2, 1) = 6 * Ee(im) * Ii(im) / L ^ 2
ke(2, 2) = 4 * Ee(im) * Ii(im) / L
ke(2, 4) = -6 * Ee(im) * Ii(im) / L ^ 2
ke(2, 5) = 2 * Ee(im) * Ii(im) / L
ke(3, 0) = -Ee(im) * Aa(im) / L
ke(3, 3) = Ee(im) * Aa(im) / L
ke(4, 1) = -12 * Ee(im) * Ii(im) / L ^ 3
ke(4, 2) = -6 * Ee(im) * Ii(im) / L ^ 2
ke(4, 4) = 12 * Ee(im) * Ii(im) / L ^ 3
ke(4, 5) = -6 * Ee(im) * Ii(im) / L ^ 2
ke(5, 1) = 6 * Ee(im) * Ii(im) / L ^ 2
ke(5, 2) = 2 * Ee(im) * Ii(im) / L
ke(5, 4) = -6 * Ee(im) * Ii(im) / L ^ 2
ke(5, 5) = 4 * Ee(im) * Ii(im) / L
'Obtencion matriz de rigidez del elemento rotado K= R * ke * Rinv'
'Primera multiplicacion R * ke'
Dim hka, ika, jka As Integer
Dim valor As Double
Dim Ka(5, 5) As Double
For hka = 0 To 5
For ika = 0 To 5
valor = 0
For jka = 0 To 5
valor = valor + R(hka, jka) * ke(jka, ika)
Next
Ka(hka, ika) = valor
Next
Next
'Segunda Multiplicacion Ka * Rinv'
Dim hk, ik, jk As Integer
Dim valork As Double
Dim K(5, 5) As Double
For hk = 0 To 5
For ik = 0 To 5
valork = 0
For jk = 0 To 5
valork = valork + Ka(hk, jk) * Rt(jk, ik)
Next
K(hk, ik) = valork
Next
Next
'Matriz de rigidez desensamblada KD'
Dim ikd, jkd As Integer
For ikd = 0 To 5
For jkd = 0 To 5
KD(ikd + ckd, jkd + ckd) = ke(ikd, jkd)
Next

Next
ckd = ckd + 6
Next
'VERIFICACIO'
'CORRECTO APROBADO'

'Matriz de Compatibilidad A y Matriz de Equilibrio At'


Dim A(Mt * 6 - 1, Nt * 3 - 1) As Integer
Dim At(Nt * 3 - 1, Mt * 6 - 1) As Integer
Dim S As Integer = 0
Dim imm As Integer
For imm = 1 To Mt
S=S+1
A(3 * S - 3, 3 * i(imm) - 3) = 1
A(3 * S - 2, 3 * i(imm) - 2) = 1
A(3 * S - 1, 3 * i(imm) - 1) = 1
At(3 * i(imm) - 3, 3 * S - 3) = 1
At(3 * i(imm) - 2, 3 * S - 2) = 1
At(3 * i(imm) - 1, 3 * S - 1) = 1
S=S+1
A(3 * S - 3, 3 * j(imm) - 3) = 1
A(3 * S - 2, 3 * j(imm) - 2) = 1
A(3 * S - 1, 3 * j(imm) - 1) = 1
At(3 * j(imm) - 3, 3 * S - 3) = 1
At(3 * j(imm) - 2, 3 * S - 2) = 1
At(3 * j(imm) - 1, 3 * S - 1) = 1
Next
'VERIFICACION'
'COMPROBADO'

'Obtencion MATRIZ DE RIGIDEZ DE LA ESTRUCTURA K= At * K * A'


'Primera multiplicacion At * k'
Dim hre, ire, jre As Integer
Dim valor1 As Double
Dim Kp(3 * Nt - 1, 6 * Mt - 1) As Double
For hre = 0 To 3 * Nt - 1
For ire = 0 To 6 * Mt - 1
valor1 = 0
For jre = 0 To 6 * Mt - 1
valor1 = valor1 + At(hre, jre) * KD(jre, ire)
Next
Kp(hre, ire) = valor1
Next
Next
'Segunda multiplicacion Ka * A'
Dim hree, iree, jree As Integer
Dim valor2 As Double
Dim KRE(3 * Nt - 1, 3 * Nt - 1) As Double
For hree = 0 To 3 * Nt - 1
For iree = 0 To 3 * Nt - 1
valor2 = 0
For jree = 0 To 6 * Mt - 1
valor2 = valor2 + Kp(hree, jree) * A(jree, iree)
Next
KRE(hree, iree) = valor2
Next
Next
Dim iiiii As Double
For iiiii = 0 To Nt * 3 - 1
MsgBox("KRE(" & (iiiii) & "," & (iiiii) & ")= " & KRE(iiiii, iiiii))

Next

'OBTENCION VECTOR FUERZA'


Dim F(Nt * 3) As Double
Dim iff As Integer
For iff = 1 To Nt
F(3 * iff - 2) = Cargas.Rows(iff - 1).Cells(0).Value
F(3 * iff - 1) = Cargas.Rows(iff - 1).Cells(1).Value
F(3 * iff) = Cargas.Rows(iff - 1).Cells(2).Value
Next
'Obtencion vector desplazamiento'

End Sub

Private Sub ModuloElasticoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles ModuloElasticoToolStripMenuItem.Click
dataGridView1.Columns(0).HeaderText = "E"
dataGridView1.Columns(1).HeaderText = ""
C=2
'BORRAR CELDAS'
Me.dataGridView1.CurrentCell = Me.dataGridView1(0, O)
Dim im, jm As Integer
For im = 0 To O
For jm = 0 To 1
dataGridView1.Rows(im).Cells(jm).Value = ""
Next
Next

End Sub

Private Sub CIRCULARToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles CIRCULARToolStripMenuItem.Click
dataGridView1.Columns(0).HeaderText = "D"
dataGridView1.Columns(1).HeaderText = ""
C=3
'BORRAR CELDAS'
Me.dataGridView1.CurrentCell = Me.dataGridView1(0, O)
Dim im, jm As Integer
For im = 0 To O
For jm = 0 To 1
dataGridView1.Rows(im).Cells(jm).Value = ""
Next
Next
End Sub

Private Sub CUADRADAToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles CUADRADAToolStripMenuItem.Click
dataGridView1.Columns(0).HeaderText = "B"
dataGridView1.Columns(1).HeaderText = "H"
C=4
'BORRAR CELDAS'
Me.dataGridView1.CurrentCell = Me.dataGridView1(0, O)
Dim im, jm As Integer
For im = 0 To O
For jm = 0 To 1
dataGridView1.Rows(im).Cells(jm).Value = ""
Next
Next
End Sub

Private Sub pruebas_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles pruebas.Click
MsgBox(Math.Acos(1))

End Sub

Private Sub IntroduccionDeApoyosToolStripMenuItem_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles IntroduccionDeApoyosToolStripMenuItem.Click
Restricciones.Visible = True
dataGridView1.Visible = False
Cargas.Visible = False

Dim R As Integer = 0
For R = 1 To Nt
With Restricciones
.Rows.Add()
End With
Next
End Sub

Private Sub ApoyoMovilToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles IntroduccionCargas.Click
Restricciones.Visible = False
dataGridView1.Visible = False
Cargas.Visible = True

Dim R As Integer = 0
For R = 1 To Nt
With Cargas
.Rows.Add()
End With
Next
End Sub

Private Sub Restricciones_CellContentClick(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.DataGridViewCellEventArgs) Handles Restricciones.CellContentClick
End Sub
End Class

CellValueChanged

Public Class Form1