Click here to Skip to main content
15,896,348 members
Articles / Programming Languages / Visual Basic

Mathemathics Framework

Rate me:
Please Sign up or sign in to vote.
4.76/5 (56 votes)
16 Sep 2008CPOL6 min read 75.5K   6.2K   171  
.NET Mathematical Framework
Imports System.Math
Imports System.Drawing
Imports System.Windows.Forms
Imports Basics
Imports GraphicsObjects



Public Class GraphicsDerivadeTool
    Inherits GraphicsToolWVisor

    Protected intEnableDer As Boolean
    Private GMCls As GraphicMathCls
    Private MathDeleg As BVMathDelegate
    Private x, y As Single
    Private P1, P2 As PointF
    Dim pend As Single

#Region "Constructor"

    Public Sub New(ByVal Visor2D As IVisorBase, ByVal CalcObj As Object)
        MyBase.New(Visor2D)

        'objVisor2D = Visor2D
        GMCls = New GraphicMathCls(objVisor2D)
        If TypeOf CalcObj Is ICalcS Then
            MathDeleg = New BVMathDelegate(CType(CalcObj, ICalcS))
        ElseIf TypeOf CalcObj Is ICalcSC Then
            MathDeleg = New BVMathDelegate(CType(CalcObj, ICalcSC))
        Else
            Throw New Exception("Invalid CalcObject")
        End If

        'AddHandler objVisor2D.MouseDown, AddressOf OnRenderControl_MouseDown
        'AddHandler objVisor2D.MouseUp, AddressOf OnRenderControl_MouseUp
        'AddHandler objVisor2D.MouseMove, AddressOf OnRenderControl_MouseMove

    End Sub

    'Public Sub Dispose()
    '    RemoveHandler objVisor2D.MouseDown, AddressOf OnRenderControl_MouseDown
    '    RemoveHandler objVisor2D.MouseUp, AddressOf OnRenderControl_MouseUp
    '    RemoveHandler objVisor2D.MouseMove, AddressOf OnRenderControl_MouseMove

    'End Sub


#End Region

#Region "Properties"

    Public Property EnableDer() As Boolean
        Get
            Return intEnableDer
        End Get
        Set(ByVal Value As Boolean)
            intEnableDer = Value
        End Set
    End Property

#End Region

#Region "Methods"

    Protected Overrides Sub OnRenderControl_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
        Draw(sender, e)
    End Sub

    Protected Overrides Sub OnRenderControl_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) 'Handles objVisor2D.OnRenderControlMouseUp
        Draw(sender, e)
    End Sub

    Protected Sub Draw(ByVal sender As Object, ByVal e As MouseEventArgs)
        If EnableDer Then
            If e.Button = MouseButtons.Left OrElse e.Button = MouseButtons.Right Then

                pend = MathDeleg.DerivadeDelegate(objVisor2D.Cursor1Position.X, 0.0001)
                y = MathDeleg.CalcDelegate(objVisor2D.Cursor1Position.X)
                x = objVisor2D.Cursor1Position.X
                Me.GMCls.GetTangentCoordinates(x, y, pend, P1, P2)
                Me.objVisor2D.Refresh(Me)
                'GMCls.DrawTangent(
            End If
        End If
    End Sub

    Protected Overrides Sub OnRenderControl_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) 'Handles objVisor2D.OnRenderControlMouseMove
        Draw(sender, e)
    End Sub

#End Region

    Public Overrides Sub Redraw(ByVal sender As Object, ByVal p As PaintEventArgs)
        If intEnableDer Then
            p.Graphics.DrawLine(Me.intGraphics.Pen, P1, P2)
            'GMCls.DrawTangent(p.Graphics, x, y, pend, False)
        End If
    End Sub


End Class


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer Universidad Tecnológica Nacional
Argentina Argentina
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions