Results 1 to 10 of 11

Thread: searching for Curves and Surfaces in the space

Threaded View

  1. #1

    searching for Curves and Surfaces in the space

    suppose someone tell you to plot this equation
    Pow(x,4) + Pow(y,4) + Pow(z,4) - Pow(x*x + y*y + z*z,2) + 3 * (x*x + y*y + z*z) = 0
    and you don't have any clue how to solve it first such as saying:
    z = f(x,y) , so how to plot it ?
    there is a plan: is to search the points in space one by one in which this equation is approximately true such as:
    If k <= 0.1 And k >= -0.1 Then ...
    k is the value of the equation.
    change it to:
    If k <= 0.5 And k >= -0.5 Then
    and you get a thicker surface curve with more points.

    now if we tried the above equation but replacing Pow to '^' (uncomment line 178 ) then the time is twice than if use Pow. this is not important issue since we can use the speedier version.
    try equation in line 175:
    k = Sin(x*y)+Sin(y*z)+Sin(z*x)
    it is ineresting
    in line 217 : TBGL_PointSize 2 : make it 1 or 3 as necessary
    change the range in line 162 as the plotting needed
    this is an experimental mathematics
    i have used the Entity System to position and rotate and look at using Entity system examples by Petr ,2009
    also using Oxygen module to speed the calculations
    you may wait from 6 to 30 seconds for every graphics since we check every point in the space within the range.
    Click image for larger version. 

Name:	surface.JPG 
Views:	6 
Size:	26.6 KB 
ID:	9743Click image for larger version. 

