Search This Blog

Most Viewed

Monday, May 2, 2011

Curve Plotting in vb.net





The code for Curve Plotting in VB.Net is given below with the rotation and shear transformation in Cartesian Coordinate system 


≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡



Imports System.Math


Public Class transform

    Private Sub transform_Load(ByVal sender As System.Object,
                               ByVal e As System.EventArgs) Handles MyBase.Load
        CurvePic.BackColor = Color.White

    End Sub

    Private Sub DrawBtn_Click(ByVal sender As System.Object,
                              ByVal e As System.EventArgs) Handles DrawBtn.Click
        CurvePic.Refresh()

        Dim graph As Graphics
        graph = Graphics.FromHwnd(CurvePic().Handle)

        Dim curvescript As New MSScriptControl.ScriptControl
        curvescript.Language = "VBscript"


        Dim x, y As Double          'Cartesian Coordinate of Curve
        Dim ox, oy As Double        'Computer Coordinate of Origin
        Dim acc As Double           'Sampling time period
        Dim xscl, yscl As Double    'Scal Factor in x and y direction
        Dim posx, posy As Long      'Computer coordinate of curve
        Dim rposx, rposy As Long    'Rotated Computer Coordinate of Curve
        Dim sposx, sposy As Long    'Sheard Computer Coordinate of curve
        Dim q As Double             'Roatation angle
        Dim rx, ry As Double        'Rotated Cartesian Coordinate of curve
        Dim sx, sy As Double        'Sheard Caresian Coordinate of curve
        Dim k1, k2 As Double        'Shear Factor

        'Shear Factor
        Try
            k1 = CDbl(xshearTxt.Text)
            k2 = CDbl(yshearTxt.Text)
        Catch ex As Exception
            k1 = 0
            k2 = 0
        End Try


        'Rotation angle in clock wise direction
        Try
            q = (2 * PI / 360) * CDbl(rotTxt.Text)
        Catch
            q = 0
        End Try

        'Coordinates of origin
        ox = CurvePic.Width / 2
        oy = CurvePic.Height / 2

        Try
            acc = 1 / CDbl(SamTxt.Text)
            xscl = CDbl(XzoomTxt.Text)
            yscl = CDbl(YzoomTxt.Text)

        Catch ex As Exception
            acc = 0.01
            xscl = 10
            yscl = 10

        End Try


        For x = -ox / xscl To ox / xscl Step acc

            Application.DoEvents()

            Try
                curvescript.ExecuteStatement("x=" & x)
                curvescript.ExecuteStatement("PI=" & PI)

                y = curvescript.Eval(CurveTxt.Text)

            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try


            posx = CLng(ox + x * xscl)
            posy = CLng(oy - y * yscl)

            rx = x * Cos(q) + y * Sin(q)
            ry = -x * Sin(q) + y * Cos(q)

            sx = x + k1 * y
            sy = y + k2 * x

            rposx = CLng(ox + rx * xscl)
            rposy = CLng(oy - ry * yscl)

            sposx = CLng(ox + sx * xscl)
            sposy = CLng(oy - sy * yscl)

            Try

                graph.DrawRectangle(pen:=Pens.Blue,
                                    x:=posx,
                                    y:=posy,
                                    height:=1,
                                    width:=1)
                graph.DrawRectangle(pen:=Pens.Black,
                                    x:=rposx,
                                    y:=rposy,
                                    height:=1,
                                    width:=1)
                graph.DrawRectangle(pen:=Pens.Red,
                                    x:=sposx,
                                    y:=sposy,
                                    height:=1,
                                    width:=1)


            Catch exp As Exception
                MsgBox(exp.ToString)

            End Try

        Next


    End Sub
End Class


≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡



the desiner.vb of this project is as follows:

≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡


