Gamestudio Links
Zorro Links
Newest Posts
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Newbie Questions
by AndrewAMD. 12/04/23 11:14
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
2 registered members (TipmyPip, izorro), 556 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Ugh! Trigonometry! #138999
06/30/07 23:23
06/30/07 23:23
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
I'm trying to create a small double pendulum simulation (or rather, sin(ulation), ).

What I can't figure out, though, is how all the trig works together to produce a simulated circle path. A double pendulum can be described like this:



But I don't know how to get the circles to work in C-Script.

I know it's been done (Gravball), but I don't know how it all works.

Could anyone help out?

Here's my Code:

var video_mode= 8;
var video_screen= 1;
var video_depth= 32;
var screen_color[3]= 1,0,0;

var originVector[2]= 512,200;
var jointVector[2]= 512,300;
var endVector[2]= 512,400;

bmap masspoint= "masspoint.pcx";

function main()
{
set_center_and_pos();
trig_set();
while(1)
{
draw_line(originVector,vector(0,255,0),100);
draw_line(jointVector,vector(0,255,0),100);
draw_line(endVector,vector(0,255,0),100);
wait(1);
}
}

panel mass1
{
pos_x= 0;
pos_y= 0;
bmap= masspoint;
flags= visible | overlay;
}

panel mass2
{
pos_x= 0;
pos_y= 0;
bmap= masspoint;
flags= visible | overlay;
}

function set_center_and_pos()
{
while(1)
{
mass1.pos_x= jointVector.x - 8;
mass1.pos_y= jointVector.y - 8;
mass2.pos_x= endVector.x - 8;
mass2.pos_y= endVector.y - 8;
wait(1);
}
}

function trig_set()
{
while(1)
{
jointVector.x+= cos(originVector.x - sin(jointVector.x));
jointVector.y+= cos(originVector.y - sin(jointVector.y));
endVector.x+= 1 * cos(originVector.x + sin(endVector.x));
endVector.y+= 3 * cos(originVector.y + sin(endVector.y));
wait(1);
}
}



Last edited by MrCode; 06/30/07 23:25.

Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: Ugh! Trigonometry! [Re: MrCode] #139000
06/30/07 23:41
06/30/07 23:41
Joined: Mar 2006
Posts: 752
Portugal
demiGod Offline
User
demiGod  Offline
User

Joined: Mar 2006
Posts: 752
Portugal
Well, to obtain the circle you just need this code, where distance will be the circle radius, dont know if is this what you want, cause youŽll need entities / pointers

limit.x = center.x + distance * cos(center.pan) * cos(center.tilt);
limit.y = center.y + distance * sin(center.pan) * cos(center.tilt);
limit.z = center.z + distance * sin(center.tilt);

Re: Ugh! Trigonometry! [Re: demiGod] #139001
07/01/07 01:25
07/01/07 01:25
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
I'm doing this in 2D, so no, I don't think this is the code I want.

How would you convert that to 2D?


Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: Ugh! Trigonometry! [Re: MrCode] #139002
07/01/07 08:48
07/01/07 08:48
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
limit.x = center.x + distance * cos(center.pan);
limit.y = center.y + distance * sin(center.pan);

just cut off the tilt and .z stuff and it is 2D

Oh I see you do this with panels.
Well thats not a big deal either.
Code:

var spin_status;

function start_spinning(_r1,_r2,_speed1,_speed2)
{
var angle_one;
var angle_two;

spin_status = 1;

while(spin_status)
{
panel_mass1.pos_x = originVector.x + _r1 * cos(angle_one);
panel_mass1.pos_y = originVector.y + _r1 * sin(angle_one);

panel_mass2.pos_x = panel_mass1.pos_x + _r2 * cos(angle_two);
panel_mass2.pos_y = panel_mass1.pos_y + _r2 * sin(angle_two);

angle_one += _speed1 * time_step;
angle_two += _speed1 * time_step;

wait(1);
}
}

function stop_spinning()
{
spin_status = 0;
}

//call of start_spinning():
start_spinning(200,80,10,15);
radius of mass1 = 200
radius of mass2 = 80
angle speed of mass1 = 10
angle speed of mass2 = 15



Last edited by Xarthor; 07/01/07 08:54.
Re: Ugh! Trigonometry! [Re: Xarthor] #139003
07/19/07 06:06
07/19/07 06:06
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
Sorry to wait until the thread is on page 6 to revive it, but I don't want to double-post.

I figured out the trig (finally), and I just need to know how the gravity thing would work out. here's my current Code:

var video_mode= 8;
var video_screen= 1;
var video_depth= 32;
var screen_color[3]= 1,0,0;

var originVector[2]= 512,200;
var jointVector[2]= 512,300;
var endVector[2]= 512,400;
var angle;
var angle2;

bmap masspoint= "masspoint.pcx";

function main()
{
set_center_and_pos();
trig_set();
while(1)
{
draw_line(originVector,vector(0,255,0),100);
draw_line(jointVector,vector(0,255,0),100);
draw_line(endVector,vector(0,255,0),100);
wait(1);
}
}

panel mass1
{
pos_x= 0;
pos_y= 0;
bmap= masspoint;
flags= visible | overlay;
}

panel mass2
{
pos_x= 0;
pos_y= 0;
bmap= masspoint;
flags= visible | overlay;
}

function set_center_and_pos()
{
while(1)
{
mass1.pos_x= jointVector.x - 8;
mass1.pos_y= jointVector.y - 8;
mass2.pos_x= endVector.x - 8;
mass2.pos_y= endVector.y - 8;
wait(1);
}
}

function trig_set()
{
while(1)
{
endVector.x= sin(angle) * 50 + jointVector.x;
endVector.y= cos(angle) * 50 + jointVector.y;
jointVector.x= sin(angle2) * 100 + originVector.x;
jointVector.y= cos(angle2) /*circle*/ * 100 /*length*/ + originVector.y;
angle+= 50 * time_step;
angle2-= 1 * time_step;
wait(1);
}
}



this makes the first mass point spin very slowly around the center, while the second mass point spins very fast around the first one.

Additionally, the draw_line command seems to always "interpolate" (if you want to call it that) to a triangle when you draw more than one line. It's rather annoying and I would like to know if there's a way to suppress it or work around it.

EDIT: nvr mind about the triangle problem, all I had to do was draw another line back to jointVector.

Last edited by MrCode; 07/19/07 06:09.

Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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