Calculating Displacement based on the compass direction

Hi, I need some help with programming the calculation of displacement. Given the distance the object has moved in the XY plane, and the yaw (heading) of the object, I'd like to calculate the displacement of the object. For example, the object moved 5m North and 2m East.

The data I have is the distance it travels in the XY plane (X distance and Y distance) and the heading of the device which is determined by the direction of X. I know how to calculate it on paper but I am having trouble to program it.

I've attached two examples that shows how I obtained the calculations. In the 1st example, the X-distance travelled is 3 meters while the Y-distance is 4 meters and the heading of the X-axis is 70°. After calculating, I managed to get that it has travelled 2.733m South and 4.187m East. In example 2, it travel, the X-distance is -5m and the Y-distance is -12m, the heading is 160°. I calculated that the object travels 8.80m North and 9.566m East.


if the angle 'a' between the X-axis and the N/S axis is known

then for given 'x' value (x can be signed), N/S value = xcos(a) , +ve being N, -ve being S

similarly for a give 'y' value (y can be signed), E/W value = ycos(b) , +ve being E, -ve being W, b being angle between the y-axis and E/W axis

hope that helps...

Hi Sherzaad,

The angle between the X-axis and the North is determined by the (yaw) heading of the device. It's a value that I measured. However, I'm not sure about the programming to find the angle 33.13° in Example1 and 22.62° in Example2. Is there any quick method to identify the angle as I struggle to identify it myself while calculating.
I assume the 'x' value you mention is the adjacent value between X-distance and Y-distance.

Hi Rupert,
Thanks, I'll look into it.

I've got enough help from Stack Overflow

why do you say you traveled on a particular heading yet also say x and y where x and y are not the north/south and west/east directions

yaw, by the way, is the orientation of the aircraft relative to the direction of travel which may be required in a wind

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.