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 Professional Discussion / Help with Maths - Part 2

Author
Message
JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 1st Dec 2003 12:57
Morning all...

I've been playing about with some sprite movements, especially trying to get them to move around curves/arcs.

However I'm getting totally confused over the mathematics behind it, and really would appreciate some help (maths was never my forte at school some 16 years ago...!)

For example, if I use the following code...

sprite 1,screen width()/2,screen height()/2,1
offset sprite 1,sprite width(1)/2,sprite height(1)/2

for i=0 to 180
sprite 1,4*cos(i)+sprite x(1),4*sin(i)+sprite y(1),1
print i
wait 50
next i

Sure enough the sprite sweeps from 12 oclock to 6 oclock


But if I use the following...

sprite 1,screen width()/2,screen height()/2,1
offset sprite 1,sprite width(1)/2,sprite height(1)/2

for i=180 to 0 step -1
sprite 1,4*cos(i)+sprite x(1),4*sin(i)+sprite y(1),1
print i
wait 50
next i

The sprite sweeps from 12 oclock to 6 oclock, but this time in a counter-clockwise direction. I would have thought it should have gone from 6oclock to 12 oclock!!!

Likewise, how on earth would I be able to go from 6oclock to 3oclock in a clockwise direction (because at 12oclock, the degree would reset to 0), or from 6 oclock to 9oclock in a counterclockwise direction...!!!!

I've noticed in the manual there are some commands which are...

CurveValue
WrapValue
NewXValue
NewYValue
NewZValue
CurveAngle

But I'm affraid the documentation is, er, not too good.

So, what am I doing wrong (obviously it's me not understanding mathematics), and can the same effect be achieved using the above poorly-documentated commands.

MANY thanks...

-----

~ J ~
las6
23
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Finland
Posted: 1st Dec 2003 13:27
agh!
You are confusing me.

first of all, use parenthesis (brackets) in your math.
Even though it shouldn't be necessary, it makes a life lot easier for you and the ones who have to read your code.

and if you want the clock to go from 6 o'clock to 12, clockwise, then you'll have to do this:
(actually I'm not sure about your maths, but judging by your other examples, it should work that way)



No offense, but why did you think moving the clock backwards would make it go clockwise? Cos that's exactly what you asked.

and what comes to moving the clock from 6 o'clock to 3 o'clock, clockwise again, try this:´


Keyboard not detected. Press F1 to continue.
JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 1st Dec 2003 13:34
OK,

so using...

Quote: "for i=180 to 360
sprite 1,4*cos(i)+sprite x(1),4*sin(i)+sprite y(1),1
print i
wait 50
next i
"


Which will go from 6oclock to 12oclock in a clockwise direction Yes?

How do I make it foes from 6oclock to 12oclock in a counterclockwise direction then? Because...

Quote: "for i=180 to 0 step -1
sprite 1,4*cos(i)+sprite x(1),4*sin(i)+sprite y(1),1
print i
wait 50
next i
"


Does NOT go counterclockwise...!

-----

~ J ~
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Dec 2003 14:02
You need to *subtract* the adjustment to move backwards.

JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 1st Dec 2003 14:07
Cheers IanM, that's another I owe you...!

-----

~ J ~
JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 1st Dec 2003 14:10
So in terms of...



That is moving from 6 to 12 in a counter-clockwise direction. What if I needed to move from 6 oclock all the way round, past 12 oclock, and ending up at 9oclock?

Sure, I could do it in two stages, but surely this isn't the way to go, hence the reason about those other commands.

-----

~ J ~
las6
23
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Finland
Posted: 1st Dec 2003 14:12
Err...?!?

Quote: "for i=180 to 0 step -1
sprite 1,4*cos(i)+sprite x(1),4*sin(i)+sprite y(1),1
print i
wait 50
next i

The sprite sweeps from 12 oclock to 6 oclock, but this time in a counter-clockwise direction"


Didn't you just say that goes counterclockwise. Way too confusing way to explain things.

Keyboard not detected. Press F1 to continue.
las6
23
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Finland
Posted: 1st Dec 2003 14:15
Not sure if DB supports negative variables in for - next loop, but here goes:



Keyboard not detected. Press F1 to continue.
JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 1st Dec 2003 14:18
Ok las6, point taken, perhaps wrong choice of words.

What I therefore should have said is that I wanted my sprite to go from 12 to 6, passing 3 (counter clockwise), which worked.

I wanted to know why, by simply having a decreasing value, why my sprite wouldn't go from 6 to 12, passing through 3, instead it WAS going counter-clockwise this is true, but from 12 to 6, via 9. Which is NOT what I wanted.

IanM has explained this and it makes perfect sense now.

Perhaps I didn't explain things as clearly as I should.

-----

~ J ~
JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 1st Dec 2003 14:21
Quote: "Not sure if DB supports negative variables in for - next loop, but here goes:"


Yep, it sure does.

MANY MANY thanks again.

Remind me to get the beers in if ever I'm in Finland!!!!

-----

~ J ~
JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 1st Dec 2003 14:34
One final question...

My code is now



The sprite now flies off the screen...!

All I've done is added +sprite x|y(1).

I understand that 2*cos affects the X and 2*sin affects the Y, but I'm confused as to why my sprite simply can't be positioned anywhere on screen, and my apply the 'maths' to move it around...

-----

~ J ~
JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 1st Dec 2003 15:29
Sorted....

Thanks to you guys again...

-----

~ J ~

Login to post a reply

Server time is: 2026-07-27 01:32:59
Your offset time is: 2026-07-27 01:32:59