Solved

Converting Angle To Coordinates

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

18 Experts available now in Live!

Get 1:1 Help Now