Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Moving in an arc - cos?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
GenesisXCS




PostPosted: Fri Dec 18, 2009 1:22 am   Post subject: Moving in an arc - cos?

What is it you are trying to achieve?
In essence, I'm am trying to move a 'skier' around a downhill slalom course in an arc, rather than in straight lines and bouncing off like ping - pong balls.


What is the problem you are having?
I have no previous knowledge of cos, sine, etc. I have no yet learned that in math class =S. If I was to implement it, however, into my program, how would it be done?


Describe what you have tried to solve this problem
I am currently using straight line thing, where it is something like:
if y > 500 then
x:= x + 1
y:= y -1
elsif y > 250 then
x:= x - 1
y:= y - 1

---- yeah -------

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
---------- Posted above -------

Please specify what version of Turing you are using
Turing 4.05

As an added point, I am using a PROCEDURE format of coding, and calling it when needed, if that makes any difference.
I hope that I'll be able to implement it by tmr; its due tmr, or Sunday if I can pursuade the teacher =D.

EDIT: GenesisXCS: Thanks In Advance =D
Sponsor
Sponsor
Sponsor
sponsor
mirhagk




PostPosted: Fri Dec 18, 2009 7:39 am   Post subject: RE:Moving in an arc - cos?

um i don't think we're able to teach you trigonometry by tomorrow.

I'd suggest looking at this tutorial [click here]
jbking




PostPosted: Fri Dec 18, 2009 10:06 am   Post subject: Re: Moving in an arc - cos?

My suggestion would be to consider taking a piece of graph paper and draw out such an arc and then seeing if there is a pattern of how you'd move along in such an arc. This removes all the trignometry in some ways. For example, in Logo the way to draw a circle was for the turtle to take a single step turn 1 degree and repeat the process 360 times to draw the circle. Shouldn't there be some utilities in Turing for drawing circles and other curves? Have you ever seen parabolas or other Conics? That may be useful as well.
mirhagk




PostPosted: Fri Dec 18, 2009 1:38 pm   Post subject: RE:Moving in an arc - cos?

Draw.Arc is available in turing.
TheGuardian001




PostPosted: Fri Dec 18, 2009 3:43 pm   Post subject: Re: Moving in an arc - cos?

Sine/cosine functions work exactly like linear functions in terms of graphing, they just look different. If you know how to move something on a line, you know how to move something on a sinusoidal function.

For example, if I want to draw a line made of dots, given the equation y= 2x:
code:

var y : int
for x : 0 .. 100 %my x coordinate
    y := x*2 %my y coordinate
    drawdot(x,y,black)
end for

Now lets say I want to draw a sinusoidal function, given the equation y=10*cos( 0.2 * x)
code:

var y : real
for x : 0 .. maxx %my x coordinate
    y :=  10 * cos(0.2 * x) + 100%my y coordinate
    drawdot(x,round(y),black)
end for

It's really the same thing, but with the sin/cos functions thrown in. Basically all you need to know:
for a formula in the form of a*sin (k(x - c)) + d:
a stretches it vertically. The higher the number, the taller the graph.
k stretches it horizontally. the lower the number, the wider the graph.
c shifts the graph left or right.
d shifts the graph up or down.
Tony




PostPosted: Fri Dec 18, 2009 3:57 pm   Post subject: RE:Moving in an arc - cos?

Trigonometry is easy, it's just probably not taught in a way where one sees an application right away.

This is what you need to know -- Imagine that you are moving around the circumference of a circle. If you know the angle, then cosine will tell you where you are on the x-axis and sine will tell you the y-axis.

Freaking sweet, now you can draw circles by simply drawing a point at every whole angle.

The gotcha is that because both functions know only the angle, and not how big the circle is, they give you ratios from the unit circle. That is, the real x distance from the center is radius*cos(angle)

Turing:

for i:1..360
   Draw.FillOval(100 + round(100*cosd(i)), 100 + round(100*sind(i)), 2,2,red)
   delay(10)
end for
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Insectoid




PostPosted: Fri Dec 18, 2009 4:37 pm   Post subject: RE:Moving in an arc - cos?

I don't think trig is the solution here, unless you want the skier to go up and down. A simple exponential function should be sufficient.
TheGuardian001




PostPosted: Fri Dec 18, 2009 6:04 pm   Post subject: Re: Moving in an arc - cos?

I believe they intend for it to be zig-zagging down the screen, as seen from a top down perspective, based on the version with linear movement.
Sponsor
Sponsor
Sponsor
sponsor
andrew.




PostPosted: Sat Dec 19, 2009 12:51 am   Post subject: RE:Moving in an arc - cos?

I didn't run your code, but I'm assuming you want something like this:

Turing:
View.Set ("graphics:500;500,offscreenonly")
for decreasing i : 500..0 by 2
    Draw.FillOval (round (100*sind(i))+250, i, 10, 10, black)
    View.Update
    delay (10)
    cls
end for


Basically, it's just an oval which follows a sine curve down the screen.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: