Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Trig graphing problem

  1. Dec 29, 2007 #1
    I'm writing a program in VB but since math isn't my strongest suit I'm having a little trouble figuring out the equation for this:
    I have a grid 100 x 100.

    The user will input the direction in deg and the distance to travel. I need to get the destination grid x and Y.
    0 Deg is facing up.

    I don't mind if there is a little bit of error, in fact I want it. Rounding is acceptable.

    Any help is appreciated, if you need more info just ask please.

  2. jcsd
  3. Dec 29, 2007 #2

    Gib Z

    User Avatar
    Homework Helper

    Welcome to PhysicsForums Slinger1010 !

    If I have interpreted your problem correct, from a given angle and length, you want to find the x-y co ordinates the line stops on?

    If that is the problem, I can help =] Ok I want you to try 4 separate x-y axis on a piece of paper. On the first one, draw some straight line with length r (distance to travel) and some angle between 0 and 90 in degrees (the first quadrant). Label the angle A. We define to co-ordinate this line A degrees from facing straight up and r units from the origin to have Cartesian Co-ordinates [itex](x_1, y_1)[/itex]. Now, put your pen on that point, and draw a horizontal line until you hit the y-axis. Y

    What you have now is a right angled triangle, where you know the lengths of all sides =] The side adjacent to A is y_1, the side opposite A is x_1, and the hypotenuse is r. Using elementary trig, we see that [tex]\sin A = \frac{x_1}{r} \to x_1 = r \sin A[/tex] and [tex]\cos A = \frac{y_1}{r} \to y_1 = r \cos A[/tex].

    Now, with the other 3 axis you drew, draw other lines with length r and angle A, except make them in the 2nd, 3rd and 4th quadrants respectively. Then find the right angled triangle in each of them like I just did. To see if your on the right track, the second quadrant should have the same solutions except (180 -A) replacing A.

    As for wanting some error, there are well known series that represent the Cosine and Sine functions;

    [tex]\sin x = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} ....[/tex]
    [tex]\cos x = 1 - \frac{x^2}{2!} + \frac{x^4}{4!} - \frac{x^6}{6!} ....[/tex]

    [tex] n! = 1\cdot 2 \cdot 3 \cdot 4 \cdot 5 ...\cdot (n-1) \cdot n[/tex] (The product of the positive integers upto n.

    The thing is, all of those series only work when x is in radians, not degrees. However if we convert, we work out that A degrees is [tex] \frac{A\pi}{180}[/tex] radians, so we put that in everywhere in replacement of x.

    Each of those series have an infinite amount of terms, taking all of them gives exactly cosine x and sine x, but taking the first few gives good approximations. Using more terms gives better approximations, however the approximations are much better for small numbers than they are for big numbers. For example to get 5 digits of accuracy of Sin x when x is 10 degrees, you might only need to take the first 3 terms, but to get the same accuracy when x is 300 degrees, it might take 6 or something.

    Play around with it on your calculator, see how accurate you want it to be =]
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Trig graphing problem
  1. Trig problem (Replies: 3)

  2. Problem with graphes (Replies: 1)

  3. Square trig graphs (Replies: 5)

  4. Trig problem (Replies: 4)