Solved

Converting Angle To Coordinates

Posted on 2003-11-06
3
1,106 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Export from Blender to ZPrint with textures 4 761
Software to create cartoons/animations 2 368
any RTS game state byte array size advice? 6 244
old35  java challenge 4 142
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…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 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