From what I understand, this is your problem:
- You have 2 points,
start
andnext
that you are walking between - You want to find the coordinates of a third point,
New
that should be some distance and bearing fromstart
, given that you are already facing fromstart
tonext
.
My solution is this:
- Create a normalized vector from
start
tonext
- Rotate your normalized vector by given bearing
- Multiply the normalized, rotated vector by your distance, and then add it to
start
- treating
start
as a vector, the result of the addition is your new point
Because a counter-clockwise rotation ("left" from the current point) is considered positive, you need to invert bearing
so that port is associated with negative, and starboard with positive.
Code
import math
origX = 95485
origY = 729380
nextX = 95241
nextY = 729215
distance = 2000.0
bearing = 45
origVec = origX, origY
nextVec = nextX, nextY
#Euclidean distance between vectors (L2 norm)
dist = math.sqrt((nextVec[0] - origVec[0])**2 + (nextVec[1] - origVec[1])**2)
#Get a normalized difference vector
diffVec = (nextVec[0] - origVec[0])/dist, (nextVec[1] - origVec[1])/dist
#rotate our vector by bearing to get a vector from orig towards new point
#also, multiply by distance to get new value
#invert bearing, because +45 in math is counter-clockwise (left), not starboard
angle = math.radians(-bearing)
newVec = origVec[0]+(diffVec[0]*math.cos(angle) - diffVec[1]*math.sin(angle))*distance, \
origVec[1]+(diffVec[0]*math.sin(angle) + diffVec[1]*math.cos(angle))*distance
print newVec
Output:
(93521.29597031244, 729759.2973553676)