How to Calculate Destination Coordinates in a Trig Graphing Program?

  • Thread starter Thread starter Slinger1010
  • Start date Start date
  • Tags Tags
    Graphing Trig
Click For Summary
SUMMARY

The discussion focuses on calculating destination coordinates in a 100x100 grid using trigonometric functions in a VB program. The user inputs a direction in degrees and a distance, and the goal is to derive the Cartesian coordinates (x, y) using the equations x = r * sin(A) and y = r * cos(A), where A is the angle in radians. The conversation also highlights the use of Taylor series for sine and cosine approximations, emphasizing the need to convert degrees to radians for accurate calculations.

PREREQUISITES
  • Understanding of trigonometric functions (sine and cosine)
  • Familiarity with Cartesian coordinates
  • Basic knowledge of VB programming
  • Concept of Taylor series for function approximation
NEXT STEPS
  • Implement trigonometric calculations in VB using the formulas x = r * sin(A) and y = r * cos(A)
  • Explore Taylor series for sine and cosine to improve approximation accuracy
  • Learn about converting degrees to radians in programming
  • Experiment with different angles and distances to observe coordinate outputs
USEFUL FOR

Programmers, mathematics enthusiasts, and anyone interested in implementing trigonometric calculations in graphical applications or simulations.

Slinger1010
Messages
1
Reaction score
0
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.

Ron
 
Physics news on Phys.org
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 =]
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
7K