Computer Science Canada Parabola and cosine and sine |
Author: | Newguy [ Mon May 12, 2008 8:34 pm ] | ||||
Post subject: | Parabola and cosine and sine | ||||
I created a program that asks the user for the starting x value and y value of the parabola, the x speed , the y speed and the force of gravity and creates the parabola according to the information entered. It works ok. Then I used the search function and found this code written by another member that used cosine and sine to find the increment and created the arcing trajectory using that. I want to know how it works. Haven't done math in a while so I googled trig functions to get a quick refresher but the code still doesn't make sense to me. Below is my code followed by the code I found. I post you my code because I want to know how to create the parabola according to roots entered by the user and the vertex. I have taken grade 10 math and received above 90 % so I am good with math so I can handle most things, maybe grade 11 that you throw at me. Thanks for the help. My code:
Code posted by a user:
This code I need help understanding. Especially the /5 after ANGLE. This is how I see it and I think it is wrong. ---> cosine formula is cos(theta) = Adjacent / Hypotenuse theta = ANGLE so 5 must be the hypotenuse right? Therefore you are trying to get adjancent size rite? Hypotenuse --> /_| ^ Adjacent Sine formula is sin(theta) = Opposite / Hypotenuse theta = ANGLE so 5 must be hypotenuse right? Therefore this will get the opposite size rite? Hypotenuse --> /_| <--Opposite But what does this achieve in turing? Am I interpreting this right? I need some explanations. I don't want to move on until I understand the code. Thanks again for help. ![]() That ends this very long, confusing, and hard to explain post. ![]() |
Author: | CodeMonkey2000 [ Mon May 12, 2008 10:33 pm ] |
Post subject: | RE:Parabola and cosine and sine |
I'm a bit iffy on how he implemented this, but here is what's going on. You have a set speed in a set angle (we call this velocity). Now when you have a velocity you need to know its x and y components to determine the coordinates of the object. If you draw the speed , it looks like this: ![]() Basically r is the speed and theta is the angle it's going at. Now the speed in the x direction is a, and likewise b for y direction. To figure out a and b just use simple trig. However, this will cause something to go in a linear direction at angle theta. To get the curve trajectory effect you need gravity acting on your y velocity. And that's why you see the curve. If you get rid of ySpeed += GRAVITY in the code you will see a line going at 10 degrees. And please give credit to the poster of the original code. |
Author: | zylum [ Tue May 13, 2008 12:17 am ] |
Post subject: | RE:Parabola and cosine and sine |
Using codemonkey's image, x = cos(theta) y = sin(theta) gives you the x and y components of the vector r from (px, py) to (x, y). Furthermore, the vector is normalize, meaning the length is 1. Therefore, you can multiply each component by your desired speed to get the x and y components for the desired velocity (velocity being speed with a direction). Thus the /5 just means he is assigning a speed of 1/5. |
Author: | Newguy [ Tue May 13, 2008 3:48 pm ] |
Post subject: | Re: Parabola and cosine and sine |
The code is 4 or sumthing years old so giving credit won't do much but the code was written by do_pete_ Right now I understand how the code works and the / 5 part is the "power". So how can I draw a parabola from the roots and the vertex? Should I use my code or the code that uses trig. |
Author: | CodeMonkey2000 [ Tue May 13, 2008 5:17 pm ] |
Post subject: | RE:Parabola and cosine and sine |
It doesn't matter. Use the one you understand best. |