<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class transform
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.DrawBtn = New System.Windows.Forms.Button()
        Me.CurvePic = New System.Windows.Forms.PictureBox()
        Me.rotTxt = New System.Windows.Forms.TextBox()
        Me.yshearTxt = New System.Windows.Forms.TextBox()
        Me.xshearTxt = New System.Windows.Forms.TextBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.CurveTxt = New System.Windows.Forms.TextBox()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.SamTxt = New System.Windows.Forms.TextBox()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.Label7 = New System.Windows.Forms.Label()
        Me.XzoomTxt = New System.Windows.Forms.TextBox()
        Me.YzoomTxt = New System.Windows.Forms.TextBox()
        CType(Me.CurvePic, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'DrawBtn
        '
        Me.DrawBtn.Location = New System.Drawing.Point(12, 422)
        Me.DrawBtn.Name = "DrawBtn"
        Me.DrawBtn.Size = New System.Drawing.Size(143, 29)
        Me.DrawBtn.TabIndex = 0
        Me.DrawBtn.Text = "Draw"
        Me.DrawBtn.UseVisualStyleBackColor = True
        '
        'CurvePic
        '
        Me.CurvePic.Location = New System.Drawing.Point(12, 12)
        Me.CurvePic.Name = "CurvePic"
        Me.CurvePic.Size = New System.Drawing.Size(839, 400)
        Me.CurvePic.TabIndex = 1
        Me.CurvePic.TabStop = False
        '
        'rotTxt
        '
        Me.rotTxt.Location = New System.Drawing.Point(360, 437)
        Me.rotTxt.Name = "rotTxt"
        Me.rotTxt.Size = New System.Drawing.Size(104, 20)
        Me.rotTxt.TabIndex = 2
        Me.rotTxt.Text = "30"
        '
        'yshearTxt
        '
        Me.yshearTxt.Location = New System.Drawing.Point(747, 431)
        Me.yshearTxt.Name = "yshearTxt"
        Me.yshearTxt.Size = New System.Drawing.Size(104, 20)
        Me.yshearTxt.TabIndex = 3
        Me.yshearTxt.Text = ".1"
        '
        'xshearTxt
        '
        Me.xshearTxt.Location = New System.Drawing.Point(561, 434)
        Me.xshearTxt.Name = "xshearTxt"
        Me.xshearTxt.Size = New System.Drawing.Size(104, 20)
        Me.xshearTxt.TabIndex = 4
        Me.xshearTxt.Text = ".1"
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(671, 434)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(70, 13)
        Me.Label1.TabIndex = 5
        Me.Label1.Text = "verticle shear"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(470, 437)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(85, 13)
        Me.Label2.TabIndex = 6
        Me.Label2.Text = "Horizontal Shear"
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(252, 441)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(102, 13)
        Me.Label3.TabIndex = 7
        Me.Label3.Text = "Roatation in Degree"
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(12, 460)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(48, 13)
        Me.Label4.TabIndex = 8
        Me.Label4.Text = "Function"
        '
        'CurveTxt
        '
        Me.CurveTxt.Location = New System.Drawing.Point(63, 457)
        Me.CurveTxt.Name = "CurveTxt"
        Me.CurveTxt.Size = New System.Drawing.Size(147, 20)
        Me.CurveTxt.TabIndex = 9
        Me.CurveTxt.Text = "10*sin(x)"
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.Location = New System.Drawing.Point(252, 464)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(103, 13)
        Me.Label5.TabIndex = 10
        Me.Label5.Text = "Sampling Frequency"
        '
        'SamTxt
        '
        Me.SamTxt.Location = New System.Drawing.Point(360, 464)
        Me.SamTxt.Name = "SamTxt"
        Me.SamTxt.Size = New System.Drawing.Size(104, 20)
        Me.SamTxt.TabIndex = 11
        Me.SamTxt.Text = "100"
        '
        'Label6
        '
        Me.Label6.AutoSize = True
        Me.Label6.Location = New System.Drawing.Point(470, 467)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(84, 13)
        Me.Label6.TabIndex = 15
        Me.Label6.Text = "Horizontal Zoom"
        '
        'Label7
        '
        Me.Label7.AutoSize = True
        Me.Label7.Location = New System.Drawing.Point(671, 464)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(72, 13)
        Me.Label7.TabIndex = 14
        Me.Label7.Text = "Verticle Zoom"
        '
        'XzoomTxt
        '
        Me.XzoomTxt.Location = New System.Drawing.Point(561, 464)
        Me.XzoomTxt.Name = "XzoomTxt"
        Me.XzoomTxt.Size = New System.Drawing.Size(104, 20)
        Me.XzoomTxt.TabIndex = 13
        Me.XzoomTxt.Text = "10"
        '
        'YzoomTxt
        '
        Me.YzoomTxt.Location = New System.Drawing.Point(747, 461)
        Me.YzoomTxt.Name = "YzoomTxt"
        Me.YzoomTxt.Size = New System.Drawing.Size(104, 20)
        Me.YzoomTxt.TabIndex = 12
        Me.YzoomTxt.Text = "10"
        '
        'transform
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(873, 513)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.Label7)
        Me.Controls.Add(Me.XzoomTxt)
        Me.Controls.Add(Me.YzoomTxt)
        Me.Controls.Add(Me.SamTxt)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.CurveTxt)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.xshearTxt)
        Me.Controls.Add(Me.yshearTxt)
        Me.Controls.Add(Me.rotTxt)
        Me.Controls.Add(Me.CurvePic)
        Me.Controls.Add(Me.DrawBtn)
        Me.Name = "transform"
        Me.Text = "Transform"
        CType(Me.CurvePic, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents DrawBtn As System.Windows.Forms.Button
    Friend WithEvents CurvePic As System.Windows.Forms.PictureBox
    Friend WithEvents rotTxt As System.Windows.Forms.TextBox
    Friend WithEvents yshearTxt As System.Windows.Forms.TextBox
    Friend WithEvents xshearTxt As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents CurveTxt As System.Windows.Forms.TextBox
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents SamTxt As System.Windows.Forms.TextBox
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents XzoomTxt As System.Windows.Forms.TextBox
    Friend WithEvents YzoomTxt As System.Windows.Forms.TextBox

End Class



≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

2 comments:

  1. I believe there is no frame-dragging effect of gravity on mass, only on electromagnetic energy!
    Curiously, the Lense-Thirring effect in Gravity Probe B has the same value than the geodetic effect of the Earth around the Sun.
    NASA error?
    An interesting experiment!
    Understanding Gravity Probe-B experiment without math
    http://www.molwick.com/en/gravitation/082-gravity-probe-b.html
    http://www.molwick.com/en/gravitation/r-lense-thirring-frame-dragging.jpg

    ReplyDelete
  2. This comment aimed to another post.

    ReplyDelete

If the contents is insufficient or if there any error, please write here....


Suggestion are welcome:

Popular Posts