Results 1 to 5 of 5

Thread: Mandelbrot 3D set

  1. #1

    Mandelbrot 3D set

    testing the forum 3d mandelbrot set example in thinbasic with some variations, it is excelent. but trying the same (almost) in PB 9 result in a confusing status
    Mandel3D thinbasic example: display 3d mandel set and it will also save the set as points so we can view the points in meshlab as xyz model.
    Read_3D_Points TB example: will read the dataXYZ.xyz file produced by the Mandel3D and display it quickly.

    Read_3D_Points.Bas : will read the dataXYZ.xyz file produced by the Thinbasic first example
    note if we used leng = calcleng2(x,y,z) it will display the Set okay, but use leng = calcleng(x,y,z) and it will display it as spherical
    can't believe since the 2 subs is the same, arn't the vars inside the subs protected and local ? why it works in thinbasic excellently

    Mandel3D.bas: in PB in line 137 if we use leng = calcleng(x,y,z) it will display spherical shape. but if we use instead leng = calcleng2(x,y,z) which is the same but changing the variables names, it will display the set as if it is compressed
    Attached Files Attached Files

  2. #2
    Member mike lobanovsky's Avatar
    Join Date
    Aug 2009
    Location
    Omnipresent
    Posts
    191
    Rep Power
    41
    Hi primo,

    Disclaimer: I have not run your code, I have only looked through it. Still my comments can lead you in the proper direction for you to be able to understand and debug your code yourself.

    In fact, PowerBASIC and thinBasic pass their function arguments differently on default: by reference and by copy, respectively. This means that before passing the arguments into the function, TB would make copies of them thus isolating whatever changes the function might make to their values, from the main code that called the function. OTOH PB would pass the arguments by reference so that every change made to the argument values is immediately propagated back to the caller code.

    Your calcleng function modifies the original x, y, z arguments heavily but the mods can't affect the TB caller code because the arguments aren't in fact stored in the exact memory locations where they reside in the caller code. However the same function used in PB will propagate the mods back to the caller code and will thus spoil the calculation results for the subsequent iterations. At the same time, calcleng2 seen in the PB code uses local temp vars as buffers that isolate the mods from the function's original arguments passed by the caller code. That's why that function would perform identically to the TB calcleng function, while the PB calcleng function would fail.

    Make it a habit to use explicit ByRef and ByVal parameter qualifiers to declare your function parameters in the both languages if you want to avoid similar pitfalls in the future.
    Mike
    (3.6GHz i5 Core Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, x64 Windows 7 Ultimate Sp1)

  3. #3
    Thank you mike very much for the help, i forgot BYVAL/BYREF completely as if they does not exist due to the lack of usage, yes adding BYVAL to PB solve the problem and display Mandel3D correctly:
    calcleng( BYVAL x AS SINGLE, BYVAL y AS SINGLE, BYVAL z AS SINGLE) AS SINGLE
    
    it seems we don't need to declare calcleng previously. as it works with and without "DECLARE FUNCTION calcleng" .
    i never used BYVAL/BYREF in thinbasic so i have tested thinbasic now
    and only BYREF change the x variable:
    Uses "Console"
    Local x, y As Long
    x = 2
    y = test(x)
    PrintL "x= " + x
    PrintL "y= " + y
    
    PrintL:PrintL "press any key to exit"
    WaitKey 
    
    'Function test(ByRef x As Long) As Long 
    'Function test(ByVal x As Long) As Long
    Function test(x As Long) As Long
    Local y
    x = x + 5
    y = x
    Function = y
    End Function
    
    thanks and best regards

  4. #4
    Member mike lobanovsky's Avatar
    Join Date
    Aug 2009
    Location
    Omnipresent
    Posts
    191
    Rep Power
    41
    You're welcome, primo.

    Terminology:

    DECLARE FUNCTION Foo LIB "Bar.dll" (ByVal param AS LONG) AS LONG ' this is called "forward declaration"
    
    FUNCTION Foo(ByVal param AS LONG) AS LONG ' this is called "declaration"
        param += 1        ' \
        FUNCTION = param  '  > this is called "implementation"
    END FUNCTION          ' /
    
    Mike
    (3.6GHz i5 Core Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, x64 Windows 7 Ultimate Sp1)

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736
    Just for the record,

    ThinBASIC functions parameters are ByVal by default (as it is less confusing), while PowerBASIC has parameters ByRef (as it is faster).


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Similar Threads

  1. Api Mandelbrot
    By peter in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 0
    Last Post: 20-02-2014, 22:21
  2. TB Mandelbrot Time
    By peter in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 16
    Last Post: 13-12-2013, 07:41
  3. canvas_setpixel (mandelbrot)
    By largo_winch in forum UI (User Interface)
    Replies: 14
    Last Post: 31-10-2011, 17:30
  4. 3D Mandelbrot Set
    By zak in forum General
    Replies: 11
    Last Post: 29-11-2010, 06:40
  5. Benoit Mandelbrot, RIP
    By LanceGary in forum Shout Box Area
    Replies: 6
    Last Post: 05-11-2010, 03:35

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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