Name:	surface1.JPG 
Views:	9 
Size:	19.8 KB 
ID:	9744
    'Experimental Mathematics                             =
    '===============================================================================
    
    Uses "TBGL" , "Math" , "Oxygen"
    #Include Once "%APP_INCLUDEPATH%\thinbasic_gl.inc"
    #Include Once "%APP_INCLUDEPATH%\thinbasic_glu.inc" 
    
    BEGIN CONST
      ' -- Scene IDs
      %sScene  = 1
     
      ' -- Entity IDs 
      %eCamera = 1
      
      %eContour       
      %eLight
      %texOne
      %lMyPoints       
    End Const
    
    Type Point3D
      x As Single
      y As Single
      z As Single
      red As Single
      green As Single
      blue As Single
      tu As Single
      tv As Single
    End Type
       
    Global Nb As DWord = 2000000 '401880 '8120601
    Global x, y, z,zz As Single
    Global FrameRate As Long
    Global Vertex(Nb) As Point3D ' single
    Global total As Long 
    'Global ColorA(Nb)  As TBGL_TRGB      ' Byte
      
    
    FUNCTION TBMAIN()
      LOCAL hWnd As DWORD
      Global FrameRate As Double
      Global ang, earthX, earthZ, OrbitRadius As Single
      Global flag, mask As Long
      flag = 1 : mask = 1
      OrbitRadius = 2.5
      
      ' -- Create and show window
      hWnd = TBGL_CreateWindowEx("press Space to toggle the camera position , press 'M' to set a mask , 'R' reset mask to default ", 800, 600, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) 
      TBGL_ShowWindow 
      
      ' -- Create scene
      TBGL_SceneCreate(%sScene)
    
      ' -- Create basic entities
      ' -- Create camera to look from 0, 8, 20 to 0, 0, 0 
      TBGL_EntityCreateCamera(%sScene, %eCamera)
        TBGL_EntitySetPos(%sScene, %eCamera, 0, 8, 20)
        TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)  
      ' -- Create point light  
      TBGL_EntityCreateLight(%sScene, %eLight)
      TBGL_EntitySetPos(%sScene, %eLight, 10, 20, 50)
      
      ' -- Create something to look at 
      '---Start time
      Dim T0  As Double = Timer
      CreatePointsList()
      Dim T1  As Double = Timer
      MsgBox(0, "Total time to create points List "  & Format$(T1 - T0, "#0.00") & " secs" & " ...   number of points = " & Str$(total))
      
      TBGL_EntityCreateDLSlot(%sScene, %eContour, 0, %lMyPoints) 
        
        TBGL_EntitySetColor(%sScene, %eContour, 255, 255, 255)
            
      ' -- Resets status of all keys 
      TBGL_ResetKeyState() 
      TBGL_EntitySetTexture(%sScene, %eContour, %texOne )
      'TBGL_LoadTexture APP_Path+"SampleScripts\TBGL\GBuffers\Textures\Bricks.bmp", %texOne, %TBGL_TEX_MIPMAP
      TBGL_LoadTexture APP_Path+"SampleScripts\UI\Dialogs\Images\frogduck.bmp", %texOne, %TBGL_TEX_MIPMAP        
      
      ' -- Main loop
      While TBGL_IsWindow(hWnd) 
        FrameRate = TBGL_GetFrameRate
        TBGL_SetWindowTitle( hWnd, "FPS = "+Str$(FrameRate)+"  press Space to toggle the camera position , press 'M' to set a mask , 'R' reset mask to default ")
        TBGL_ClearFrame 
        If TBGL_GetWindowKeyOnce( hWnd, %VK_SPACE) Then
        If flag = 1 Then
         TBGL_EntitySetPos(%sScene, %eCamera, 0, 25, 0.1)
         TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)
         
         flag * -1  
         Else 
         TBGL_EntitySetPos(%sScene, %eCamera, 0, 12, 20)
         TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0) 
         flag * -1  
        End If
        End If
        
        If TBGL_GetWindowKeyOnce( hWnd, %VK_M) Then 
          If mask = 1 Then
            TBGL_EntitySetColorMask(%sScene, %eCamera, %TBGL_RED  )
            mask * -1
            Else
            TBGL_EntitySetColorMask(%sScene, %eCamera, %TBGL_GREEN  )
            mask * -1
          End If
        End If
         
         If TBGL_GetWindowKeyOnce( hWnd, %VK_R) Then
           TBGL_EntitySetColorMask(%sScene, %eCamera, %TBGL_DEFAULT)
         End If
         
         TBGL_EntitySetRot(%sScene, %eContour, 0, GetTickCount/40, 0)
          
        TBGL_SceneRender(%sScene)
       
        TBGL_DrawFrame 
     
        ' -- ESCAPE key to exit application
        If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While 
      
      Wend 
    
      TBGL_DestroyWindow
    END FUNCTION
            
    
    '==================================
    Sub CreatePointsList() 
    
      String src = " 
      ' -- Re-declare types
        
      Type Point3D
      x As Single
      y As Single
      z As Single
      red As Single
      green As Single
      blue As Single
      tu As Single
      tv As Single
      End Type
      
      dim oVertex(2000000) At #Vertex As Point3D
      dim oTexA(2000000)At #TexA As Point3D
      
      dim N At #total As long
      'dim oColorA(2000000) At #ColorA As TBGL_TRGB
      Long a, b, c, Nb
      Single x, z, k, xMin, yMin, zMin, xMax, yMax, zMax, range, step1
        
      Long NbX
      Long NbZ
      Long NbY
      nbx = 300
      nby = 300
      nbz = 300
      
      'xMin = -2 : yMin = -2: zMin = -2 : xMax = 2: yMax = 2 : zMax = 2
      'xMin = -3 : yMin = -3: zMin = -3 : xMax = 3: yMax = 3 : zMax = 3
      xMin = -4 : yMin = -4: zMin = -4 : xMax = 4: yMax = 4 : zMax = 4
      'xMin = -5 : yMin = -5: zMin = -5 : xMax = 5: yMax = 5 : zMax = 5
    
      range = xMax - xMin
      step1 = range / NbX
      x = xMin: z = zMin : y = yMin
      N = 0  
      For c = 0 To NbY
         For b=0 To NbZ
        
        For a=0 To NbX
          
          'k = 320*(((x*x + (9*y*y)/4 +z*z -1)^3) - x*x*z*z*z - (9*y*y*z*z*z)/80)
          'k = Sin(x*y)+Sin(y*z)+Sin(z*x)
          'k = x^3+y^2+z^2
           k = Pow(x,4) + Pow(y,4) + Pow(z,4) - Pow(x*x + y*y + z*z,2) + 3 * (x*x + y*y + z*z)
          'k = x^4 + y^4 + z^4 - (x^2 + y^2 + z^2)^2 + 3 * (x^2 + y^2 + z^2)
          
                 
          If k <= 0.1 And k >= -0.1 Then 
          'If k <= 0.5 And k >= -0.5 Then 
            N = N+1
            oVertex(N).x = x
            oVertex(N).y = y 
            oVertex(N).z = z
            oVertex(N).tu = a/NbX
            oVertex(N).tv = b/Nbz
                 
          End If
          x  = x + step1
          
        Next a
        x = xMin
        z = z + step1
        
      Next b
      x = xMin
      z = zMin
      y = y + step1
    Next c
    'print str N 
     terminate    
      "        
       
      ' -- Pass the source
      'O2_Asmo src
      o2_basic src
      If Len(o2_error) Then
        MsgBox 0, o2_error : Stop
      End If              
      ' -- Execute
      o2_exec
      
      Long N       
      TBGL_NewList %lMyPoints
        TBGL_PointSize 2
        TBGL_UseLighting %FALSE
        
        TBGL_BeginPoly %GL_POINTS
         For N=1 To Nb
           glTexCoord2f(Vertex(N).tu, Vertex(N).tv)
           glVertex3f(Vertex(N).x,Vertex(N).y,Vertex(N).z)
         Next   
       
        TBGL_EndPoly
        TBGL_EndList
        TBGL_UseLighting %TRUE
    End Sub
    
    Last edited by primo; 12-10-2017 at 17:50.

Similar Threads

  1. Space bar echoes ?
    By RobbeK in forum TBGL General
    Replies: 11
    Last Post: 13-10-2013, 21:37
  2. Space-Plates
    By Charles Pegge in forum Shout Box Area
    Replies: 10
    Last Post: 28-02-2012, 12:21
  3. New program... parametric surfaces
    By sblank in forum WCHS thinBasic gaming forum
    Replies: 11
    Last Post: 22-11-2010, 20:37
  4. Replies: 1
    Last Post: 19-10-2010, 17:55
  5. searching for a word :)
    By Lionheart008 in forum thinAir General
    Replies: 1
    Last Post: 12-05-2009, 02:22

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •