Imports System.Math Public Class Elipsoide Public SemiEixoMaior As double Public Excentricidade As double Public Nome As String Public Sub New(nome as String, a as Double, f as Double) Dim fi as Double = 1/f SemiEixoMaior = a Excentricidade = Sqrt(2*fi - fi^2) Nome = nome End Sub End Class Public Class Mercator Public Elip As Elipsoide Public x As Double Public y As Double Public k As Double Public m As Double Public ReadOnly Property c As Double Get Return 0 ' convergência meridiana é sempre zero End Get End Property Public Sub New(el As Elipsoide, lat As Double, lon As Double, Optional ByVal l0 As Double = 0) Elip = el m = l0 x = Calcular_X(lon * PI / 180) y = Calcular_Y(lat * PI / 180) k = Calcular_K(lat * PI / 180) End Sub Public Function Calcular_X(ByVal longitude As Double) As Double Return Elip.SemiEixoMaior * (longitude - m * PI / 180) End Function Public Function Calcular_Y(ByVal latitude As Double) As Double Dim termo1 As Double = Tan(PI / 4 + latitude / 2) Dim termo2 As Double = (1 - Elip.Excentricidade * Sin(latitude)) / (1 + Elip.Excentricidade * Sin(latitude)) Dim termo3 As Double = Pow(termo2, Elip.Excentricidade / 2) Return Elip.SemiEixoMaior * Log(termo1 * termo3) End Function Public Function Calcular_K(ByVal latitude As Double) As Double Dim N As Double = Elip.SemiEixoMaior / Sqrt(1 - Pow(Elip.Excentricidade, 2) * Pow(Sin(latitude), 2)) Return Elip.SemiEixoMaior / (N * Cos(latitude)) End Function Public Shared Function ProblemaInverso(el As Elipsoide, x As Double, y As Double, m As Double) As Double() Dim e As Double = el.Excentricidade Dim a As Double = el.SemiEixoMaior Dim l As Double = (x / a + m * PI / 180) Dim t As Double = Exp(-y / a) Dim o0 As Double = PI / 2 - 2 * Atan(t) Dim o(50) As Double o(0) = o0 Dim i As Integer For i = 1 To o.Length - 1 o(i) = PI / 2 - 2 * Atan(t * (((1 - e * Sin(o(i - 1))) / (1 + e * Sin(o(i - 1)))) ^ (e / 2))) If Abs(o(i - 1) - o(i)) <= 0.00000001 Then Exit For End If Next Return New Double() {o(i) * 180 / PI, l * 180 / PI} End Function End Class Module Teste Public Sub Main() 'Altere estes valores: 'Entrada '************************************************' Dim lat = -8.50411 'Latitude em graus decimais Dim lon = -32.20301 'Longitude em graus decimais Dim m = -33 'Meridiano Central '************************************************' Dim el As New Elipsoide("GRS80", 6378137, 298.257222101) Dim mer As New Mercator(el, lat, lon, m) 'PROBLEMA DIRETO Dim mer_inv1 = Mercator.ProblemaInverso(el, mer.x, mer.y, m) 'PROBLEMA INVERSO 'Saída '************************************************' Dim str as String = "Coord. de Entrada (lat, lon, merid central):" & vbNewLine & "(" & lat & "," & lon & "," & m & ")" Console.Write(str) Console.Write(vbNewLine & "Problema Direto:") str = vbNewLine & "(x, y, fator escala):" & vbNewLine & "(" & Round(mer.x,3) & "," & Round(mer.y,3) & "," & Round(mer.k,8) & ")" Console.Write(str) Console.Write(vbNewLine & "Problema Inverso:") str = vbNewLine & "(lat, lon):" & vbNewLine & "(" & Round(mer_inv1(0),8) & "," & Round(mer_inv1(1),8) & ")" Console.Write(str) '************************************************' End Sub End Module
Write, Run & Share VB.net code online using OneCompiler's VB.net online compiler for free. It's one of the robust, feature-rich online compilers for VB.net language, running on the latest version 16. Getting started with the OneCompiler's VB.net compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as VB.net
. OneCompiler also has reference programs, where you can look for the sample code to get started with.
OneCompiler's VB.net online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample VB.net program which takes name as input and prints hello message with your name.
Public Module Program
Public Sub Main(args() As string)
Dim name as String = Console.ReadLine() ' Reading input from STDIN
Console.WriteLine("Hello " & name) ' Writing output to STDOUT
End Sub
End Module
Visual Basic is a event driven programming language by Microsoft, first released in the year 1991.
Variable is a name given to the storage area in order to identify them in our programs.
Simple syntax of Variable declaration is as follows
Dim variableName [ As [ New ] dataType ] [ = initializer ]
variableName = value
If condition-expression Then
'code
End If
If(conditional-expression)Then
'code if the conditional-expression is true
Else
'code if the conditional-expression is false
End If
If(conditional-expression)Then
'code if the above conditional-expression is true
Else If(conditional-expression) Then
'code if the above conditional-expression is true
Else
'code if the above conditional-expression is false
End If
If(conditional-expression)Then
'code if the above conditional-expression is true
If(conditional-expression)Then
'code if the above conditional-expression is true
End If
End If
Select [ Case ] expression
[ Case expressionlist
'code ]
[ Case Else
'code ]
End Select
For counter [ As datatype ] = begin To end [ Step step ]
'code
[ Continue For ]
'code
[ Exit For ]
'code
Next [ counter ]
For Each element [ As datatype ] In group
'code
[ Continue For ]
'code
[ Exit For ]
'code
Next [ element ]
While conditional-expression
'Code
[ Continue While ]
'Code
[ Exit While ]
'Code
End While
Do { While | Until } conditional-expression
'Code
[ Continue Do ]
'Code
[ Exit Do ]
'Code
Loop
Do
'Code
[ Continue Do ]
'Code
[ Exit Do ]
'Code
Loop { While | Until } conditional-expression
Procedure is a sub-routine which contains set of statements. Usually Procedures are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
Procedures are of two types.
Functions return a value when they are called.
[accessModifiers] Function functionName [(parameterList)] As returnType
'code
End Function
Sub-procedures are similar to functions but they don't return any value.
Sub ProcedureName (parameterList)
'Code
End Sub