Function plotting(3D)

2019年03月23日

首頁

 

 

3-D Function plotting

Three dimensional (3-D) computer graphics are graphics render that using a 3-D representation of geometric data that is stored in computer for the purposes of performing graphic calculations and rendering 2D images.3-D computer graphics algorithms rely on many of the same algorithms as 2D computer vector graphics of wire-frame model and 2D computer raster graphics in the final rendered display. In computer graphics software, the distinction between 2D and 3-D is occasionally blurred. 2D applications may use 3-D techniques to achieve effects such as lighting, and primarily 3-D may use 2D rendering techniques. A 3-D model is a mathematical representation of any 3-D object. A 3-D model can be rendered visually as a 2D image by means of a 3-D rendering process, or used in non-graphical computer simulations and calculations. In this article, we will focus on the 3-D function graphic plotting not concerned with the mathematical elements such as 3-D transformation, if readers are interest the mathematical material, please refer “Visual graphics programming( Rod Stephens) “ or writer’s another publication “Projection and transformation matrix(www.chday169.url.tw)”.

 

(a) Coordinate system in world and eye system.

 

To represent a point in 3-D space, we need a 3-D mutually perpendicular axes coordinate system (rectangular coordinate system). The 3-D coordinate can be derived from 2d coordinate system (xy plane) by adding another augment z through the origin as z axis, resulting two additional planes (yz and xz plane). Two orientations are possible when elect to z axis. If the z axis points toward the view’s eye, the associate system is referred to as right-hand system. Similarly, a coordinate system with the z axis pointing away from the viewer is called the left-hand system. Which system you choose is no matter, but you’ll coincidence with your projection system. If your data is created by a non-rectangular coordinate system, you may convert this data to the rectangular coordinate system first.

 

