Solved

Converting Angle To Coordinates

Posted on 2003-11-06
3
1,105 Views
Last Modified: 2013-12-26
Hi, I need a formula, algorithm or a function("Visual Basic") that can take a position(X, Y), an angle(0-360) and a number, and based on these values it will give you a position(X, Y).
For example if I say:

Position: 1, 1
Angle: 90
Number: 2

it will return 1, 3, cause 90 degrees is up and 1, 3 is 3 steps from 1, 1.

Or another example:

Position: 1, 1
Angle: 180
Number: 7

it will return -6, 1. cause 180 degrees is left and -6, 1 is 7 steps from 1, 1.

- Julian
0
Comment
Question by:JulianS
  • 2
3 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9694013
newx = oldx + length * cosine(angle)
newy = oldy + length * sine(angle)
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 180 total points
ID: 9694220
A small explanation is in order

 |
 |
 |
 |
 |                       B
 |                     /|                      
 |                   /  |
 |              H /    |
 |               /      |  O
 |             /        |
 |           /          |
 |     A ./______|C
 |             A
 |_________________________________

A is your oldx,oldy .... B is the new location newx,newy .... you are given the angle CAB and length AB (denoted by H)

basically H - hypotenuse ... A - adjacent ... O - opposite

clearly co-ordinates of C are newx,oldy
also newx = oldx + A

now Cos(CAB) = A/H
or A = cos (CAB) * H
therefore newx = oldx + cos(CAB) * H

same applies to newy which will evaluate to
newy = oldy + H * sin(CAB)
0
 
LVL 31

Assisted Solution

by:GwynforWeb
GwynforWeb earned 70 total points
ID: 9727607
For this

Position: x, y
Angle: t
Number: n

As a subroutine

Sub newpos(x,y,t,n)
newXpos=x + round(n*cos(t))
newYpos=y + round(n*sin(t))
End Sub

or as a pair of functions

Function  newXpos(x,y,t,n)
newXpos=x + round(n*cos(t))
End Function

Function  newYpos(x,y,t,n)
newYpos=y + round(n*sin(t))
End Function
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question