Solved

Converting Angle To Coordinates

Posted on 2003-11-06
3
1,104 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
3d letters for 3d font rendering 7 1,002
Will this chess board object .clone() call in Java make a perfect copy? 3 81
PDF: Display my cards game? 8 98
bunnyEars2 challenge 6 108
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.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now