Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Vector Gravity Simulation in realtime (physics project)

Author
Message
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 22nd Oct 2009 23:27 Edited at: 22nd Oct 2009 23:29
I am currently working on a simulation of gravity. If you look at my picture, I need to create the hexagons from vectors so that when a planet is put in the middle of them the nearest one shrinks, and pulls all of the other hexagons towards it. Any ideas?



Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 23rd Oct 2009 02:24
Just thinking out loud, if you use sin and cos to draw the hexagons maybe if you scale sin and cos depending on how far away they are from a planet then they will stretch like that.

TGC Forum - converting error messages into sarcasm since 2002.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 23rd Oct 2009 02:51 Edited at: 23rd Oct 2009 02:54
Will that work if I keep adding more, and more planets to the screen? So I get cross gravity forces, and combined gravity forces?

How about a moon in orbit animation?

Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 23rd Oct 2009 02:59 Edited at: 23rd Oct 2009 03:16
If you are interested.. take a look at this picture.. maybe you will know what I am doing.. maybe not. This is a genuine NASA image, that I have edited with a Hexagon grid.. I find it very interesting...




Wouldn't it be funny if Dark Basic found Dark Matter!

Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 23rd Oct 2009 05:11
I would start out just by making a hexagonal point cloud. Check out this code (it's in DBPro, i don't know anything about DarkBASIC, but what you're trying to do seems cool)

in the code when you see "sidelength/2" and "sidelength*sqrt(3)/2", that's really just "sidelength*cos(60)" and "sidelength*sin(60)".

I'm not sure how to figure out which points connect to which. I'll think about it more, but it probably has to do with division, modulus, and some 1d to 2d conversions (cuz every point is stored in an array). I haven't really started to solve for that yet, but this whole thing seems like it could end up looking really cool XD
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 23rd Oct 2009 14:32 Edited at: 23rd Oct 2009 14:53
Thanks! I have DBPro as well. Do you think that I can do something like this?......


set vector2,Map,hexagon(a).x,hexagon(a).y

Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 23rd Oct 2009 16:34 Edited at: 23rd Oct 2009 16:45
Nearly have it, I just need to figure out the diagonals, which are an offset of X/Y. I'm not sure when the code drops down a line.



Ok I am moving this to DB Pro, because it is now a DB Pro project.

Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 24th Oct 2009 09:41


I've done a bit more, i smoothed out some kinks in the point cloud generator, and figured out how to get the number of points in one row. It was pretty hard for me ta figure out, i just guess I'm not used to geometry and integers :\

Again, the above code is in DBPro. I figure it doesn't really matter what language it's coded in. Once you know how to do it, you can port it to darkbasic, c++, java, flash, whatever.

Still, now that i know how to find the number of dots in a row and generate a point cloud, i can start... err... connecting the dots.
Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 24th Oct 2009 10:37
Wait, scratch that, not all kinks are worked out. There are actually points generated offscreen to the left of the screen

Well, i'm going ta bed, i think i should have the lines done by tomorrow, and that'll be cool!
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 24th Oct 2009 15:45 Edited at: 24th Oct 2009 15:53
Thanks! I was just beginning to realise that I need the dots in rows. Starting to understand what I need now. I've never used dots, and lines before, and the new commands were making me forget what I am actually trying to achieve. On the far right I would need some drawing tools to add the atoms. I also want to see if snowflakes form naturally from gravity, so I need a temperature setting as well, and how this effects the distribution of particles in the atmosphere, and how this particle arrangement alters the hexagons around it. Basically, what I am saying is that I need a gap on the far right.

Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 24th Oct 2009 17:30 Edited at: 24th Oct 2009 17:34
Had a play with your new code. This is cool! Press space.



Although I don't see the tiny hexagons which I want to shrink down?

Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 24th Oct 2009 17:45 Edited at: 24th Oct 2009 17:51
Oh fixed it! And guess what.... I got a perfect snowflake in the middle of the screen! Yay.. this is great! Now it need to work all over the screen, and not just in the middle.



Edit: Oh I know what it is, I need the mouse to jump to grid coordinates.

Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 24th Oct 2009 18:18 Edited at: 24th Oct 2009 18:29
Hmmm.. A bit more complicated. The mouse cursor need to jump to the centre of a hexagon no matter what size it is, and the hexagons change positions. So that is the coding that I need.

I think this is the end of the Big Bang theory.

Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 25th Oct 2009 06:26 Edited at: 25th Oct 2009 06:33
Still struggling to lock the cursor. Anyway, I've added a temperature gauge, and slider. The colder the temperature the smaller the hexagons. Which reminds me of the Einstein-Bose condensate experiment. At zero the hexagons become just a dot (the atoms in Einsteins experiment also became just a dot), with total collapse of gravity. It seemed strange to Einstein, but works absolutely fine with this model.. in fact you have no other option. So far Quantum Physics are nothing more than everyday physics... which is exactly what you want.

demons breath
20
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 25th Oct 2009 14:00
I think what you'd need is to find out which hexagon the mouse is over. Then take the x and y positions of 2 opposite dots and simply put it in between at (x1+x2)/2 (y1+y2)/2. No matter which points you used, as long as they were on opposite sides, the point half way in between would still be where you wanted the mouse cursor to jump to.

Unfortunately, if you had the mouse jumping to there then if you were reading the mousex() and mousey() positions then it would probably always jump the mouse to the center of the same hexagon unless you moved the mouse really fast. I don't know, I haven't tried it, but maybe storing where the mouse should be in an array (1,1) at (0,0) and (0,1) and then where the mouse would jump to in (1,0) and (1,1).

I'm not too sure how to tell where the mouse is though, and whether it's over a certain hexagon. Which is probably the part you weren't sure of. So this is probably a pretty useless post. Oh well...

"A West Texas girl, just like me"
-Bush
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 25th Oct 2009 17:47
I'll just do it equal distances for now, it might still work anyway.

Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 27th Oct 2009 19:21
I have this at the moment, but it's not perfectly symmetrical. Is there anything I can do to get this more symmetrical?



Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 28th Oct 2009 01:35
Ummmm that's dbp code. this is the dbc board man haha

New Site! Check it out \/
Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 28th Oct 2009 02:22
still, it's about the solution to the problem. The algorithm to solve for it still holds true in any language.

Login to post a reply

Server time is: 2024-05-09 16:50:08
Your offset time is: 2024-05-09 16:50:08