|
2 registered members (TipmyPip, izorro),
556
guests, and 2
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Ugh! Trigonometry!
#138999
06/30/07 23:23
06/30/07 23:23
|
Joined: Mar 2007
Posts: 677 0x00000USA
MrCode
OP
User
|
OP
User
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.
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
Expert
|
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
MrCode
OP
User
|
OP
User
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.
void main()
{
cout << "I am MrCode,";
cout << "hear me roar!";
system("PAUSE");
}
|
|
|
|