(b) Data creating and structure Type(VB 6)

 

    The 3-D graphic algorithm discussing here can be applied by any mathematical functions (z function(z=f(x,y), parametric function(x=f(u,v),y=g(u,v),z=h(u,v)

,implicit function( f(x,y,z)=c) or surface generating of profile rotation, extrusion, transformation ,tube function, etc., or scatter data. For convention, the point data Type can be declared as:

 

VB 6.0

Public PointApi ‘same as ‘Point’ of VB.Net

   X as Long  

   Y as Long

End Type

Public Type PtXy  ‘same as ‘PointF’ of VB.Net

    x As Single

    y As Single

 End Type

 

Public Type PtXyz  ‘same as ‘Public Structure’ of VB.Net

    x As Single ‘same as ‘Dim x as single’ of VB.Net

    y As Single

    z As Single

End Type          ‘same as ‘End Structure’

 

Public Type Point3-D

    Coord(0 to 3) As Single

    Trans(0 to 3) As Single

    PrjBotm(0 to 2) As single ‘bottom view projection

PrjBack(0 to 2) As single ‘back view projection

PrjSide(0 to 2) as single ‘side view projection

 End Type

 

(c)Transformation matrix (VB 6 and VB.NeT)

 

As a matter of convention, we will use the rectangular coordinate to represent

the position of a point or a point vector. We can use the generalized 4*4 transformation matrix for a point in 3-D homogeneous coordinate system. In 3-D computer graphics, the transformation matrix may include such as translation, shearing, scaling, rotation and reflection, etc. You can find the detail transformation operation processers in many textbook or link www.chday169.url.tw to get more information, so we don’t intend to discuss here. Hereafter, we list some useful snippet codes of function or sub to get transformation matrix coefficients.

 

Public Sub CreateTransFormationMatrix(ByVal ViewTypeIn As Integer)

        Select Case ViewTypeIn

            Case 1

                CalTransformationMatrixA()

            Case 2

                CalTransformationMatrixB()

 

        End Select

 

    End Sub

  

    'Calculate the transformation matrix.

    ' ********************************************************

    Private Sub CalTransformationMatrixA() 'get glAx,glAy,glAz,-----------------

        'MsgBox ("eyexin=" & EyeXIn)

        Dim T1(3, 3) As Single

        Dim T2(3, 3) As Single

        Dim r1 As Single

        Dim r2 As Single

        Dim ctheta As Single

        Dim stheta As Single

        Dim cphi As Single

        Dim sphi As Single

 

        ' Rotate around the Z axis so the  'z軸旋轉,觀測者眼睛在Y-Z 平面

        ' eye lies in the Y-Z plane.

        r1 = System.Math.Sqrt(EyeX * EyeX + EyeY * EyeY)

        stheta = EyeX / r1 's(theta)

        ctheta = EyeY / r1 'cos(theta)

        MakeIdentity(T1)

        T1(0, 0) = ctheta

        T1(0, 1) = stheta

        T1(1, 0) = -stheta

        T1(1, 1) = ctheta

 

        ' Rotate around the X axis so the 'x軸旋轉,觀測者眼睛在Z軸上

        ' eye lies  the Z axis.

        r2 = System.Math.Sqrt(EyeX * EyeX + EyeY * EyeY + EyeZ * EyeZ)

        sphi = -r1 / r2 'sin(phi)

        cphi = -EyeZ / r2 'cos(phi)

        MakeIdentity(T2)

        T2(1, 1) = cphi

        T2(1, 2) = sphi

        T2(2, 1) = -sphi

        T2(2, 2) = cphi

        ' here. We just ignore the Z coordinate when drawing.)

 

        ' Combine the transformations.

        MatrixMatrixMult(T, T1, T2)

        glAx = T(0, 0)

        glAy = T(1, 0)

        glAz = T(2, 0)

        glBx = T(0, 1)

        glBy = T(1, 1)

        glBz = T(2, 1)

        glCx = T(0, 2)

        glCy = T(1, 2)

        glCz = T(2, 2)

       

    End Sub

    ' ********************************************************

    ' Calculate the transformation matrix.

    ' ********************************************************

    Private Sub CalTransformationMatrixB() 'get glAx,glAy,glAz,-----------------

        'MsgBox("into CalTransformationMatrixB" & " m3Perspective= " & m3Perspective & "; focusx= " & FocusX)

        Dim T(0 To 3, 0 To 3) As Single

        m3PProject(T, m3Perspective, eyeR, eyePhi, eyetheta, FocusX, FocusY,  FocusZ, 0, 1, 0)

        FactorMaker(T)

      

    End Sub

 

Public Sub IsomPrjMaker()

        Dim i As Integer, j As Integer, tIso(0 To 3, 0 To 3) As Single

        Dim Phi As Single, Theta As Single

        Phi = 45 * Ra

        Theta = 35.26439 * Ra

        Erase tIso()

        For i = 0 To 3

          For j = 0 To 3

             tIso(i, j) = 0

          Next j

        Next i

        tIso(0, 0) = Cos(Phi)

        tIso(0, 1) = Sin(Phi) * Sin(Theta)

        tIso(0, 2) = -Sin(Phi) * Cos(Theta)

       

        tIso(1, 0) = 0#

        tIso(1, 1) = Cos(Theta)

        tIso(1, 2) = Sin(Theta)

       

        tIso(2, 0) = Sin(Phi)

        tIso(2, 1) = -Cos(Phi) * Sin(Theta)

        tIso(2, 2) = Cos(Phi) * Cos(Theta)

       

        tIso(3, 3) = 1#

        glAxIso = tIso(0, 0)

        glAyIso = tIso(1, 0)

        glAzIso = tIso(2, 0)

        glBxIso = tIso(0, 1)

        glByIso = tIso(1, 1)

        glBzIso = tIso(2, 1)

        glCxIso = tIso(0, 2)

        glCyIso = tIso(1, 2)

        glCzIso = tIso(2, 2)              

        End Sub

 

Public Sub DimetricPrjMaker()

        Dim i As Integer, j As Integer, tDim(0 To 3, 0 To 3) As Single

        Dim Phi As Single, Theta As Single

        Phi = 22.208 * Ra

        Theta = 20.705 * Ra

        Erase tDim()

        For i = 0 To 3

          For j = 0 To 3

             tDim(i, j) = 0

          Next j

        Next i

        tDim(0, 0) = Cos(Phi)

        tDim(0, 1) = Sin(Phi) * Sin(Theta)

        tDim(0, 2) = -Sin(Phi) * Cos(Theta)       

        tDim(1, 0) = 0#

        tDim(1, 1) = Cos(Theta)

        tDim(1, 2) = Sin(Theta)       

        tDim(2, 0) = Sin(Phi)

        tDim(2, 1) = -Cos(Phi) * Sin(Theta)

        tDim(2, 2) = Cos(Phi) * Cos(Theta)       

        tDim(3, 3) = 1#

        glAxDim = tDim(0, 0)

        glAyDim = tDim(1, 0)

        glAzDim = tDim(2, 0)

        glBxDim = tDim(0, 1)

        glByDim = tDim(1, 1)

        glBzDim = tDim(2, 1)

        glCxDim = tDim(0, 2)

        glCyDim = tDim(1, 2)

        glCzDim = tDim(2, 2)

        End Sub

 

Public Function CabinetPrjMaker(Alph As Single)

 

 Dim Sx As Single, Sy As Single, Sz As Single

 Sx = 1

 Sy = 1

 Sz = 0.5

 Alph = Alph * Ra

    glAxCab = Sx

    glAyCab = 0

    glAzCab = Sz * Cos(Alph)

    glBxCab = 0

    glByCab = Sy

    glBzCab = Sz * Sin(Alph)

    glCxCab = 0

    glCyCab = 0

    glCzCab = 1

 End Function

 

Public Function CavalierPrjMaker(Alph As Single)

 Dim Sx As Single, Sy As Single, Sz As Single

 Sx = 0.5

 Sy = 0.5

 Sz = 1

Alph = Alph * Ra

    glAxCav = Sx

    glAyCav = 0 '-Sy * Cos(Beta)

    glAzCav = Sz * Cos(Alph)

    glBxCav = 0

    glByCav = Sy 'Sy * Sin(Beta)

    glBzCav = Sz * Sin(Alph)

    glCxCav = 0

    glCyCav = 0

    glCzCav = 1

 

    End Function

Public Function EqualAnglePrjMaker(z As Single)

glAxEang = 1 / (1 + z)

glAyEang = 0

glAzEang = 0

glBxEang = 1 / (1 + z)

glByEang = 0

glBzEang = 0

End Function

 

Public Function EqualAreaPrjMaker(z As Single)

glAxEang = 1 / Sqr(1 + z)

glAyEang = 0

glAzEang = 0

glBxEang = 1 / Sqr(1 + z)

glByEang = 0

glBzEang = 0

End Function

 

To get the projection point(xp,yp) of projection of 3-D point(x,y,z), you can apply the formulas as following:

 

(a) Trimetric projection

xp=glAx*x+glAy*y+glAz*z

yp=glBx*x+glBy*y+glBz*z

zp=glCx*x+glCy*y+glCz*z

 

    (b) Isometric projection

xp=glAxIso*x+glAyIso*y+glAzIso*z

yp=glBxIso*x+glByIso*y+glBzIso*z

 

(c) Cabinet projection

 xp=glAxCab*x+glAyCab*y+glAzCab*z

yp=glBxCab*x+glByCab*y+glBzCab*z

 

The data of projection point(xp,yp) can be used to draw on VB 6PictureBox with ScaleMode = Vbuser , for Win32 Api or VB.net ,you need to convert the floating data type to Api or VB Net long data Type.  

 

(d)Conversion between user scale and pixel scale

 

The size of left and top Form of PictureBox of VB 6.0 can be set as negative, so    the function z=x^2+y^2, (-5>= x>=5, -5>= y>=5), the z values vary from -50 to 50),  if (xp,yp) values are negative after transformation, we can draw the graph by setting the canvas scale as canvas.Scale(-50,50)-(50,-50), while in Api or VB.Net you can use the following sub or function to convert the function values to coincide with the graphic devices.

   

Public Function ptConvertToUser(ByVal canvas As PictureBox, ByVal xLeft As Single, ByVal xRight As Single, ByVal yTop As Single, ByVal yBottom As Single, _

     ByVal xPix As Integer, ByVal yPix As Integer) As PointF ‘for VB,Net

        ptConvertToUser.X = CSng(xRight - xLeft) / CSng(canvas.ClientSize.Width) * xPix + xLeft

        ptConvertToUser.Y = CSng(yBottom - yTop) / CSng(canvas.ClientSize.Height) * yPix + yTop

    End Function

 

    Public Function ptConvertToPix(ByVal canvas As PictureBox, ByVal xLeft As Double, ByVal xRight As Double, ByVal yTop As Double, ByVal yBottom As Double, _

     ByVal xUser As Single, ByVal yUser As Single) As PointF

        ptConvertToPix.X = xUser * CSng(canvas.ClientSize.Width) / (xRight - xLeft) - xLeft * CSng(canvas.ClientSize.Width) / (xRight - xLeft)

        ptConvertToPix.Y = yUser * CSng(canvas.ClientSize.Height) / (yBottom - yTop) - yTop * CSng(canvas.ClientSize.Height) / (yBottom - yTop)

    End Function

 

    Public Function ptConvertToUser(ByVal canvas As PictureBox, ByVal xLeft As Single, ByVal xRight As Single, ByVal yTop As Single, ByVal yBottom As Single, _

        ByVal ptPix As Point) As PointF

        ptConvertToUser.X = CSng(xRight - xLeft) / CSng(canvas.ClientSize.Width) * ptPix.X + xLeft

        ptConvertToUser.Y = CSng(yBottom - yTop) / CSng(canvas.ClientSize.Height) * ptPix.Y + yTop

    End Function

 

    Public Function ptConvertToPix(ByVal canvas As PictureBox, ByVal xLeft As Double, ByVal xRight As Double, ByVal yTop As Double, ByVal yBottom As Double,ByVal PtUser As PointF) As Point

        ptConvertToPix.X = PtUser.X * CSng(canvas.ClientSize.Width) / (xRight - xLeft) - xLeft * CSng(canvas.ClientSize.Width) / (xRight - xLeft)

        ptConvertToPix.Y = PtUser.Y * CSng(canvas.ClientSize.Height) / (yBottom - yTop) - yTop * CSng(canvas.ClientSize.Height) / (yBottom - yTop)

    End Function

 

    Please note here, “ByVal xPix As Integer, ByVal yPix As Integer” should change to ByVal xPix As Long, ByVal yPix As long” ,”Point” change to “pointAPI”, “PointF” tO “PtXy” for VB 6.

  

 

(e)Drawing of 3-D graph(VB 6.0)

 

Private Sub Function3-DValues()

 ' Initialize the data points.

 Dim i As Integer, j As Integer

 Dim xU As Single, yV As Single, zW As Single, ans As Variant

Erase T, Points

 ReDim T(0 To 3, 0 To 3) As Single

 ReDim Preserve Points(0 To NdoXU, 0 To NdoYV)

 zBotmBase = 99999

 xBotmBase = 99999

 yBotmBase = 99999

 zTopBase = -99999

 xTopBase = -99999

 yTopBase = -99999

   Select Case functionType

   Case "contour3-D"

            dxU = (V1Domn2 - V1Domn1) / NdoXU

            dyV = (V2Domn2 - V2Domn1) / NdoYV

            For i = 0 To NdoXU

                xU = V1Domn1 + i * dxU

                For j = 0 To NdoYV

                     yV = V2Domn1 + j * dyV                    

                    Points(i, j).Coord(0) = xU ' Sin(x)

                    Points(i, j).Coord(1) = yV ' Cos(y)

                    Points(i, j).Coord(2) = FunctionZValFromXY(glVbScriptA, ZEq, CDbl(xU), CDbl(yV)) 'ans

                    Points(i, j).Coord(3) = 1#

                    If i = 0 And (j = 0 Or j = NdoYV) Then

                   If Points(i, j).Coord(0) > xTopBase Then xTopBase = Points(i, j).Coord(0)

                   If Points(i, j).Coord(1) > yTopBase Then yTopBase = Points(i, j).Coord(1)

                   If Points(i, j).Coord(2) > zTopBase Then zTopBase = Points(i, j).Coord(2)

                   If Points(i, j).Coord(0) < xBotmBase Then xBotmBase = Points(i, j).Coord(0)

                   If Points(i, j).Coord(1) < yBotmBase Then yBotmBase = Points(i, j).Coord(1)

                   If Points(i, j).Coord(2) < zBotmBase Then zBotmBase = Points(i, j).Coord(2)

                Next j

            Next i

    Case "parameter3-D"

          .

          .

          .

          End Select

          ‘modify the values of function

           Dim TptXY As Single, tptZ As Single

                 TptXY = DMAX1(Abs(xTopBase), Abs(xBotmBase), Abs(yTopBase), Abs(yBotmBase))

                 tptZ = DMAX1(Abs(zTopBase), Abs(zBotmBase))

                  If TptXY >= 0.001 Then ratioXY = 10# / TptXY

                   If tptZ >= 0.001 Then ratioZ = 10# / tptZ                

                  For i = 0 To NdoXU

                       For j = 0 To NdoYV

                        With Points(i, j)

                        .Coord(0) = .Coord(0) * ratioXY

                        .Coord(1) = .Coord(1) * ratioXY

                        .Coord(2) = .Coord(2) * ratioZ

                        End With

                       Next j

                 Next i

                  xTopBase = xTopBase * ratioXY

          yTopBase = yTopBase * ratioXY

          zTopBase = zTopBase * ratioZ

          xBotmBase = xBotmBase * ratioXY

          yBotmBase = yBotmBase * ratioXY

          zBotmBase = zBotmBase * ratioZ

     zBotmBase = zBotmBase - 2.5

     yBotmBase = yBotmBase - 2.5

     xBotmBase = xBotmBase - 2.5

     zTopBase = zTopBase + 2.5

     yTopBase = yTopBase + 2.5

     xTopBase = xTopBase + 2.5

   

    pt3-DCen.Coord(0) = (xTopBase + xBotmBase) / 2

    pt3-DCen.Coord(1) = (yTopBase + yBotmBase) / 2

    pt3-DCen.Coord(2) = (zTopBase + zBotmBase) / 2

    End Sub

 

Private Sub Function3-DPrj()

 Dim i As Integer, j As Integer

 Dim x As Single, y As Single, ans As Variant, Z As Single

 Dim stEq As String

    'case 3-D view

    lcXPrjMin = 99999

    lcXPrjMax = -99999

    lcYPrjMin = 99999

    lcYPrjMax = -99999

    lcZPrjMin = 99999

    lcZPrjMax = -99999

    For i = 0 To NdoXU

         For j = 0 To NdoYV

             Points(i, j).Trans(0) = glAx * Points(i, j).Coord(0) + glAy * Points(i, j).Coord(1) + glAz * Points(i, j).Coord(2)

             Points(i, j).Trans(1) = glBx * Points(i, j).Coord(0) + glBy * Points(i, j).Coord(1) + glBz * Points(i, j).Coord(2)

             Points(i, j).Trans(2) = glCx * Points(i, j).Coord(0) + glCy * Points(i, j).Coord(1) + glCz * Points(i, j).Coord(2)

             If i = 0 And (j = 0 Or j = NdoYV) Then FrmDocument.List1.AddItem (i & " ; " & j & " ; " & Points(i, j).Coord(0) & " ; " & Points(i, j).Coord(1) & "; " & Points(i, j).Coord(2))

             If i = 0 And (j = 0 Or j = NdoYV) Then FrmDocument.List1.AddItem (i & " ; " & j & " ; " & Points(i, j).Trans(0) & " ; " & Points(i, j).Trans(1) & "; " & Points(i, j).Trans(2))

             If Points(i, j).Trans(0) >= lcXPrjMax Then lcXPrjMax = Points(i, j).Trans(0)

             If Points(i, j).Trans(1) >= lcYPrjMax Then lcYPrjMax = Points(i, j).Trans(1)

             If Points(i, j).Trans(2) >= lcZPrjMax Then lcZPrjMax = Points(i, j).Trans(2)

             If Points(i, j).Trans(0) < lcXPrjMin Then lcXPrjMin = Points(i, j).Trans(0)

             If Points(i, j).Trans(1) < lcYPrjMin Then lcYPrjMin = Points(i, j).Trans(1)

             If Points(i, j).Trans(2) < lcYPrjMin Then lcZPrjMin = Points(i, j).Trans(2)

        Next j

    Next i

     xPrjMin3-DV = lcXPrjMin

     yPrjMin3-DV = lcYPrjMin

     zPrjMin3-DV = lcZPrjMin

     xPrjMax3-DV = lcXPrjMax

     yPrjMax3-DV = lcYPrjMax

     zPrjMax3-DV = lcZPrjMax

     '------------------------------------------

     pt3-DCen.Trans(0) = glAx * pt3-DCen.Coord(0) + glAy * pt3-DCen.Coord(1) + glAz * pt3-DCen.Coord(2)

     pt3-DCen.Trans(1) = glBx * pt3-DCen.Coord(0) + glBy * pt3-DCen.Coord(1) + glBz * pt3-DCen.Coord(2)

    ' case  Botm

    ‘

    ‘

    ‘

   

    ' case back

    ‘

    ‘

    ‘

    ' case Side

    ‘

    ‘

    ‘

   

     canvas_Xmin = DMIN1(CDbl(xPrjMin3-DV), CDbl(xPrjMinBotm), CDbl(xPrjMinSide), CDbl(xPrjMinBack))

     canvas_Xmax = DMAX1(CDbl(xPrjMax3-DV), CDbl(xPrjMaxBotm), CDbl(xPrjMaxSide), CDbl(xPrjMaxBack))

     canvas_Ymin = DMIN1(CDbl(yPrjMin3-DV), CDbl(yPrjMinBotm), CDbl(yPrjMinSide), CDbl(yPrjMinBack))

     canvas_Ymax = DMAX1(CDbl(yPrjMax3-DV), CDbl(yPrjMaxBotm), CDbl(yPrjMaxSide), CDbl(yPrjMaxBack))

End Sub

 

 

Sub SurfaceDraw(DrwTypeIn As String, Optional LineColor As Long = -1)

   ReDim Preserve T(0 To 3, 0 To 3)

   Picture1.Cls

   Picture2.Cls

    isDrawing = True

    ' Calculate the transformation matrix.

   CreateTransFormationMatrix ViewType

 

' Split the equation from listbox

Equation_Split

'Calculate the value of function

Function3-DValues

'Calculte the projection value of 3-D points

Function3-DPrj

canvas_Xmin = xPrjMin3-DV - 15

canvas_Xmax = xPrjMax3-DV + 15

canvas_Ymin = yPrjMin3-DV - 15

canvas_Ymax = yPrjMax3-DV + 15

 

xLeft = Round(canvas_Xmin + 0.5, 0)

xRight = Round(canvas_Xmax + 0.5, 0)

yTop = Round(canvas_Ymax + 0.5, 0)

yBottom = Round(canvas_Xmin + 0.5, 0)

Picture1.Scale (xLeft, yTop)-(xRight, yBottom) '(canvas_Xmin, canvas_Ymax)-(canvas_Xmax, canvas_Ymin)

Picture2.Scale (xLeft, yTop)-(xRight, yBottom) '(canvas_Xmin, canvas_Ymax)-(canvas_Xmax, canvas_Ymin)

'Plot the x,y,z axels\

.

.

.

'--------------------------------------------------

  Dim i As Integer, j As Integer

  Dim ptTpt As Point2D, ptsPrj() As PointAPI, ptTptApi As PointAPI, ptsPrjB() As PointAPI

   Dim LineColors(0 To 3) As Long

Select Case LCase(DrawType)

Case "mesh"

If LineColor = -1 Then

    LineColors(0) = vbBlue

    LineColors(1) = vbCyan

    LineColors(2) = vbGreen

    LineColors(3) = vbMagenta

End If

 

If LineColor = -1 Then

  Picture1.ForeColor = LineColors(0)

  Picture2.ForeColor = LineColors(0)

  Else

  Picture1.ForeColor = LineColor

   Picture2.ForeColor = LineColor

  End If

Case "face"

     Picture1.DrawStyle = vbSolid

     Picture1.FillStyle = vbFSSolid

     Picture2.DrawStyle = vbSolid

     Picture2.FillStyle = vbFSSolid

     'setting of color(顏色設定)

              Dim tptV0 As Single, tptV1 As Single, tptV2 As Single

             Dim tpt1(0 To 2) As Single

              Dim rgb_R As Byte, rgb_G As Byte, rgb_B As Byte

                            tpt1(0) = (xTopBase - xBotmBase)

                            tpt1(1) = (yTopBase - yBotmBase)

                            tpt1(2) = (zTopBase - zBotmBase)

                            For i = 0 To 2

                            If Abs(tpt1(i)) < 0.01 And tpt1(i) <= 0.01 Then tpt1(i) = -0.01

                            If Abs(tpt1(i)) < 0.01 And tpt1(i) > 0.01 Then tpt1(i) = 0.01

                             If Abs(tpt1(i)) < 0.01 And tpt1(i) = 0# Then tpt1(i) = 0.01

                            Next i

                           

              For i = 0 To NdoXU

              For j = 0 To NdoYV

              With Points(i, j)

                            Select Case LCase(fillColorType)

                            Case "rgb", "pattern"

                            tptV0 = .Coord(0) * PI / tpt1(0)

                            tptV1 = .Coord(1) * PI / tpt1(1)

                            tptV2 = .Coord(2) * PI / tpt1(2)

                            rgb_R = CInt((Sin(tptV0) + 1) * 255 * 0.5)

                            rgb_G = CInt((Cos(tptV1) + 1) * 255 * 0.5)

                            rgb_B = CInt((Cos(tptV2) + 1) * 255 * 0.5)

                            If rgb_R >= 255 Then rgb_R = 255

                            If rgb_G >= 255 Then rgb_G = 255

                            If rgb_B >= 255 Then rgb_B = 255

                            If rgb_R < 0 Then rgb_R = 0

                            If rgb_G < 0 Then rgb_G = 0

                            If rgb_B < 0 Then rgb_B = 0

                            .ptRGBcol = RGB(rgb_R, rgb_G, rgb_B)

                          Case "transparent"

                            .ptRGBcol = colorBack                      

                         Case "color"

                         .ptRGBcol = FillColor

                   End Select

               End With

               Next j

               Next i 

    Dim PtsAPI() As PointAPI, ptsAPIB() As PointAPI

    Dim ptsRect(0 To 3) As PointAPI, ptsRectB(0 To 3) As PointAPI

   

  ' Select Case LCase(TypeStr)

     'Case "side"

     .

     .

     .

     ' Case "back"

     .

     .

     .               

     ‘Case "bottom", "botm"               

     .

.

.             

     'Case "3-D", "3-Dview"

                   Erase PtsAPI, ptsAPIB

                    ReDim Preserve PtsAPI(0 To NdoXU, 0 To NdoYV), ptsAPIB(0 To NdoXU, 0 To NdoYV)

                  For i = 0 To NdoXU

                   For j = 0 To NdoYV

                            ptTpt.x = Points(i, j).Trans(0)

                            ptTpt.y = Points(i, j).Trans(1)

                            PtsAPI(i, j) = PtConvertToPix(Picture1, ptTpt)

                            ptsAPIB(i, j) = PtConvertToPix(Picture2, ptTpt)

                    Next j

                    Next i              

                  For i = 0 To NdoXU - 1

                   For j = 0 To NdoYV - 1

                            ptsRect(0) = PtsAPI(i, j)

                            ptsRect(1) = PtsAPI(i, j + 1)

                            ptsRect(2) = PtsAPI(i + 1, j + 1)

                            ptsRect(3) = PtsAPI(i + 1, j)

                            ptsRectB(0) = ptsAPIB(i, j)

                            ptsRectB(1) = ptsAPIB(i, j + 1)

                            ptsRectB(2) = ptsAPIB(i + 1, j + 1)

                            ptsRectB(3) = ptsAPIB(i + 1, j)

                            Picture1.FillColor = Points(i, j).ptRGBcol

                            Picture2.FillColor = Points(i, j).ptRGBcol

                             If LCase(fillColorType) = "pattern" Then

                             Dim mRgn As Long, mRgnB As Long

                              mRgn = CreatePolygonRgn(ptsRect(0), 4, 1)

                              mRgnB = CreatePolygonRgn(ptsRectB(0), 4, 1)

                               Call FillRgn(Picture1.hdc, mRgn, glPatternBrush)

                               Call FillRgn(Picture2.hdc, mRgnB, glPatternBrush)

                               Picture1.ForeColor = vbMagenta

                               Picture2.ForeColor = vbMagenta

                                'DrawMesh Picture2, "3-D"

                               Else

                               Polygon Picture1.hdc, ptsRect(0), 4

                               Polygon Picture2.hdc, ptsRectB(0), 4

                               End If

                    Next j

                    Next i

                      If LCase(fillColorType) = "pattern" Then

                      Picture1.ForeColor = vbMagenta

                      Picture2.ForeColor = vbMagenta

                     DrawMesh Picture1, "3-D", vbMagenta

                     DrawMesh Picture2, "3-D", vbMagenta

                    End If

            End Select

          End Sub

 

For more information, please link “chday169.url.tw”

http://vlog.xuite.net/play/MmhYbWNzLTgzOTQ1MTIuZmx2

ContourPlot_0001 @ 隨意窩 Xuite 影音

Name(您的大名)
E_MAIL(您的電子信箱)
Comment or Suggestion(您想反應的狀況,建議,或諮詢事項)
首頁


 

 

 

 

首頁 | Function plotting(3D) | Rotation/reflection(3D) | Projection/Transformation(3D) | Contour plotting(3d) | tube plotting(3D) | VB NET座標系統簡介 | Joint line segments

上次修改此網站的日期: 2018年12月02日