PDA

View Full Version : Re: Complex number library



sblank
22-02-2010, 18:39
Hi Eros,

I'm getting things backwards... thank you for the kind welcome and the quick response. I don't know why it has taken me and my students so long to find ThinBasic. We are especially fond of the TBGL module!

The complex.bi file (with tbasic extension) was attached in the previous post.

No problem with the execution speed of ThinBasic... we are used to using Python for our OpenGL graphics!

Cheers... and thanks again!

Stan



Is this the complex library you are using:
http://www.freebasic.net/forum/viewtopic.php?t=124&highlight=complex+number+library

If not, let me know where I can find it or just post here sources.

Also found this:
http://www.freebasic.net/forum/viewtopic.php?t=125&highlight=complex+number+library

José Roca
22-02-2010, 19:19
I do not think it is that complicated if we have something to start from.


You don't? The basic functions are easy, but the trigonometric functions aren't.

I once wrote a class in PowerBASIC to deal with complex numbers:
http://www.jose.it-berater.org/smfforum/index.php?topic=3191.0

It is based in ansi C functions found in the GNU Scientific Library ( http://www.gnu.org/software/gsl/ ), distributed under the terms of the GNU General Public License (GPL).

It also makes heavy use of the math functions of the C runtime library, specially because I could not find code to implement some such finite and isnan with PB.

Michael Hartlef
22-02-2010, 20:13
Hello Stan,

I welcome you here also and can only say good things about thinBasic and the crew here. Petr Schreiber is the master of the TBGL module. I created the Sprite part of it and also some other modules.
With the SDK's available for thinbasic, everyone can create modules but we also would like to hear where we can help the users.

Anyway, have a great time with thinbasic and I hope we will see you and your students more oftern posting here.

Best wishes
Michael Hartlef

Petr Schreiber
22-02-2010, 20:21
Hi Stan,

welcome to thinBasic!

On TBGL and graphics side, I think ThinBASIC offers one major advantage over Python due its syntax.
OpenGL and TBGL graphic code is ideal to be structured using indenting.

While Python is very restrictive about the indenting, you can do it freely in ThinBASIC, to highlight command nesting.

This you have to do in Python:


glPushMatrix
glRotatef timer/1000, 0, 1, 0
glBegin(GL_TRIANGLES)
glVertex3f (-1, 0, 0)
glVertex3f ( 1, 0, 0)
glVertex3f ( 0, 1, 0)
glEnd
glPopMatrix


while in ThinBASIC you can indent as necessary, adding more code clarity:


glPushMatrix
glRotatef timer/1000, 0, 1, 0
glBegin(GL_TRIANGLES)
glVertex3f( -1, 0, 0)
glVertex3f( 1, 0, 0)
glVertex3f( 0, 1, 0)
glEnd
glPopMatrix


When using TBGL, you can forget about the "3f" and use the built in commands:


tbgl_PushMatrix
tbgl_Rotate timer/1000, 0, 1, 0
tbgl_BeginPoly(%GL_TRIANGLES)
tbgl_Vertex (-1, 0, 0)
tbgl_Vertex ( 1, 0, 0)
tbgl_Vertex ( 0, 1, 0)
tbgl_EndPoly
tbgl_PopMatrix


TBGL offers many more high level functions, let me know if you need to know anything about the module.
Even the very simple above usually provide some enhacement, like being polymorph:

TBGL_Vertex can take 2 or 3 parameters, no need for special function like in OpenGL (glVertex2f vs. glVertex3f)
TBGL_Rotate can take just one parameter to behave like default 2D rotation
TBGL_Translate again polymorph with 2 or 3 params...

Then there is easy rendering mode setup -> default 3D or custom coordinate system 2D, both with user defined viewports which can be specified using relative coordinates which are more robust than default OpenGL pixels.

Display lists and textures are fully garbage collected.

As Mike said, he coded fantastic sprite engine for TBGL, so there is really lot to explore and use.
Then there are some auxiliary functions, to draw line on screen using one line of code and others.

You can use TBGL window embedded to normal dialog window, ideal for editor type applications.

Of course, TBGL can be freely intermixed with native OpenGL code, so you can continue coding the way you are used from Python.

I hope you will like it!


Petr

sblank
22-02-2010, 20:32
Hi Michael and Petr,

Thanks for the responses... I do appreciate your kindness!

Currently I'm in the midst of exploring the sample programs, but I must say that I'm very impressed with ThinBasic. I agree with Petr about Python syntax, particularly the indentation restrictions. I can't tell you how many times we've had issues with Python code and the only thing wrong was the level of indentation... such an annoyance!

Cheers,

Stan

ErosOlmi
22-02-2010, 22:46
I do not think it is that complicated if we have something to start from.


You don't? The basic functions are easy, but the trigonometric functions aren't.

I once wrote a class in PowerBASIC to deal with complex numbers:
http://www.jose.it-berater.org/smfforum/index.php?topic=3191.0

It is based in ansi C functions found in the GNU Scientific Library ( http://www.gnu.org/software/gsl/ ), distributed under the terms of the GNU General Public License (GPL).

It also makes heavy use of the math functions of the C runtime library, specially because I could not find code to implement some such finite and isnan with PB.



:D
I didn't say I would have developed it.
I said: "I do not think it is that complicated if we have something to start from"

And now, thanks to you, we have something to start from. And it is even professionally developed (as usual is your code)

I suppose that if I develop a dedicated module and publish it as source code into thinBasic SVN server (so everyone can get it) I will not infringe any Licence.

I will see what I can do and than publish in next days into SVN server
So, Stan, expect something very soon, let say by next week

Ciao
Eros

Michael Hartlef
22-02-2010, 23:32
Hi Michael and Petr,

Thanks for the responses... I do appreciate your kindness!

Currently I'm in the midst of exploring the sample programs, but I must say that I'm very impressed with ThinBasic. I agree with Petr about Python syntax, particularly the indentation restrictions. I can't tell you how many times we've had issues with Python code and the only thing wrong was the level of indentation... such an annoyance!

Cheers,

Stan


I am feeling with you. I wrote once an export script from Blender to TBGL's own model format called M15 in Python. I remember that it was also important that I displayed whitespace charcters as Python also see it differently when one line uses tabs and the other one uses spaces at the front. Even they are lined up the same, for Python it is something different.

Michael

ErosOlmi
23-02-2010, 00:16
Stan,

I think I've already something to test.

Be sure you have installed latest thinBasic beta version 1.7.10.2. You can get from here (http://community.thinbasic.com/index.php?topic=3214.msg24069#msg24069)

Than get attached files.
Put "thinBasic_iComplex.dll" (new thinBasic module handling tComplex numbers) into \thinBasic\Lib\ directory
Use "iComplex_Test.tbasic" script to test them.

For the moment I've just developed the folllowing:

variable declaration using predefined type tComplex
function i = iComplex.Set(i1, i2)
function i = iComplex.Add(i1, i2)
function i = iComplex.Sub(i1, i2)
function i = iComplex.Mul(i1, i2)
function i = iComplex.TanH(i)


where i, i1, i2 are variables of tComplex type

tComplex is defined as follows:

Type tComplex
x As Double '---real part
y As Double '---imaginary part
End Type

Before I will go too much deeper, let me know if I'm on the right track.
Eros

PS: attached file removed because surpassed.

kryton9
23-02-2010, 03:29
Won't a 2D library also be necessary to output fractals?

sblank
23-02-2010, 05:11
Eros,

Thank you very much! I'll download the new dll and try it now.

Also, to answer Kent (hopefully), we should be able to use TBGL to plot fractals. The complex number mathematics are used to calculate escape time... the eventual distance of the iterated complex function from the origin. This distance is a real number. The plotting is done using simple x,y Cartesian coordinates based on this distance of the iterated complex number to the origin. Of course, this isn't a good explanation of fractals, but basically we can plot using standard OpenGL plotting commands.

In terms of which complex functions we've used in class, the "complex.tbasic" file I attached earlier contains the functions we used most often... and it looks like you have an excellent start here!

Basically, we use:

abs (determines distance of complex number to origin)
power (^)
add
subtract
multiply
divide
sin
cos
exp

and would be thrilled with this set and anything else you can add to the module!

Thanks... and I'll give you some feedback as soon as possible!

Stan

sblank
23-02-2010, 05:27
Hi Eros,

Your dll and test file work fantastic! Good job!

If you, Petr, and/or Michael are interested, I can send you the "Python Programming in OpenGL" text I've written and that we've been using for the past three years in my class. The text is also used at the University of Illinois by a math professor friend in his mathematical programming class. The text would illustrate the kinds of 2D and 3D graphics (and fractals) we've been creating using Python and OpenGL.

It occurs to me that I could rework the text using ThinBasic?

Anyway, if you are interested, I can send it to you via mediafire. It's about 430 pages, including table of contents and index and the download size is about 5 mb. If you aren't interested, no problem.

Cheers,

Stan

Michael Hartlef
23-02-2010, 09:45
Hi Stan,

of course I'm interested.

Thanks for offering.

Michael

Michael Hartlef
23-02-2010, 09:47
Won't a 2D library also be necessary to output fractals?


What do you need? Points, Circles? Lines? All there since a year :)

Petr Schreiber
23-02-2010, 10:32
Hi,

I am also very interested in the text!

As Michael said, 2D functions are already here in TBGL as well as 2D rendering mode.


Petr

ErosOlmi
23-02-2010, 10:58
Hi Eros,

Your dll and test file work fantastic! Good job!

...


OK Stan, I will go on and give you something more complete in few days (or even before depending on my load at work).

ErosOlmi
23-02-2010, 14:35
Stan,

almost finished what you have asked as initial functionalities.
I will publish this night (CET time)

Eros

sblank
23-02-2010, 17:42
Thanks Eros!

Here is the MediaFire link to the Python and OpenGL text I wrote for my students... it seems to work well, but I'm getting tired of Python. Although I have the text copyrighted, I'm making it available to anyone who is interested. It has been a labor of love (so to speak) and essentially a snapshot of what interests me about computation... sort of the text that I always wanted to buy for my students, but couldn't.

<<link removed, file attached to this post>>

I apologize for the MediaFire adware... if there is a better file sharing/hosting site I'm open for suggestions!

Cheers,

Stan




Stan,

almost finished what you have asked as initial functionalities.
I will publish this night (CET time)

Eros

Petr Schreiber
23-02-2010, 17:55
Thanks Stan,

I think it would be also possible to attach the file here as attachement, as they are allowed up to 10MB.

I just quickly went through the pages of your text, it is really very well structured, and the examples look very attractive.
Some of the examples you have inside have already been implemented in thinBASIC, like Sierpinski triangle, but some of them are completely new to me. It will be very interesting reading!


Thanks for sharing,
Petr

EDIT: First ported example from the book here: MathArt: Port of code by Stan Blank (http://community.thinbasic.com/index.php?topic=3230.msg24214#msg24214)

sblank
23-02-2010, 18:26
Thank you for the kind words, Petr.

My students have been my critics and my editors over the past several years, so the text is better than it would have been otherwise. The kids caught many (too many!) of my errors, which allowed me to correct the text multiple times. They also suggested topics of interest, which were implemented to the best of my ability. I also received great feedback from my math professor colleague, George K. Francis, and his students at the Univ. of Illinois. I make no great claims for the content or the prose... and the errors that remain are mine, but the book was fun to write and seems to work well in the classroom and that's all that matters.

My school internet account will not let me attach the pdf to this post. I'll attach it later this evening or tomorrow evening from home.

Cheers... and thanks!

Stan




Thanks Stan,

I think it would be also possible to attach the file here as attachement, as they are allowed up to 10MB.

I just quickly went through the pages of your text, it is really very well structured, and the examples look very attractive.
Some of the examples you have inside have already been implemented in thinBASIC, like Sierpinski triangle, but some of them are completely new to me. It will be very interesting reading!


Thanks for sharing,
Petr

José Roca
23-02-2010, 18:49
I suppose that if I develop a dedicated module and publish it as source code into thinBasic SVN server (so everyone can get it) I will not infringe any Licence.


Guess not. However, the module will become GPL automatically, and also any program that uses it. And you must include a GPL license.

Because of this heavy "contamination", I haven't done further adaptations of GPL libraries.

My license for the Windows API Headers is just the opposite: I don't allow derivative works (mainly to avoid conflicts between different versions), but I allow to use them commercially and without forcing you to make your source code available.

ErosOlmi
23-02-2010, 18:54
Thanks José, I will keep it in mind.
I will publish sources of new module but only it.

ErosOlmi
23-02-2010, 19:23
sblank,

I've just release thinBasic beta 1.7.10.3.
New iComplex module is included and few examples are available in \SampleScript\iComplex\
All new keywords have been briefly documented in help file.
I didn't make any deep test on new iComplex_* keywords so if you find any strange behave please post a bug report.

Ciao
Eros

_________________________________________________
PS: I've attached to your previous post your great PDF file on pyOpenGL and removed link to external site
PS: thanks a lot for you donation!

sblank
23-02-2010, 20:15
Wow! Thanks for the quick work Eros... I'll download the file and start "playing" this evening.

Hopefully I can create a few fractals by the weekend... or over the weekend.

Also, thanks for posting the document.

Petr... great work on the MathArt port. That will give me an example to go by for other programs!

Cheers,

Stan

PS: Is it possible to change my online name to "Stan Blank" or would that require me to create a new account?



sblank,

I've just release thinBasic beta 1.7.10.3.
New iComplex module is included and few examples are available in \SampleScript\iComplex\
All new keywords have been briefly documented in help file.
I didn't make any deep test on new iComplex_* keywords so if you find any strange behave please post a bug report.

Ciao
Eros

_________________________________________________
PS: I've attached to your previous post your great PDF file on pyOpenGL and removed link to external site
PS: thanks a lot for you donation!

Petr Schreiber
23-02-2010, 21:10
Hi Stan,

you can change your name easily:

Click "Profile" in the toolbar on the top of the forum
In "Modify profile" table click "Account Related Settings"
Change "Name" item


You will still login the same, but the displayed name will be the one you choose.


Petr

sblank
23-02-2010, 21:57
Thanks Petr... got it!

Stan



Hi Stan,

you can change your name easily:

Click "Profile" in the toolbar on the top of the forum
In "Modify profile" table click "Account Related Settings"
Change "Name" item


You will still login the same, but the displayed name will be the one you choose.


Petr

ErosOlmi
23-02-2010, 22:06
Better to stop posting in this thread because I will close it now that module iComplex is out.
Maybe I will split some topics and put into TBGL area.

Ciao
Eros

sblank
23-02-2010, 22:50
Eros,

Before you close this thread, please allow me to thank you for creating the iComplex library. I also want to thank Petr for porting the MathArt script over to ThinBasic using two different methods!

I stand in awe of the kindness and support everyone has shown me in the ThinBasic community!

Cheers,

Stan



Better to stop posting in this thread because I will close it now that module iComplex is out.
Maybe I will split some topics and put into TBGL area.

Ciao
Eros

ErosOlmi
23-02-2010, 23:45
Ok, in order not to waste posts in this thread I've splitted original request of a new library working on complex numbers.
Request has been moved into "Features developed" forum and the rest of posts are now in this thread.

Also I've created a forum dedicated to iComplex module so anyone willing to talk about it can do it here.

Ciao
Eros