Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
1 registered members (AndrewAMD), 599 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
square roots and cube roots? #385250
10/15/11 11:50
10/15/11 11:50
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
ok so I found a function for the square root "sqrt(x)" usefull for calculating stuff with circles. But what if I want to use the cube root(3)? (for spheres)

So far I'm using these two function for circles:
Code:
var Area(var radius)
{
   return(pi*radius*radius);
}

var Radius(var area)
{
   return(sqrt(area/pi));
}


I cant seem to find a function to do cube roots (3) for spheres. Anyone know of such a function in 3dgs? If not... Anyone know how I could implement it?


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: square roots and cube roots? [Re: Carlos3DGS] #385251
10/15/11 12:19
10/15/11 12:19
Joined: May 2002
Posts: 7,441
ventilator Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
what do you need this for?

i think it could work with some stupid iterative method? laugh but i am no mathematican and probably there is a better way?

edit:
there is cbrt() in the c standard library (which can be used from lite-c). and you can also use pow() with 1/3.0. laugh

Re: square roots and cube roots? [Re: ventilator] #385254
10/15/11 12:38
10/15/11 12:38
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
to calculate the area of a sphere from its radius, and to calculate its radius from its area.
I found a fun indie game called "Osmos" and im trying to make my own 3D version with some ideas I have for it.

http://www.youtube.com/watch?v=pso6UBicLWU

basically what I am working on now is the basic gameplay so whenever I collide with a smaller sphere what I want is my.scale=Radius(My_Area+Your_Area);

or implemented with my functions in the above post...
my.scale=Radius(Area(my.scale)+Area(you.scale));

when I get these basics working ill do some basic velocity vectors for movement&inertia and then I can start to add all these ideas i'm getting based around this simple game's gameplay.


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: square roots and cube roots? [Re: ventilator] #385255
10/15/11 12:39
10/15/11 12:39
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
what do I have to "#include" to get "cbrt(x)" working?


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: square roots and cube roots? [Re: Carlos3DGS] #385256
10/15/11 12:41
10/15/11 12:41
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
After a quick dig on the net for c++ solutions, I came up with this lite-c variant

Code:
#define	cuberoot(xxx)	exp(log((float)xxx)/3)



Hopefully you have some KNOWN values to test with, as I was testing using
pretty random numbers and comparing them to results from the windows calculator.

Let us know how it goes...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: square roots and cube roots? [Re: EvilSOB] #385258
10/15/11 12:58
10/15/11 12:58
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
Thanks alot EvilSoB!

I'm not sure what the xxx is thoug... only one number? or num*num*num?

Would it be something like this?:
Code:
var CubeRoot(var num)
{
	return(exp(log(num)/3));
}




"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: square roots and cube roots? [Re: Carlos3DGS] #385259
10/15/11 13:04
10/15/11 13:04
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
You got it correct with your function.
Im just not too sure how accurate it will be using var's
You may need to go floats inside the functions...


XXX is just what I use in single-parameter macros.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: square roots and cube roots? [Re: EvilSOB] #385262
10/15/11 14:21
10/15/11 14:21
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
The easiest solution is pow(num, 1.0/3.0).


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1