Sine rule and boats

AngusMcDoon

Well-Known Member
Joined
20 Oct 2004
Messages
9,046
Location
Up some Hebridean loch
Visit site
Doing some YAPPery sea trials today I found my true wind speed/angle vector calculations were sometimes falling foul of the occasional non-unique solution to a triangle where 2 sides and a non-included angle are known. I guess that the cosine rule with 2 known sides and the included angle is better because there is only ever one solution. Thinking about it it makes sense that there may be 2 solutions as there are 2 solutions (per circle) to all values of arcsine apart from 1 and -1. Now I don't ever remember being taught this, or was I just day dreaming or flicking bits of chewed paper at the back of Smithers' head that day in the maths lesson?
 
Doing some YAPPery sea trials today I found my true wind speed/angle vector calculations were sometimes falling foul of the occasional non-unique solution to a triangle where 2 sides and a non-included angle are known. I guess that the cosine rule with 2 known sides and the included angle is better because there is only ever one solution. Thinking about it it makes sense that there may be 2 solutions as there are 2 solutions (per circle) to all values of arcsine apart from 1 and -1. Now I don't ever remember being taught this, or was I just day dreaming or flicking bits of chewed paper at the back of Smithers' head that day in the maths lesson?

There are two solutions to sin() and cos() - that must have been a day when you were flicking paper pellets.

The the angles with the same sin add up to 180, the angles with the same cos add up to 360.

Generally you use sin in the range -90 to +90, and you use cos in the range 0 - 180: these are the ranges that calculators and spreadsheets resolve to.

If you're solving for angles outside these ranges you need to know the quadrant that you're working in and you convert to that.

Hope that this helps...
 
Yes - there are two geniune solutions if the length of the side adjacent to the angle is greater than the opposite side - but you should be able eliminate one - or recast the problem into one with a unique solution.

What is the meaning of the sides and angles involved?
 
I divided my scalene triangle into 2 right angle triangles and resolved them instead. Seems to work in all quadrants.

Right angle triangles have all angles in the 0 - 90 range, so there's no problem with a sin solution of more that 90.

Unless you do spherical right angle triangles, which makes things more complicated ;)

(spherical right angle triangle internal angles add up to 180 x (1 + 4 x area of triangle / area of circle)
 
What is the meaning of the sides and angles involved?

Calculating true wind speed/angle from apparent wind speed/angle and boat speed. Seatalk transmits the raw data but derived data like true wind has to be calculated. I've done this in a few YAPPs, but yesterday I hit the quadrant where it went wrong. Sorted it as described in my previous post.
 
Calculating true wind speed/angle from apparent wind speed/angle and boat speed. Seatalk transmits the raw data but derived data like true wind has to be calculated. I've done this in a few YAPPs, but yesterday I hit the quadrant where it went wrong. Sorted it as described in my previous post.
If that is the case then surely you already have the included angle (the AWA - or more precisely 180-AWA) in which case there is a unique solution.

I always do these calculations by resolving the vectors into components parallel to, or perpendicular to, a chosen direction. In this case I would do that relative to the boat velocity, simple pythagoras to get the TWS and an ATAN to get the TWA
 
Can it not be reduced to a solution to an inverse tangent function? Then the ATAN2 math library function works in all quadrants.

It can, but I like working out different ways to do it and comparing how long they take. Currently it looks like...

Code:
		if(true_wind_data_available)
		{
			if(boatspeed<0.01f)
			{
				tws=aws;
				twa=awa;
			}
			else
			{
				x=boatspeed*sin(awa/DEGREES_TO_RADIANS);
				y=boatspeed*cos(awa/DEGREES_TO_RADIANS);
				z=aws-y;
				tws=sqrt(z*z+x*x);
				if(tws<0.01f)
				{
					twa=0.0f;
				}
				else
				{
					t=(M_PI_2-awa/DEGREES_TO_RADIANS)+acos(x/tws);
					twa=M_PI-t;
				}
				twa*=DEGREES_TO_RADIANS;
				if(twa<0.0f)
				{
					twa+=360.0f;
				}
			}
			handler(TRUE_WIND);
		}

The repeated awa/DEGREES_TO_RADIANS is optimized away.

Once I have the fastest algorithm I can reduce processor speed to reduce power consumption.
 
I use a similar calculation with ATAN2 in excel to derive real time tide vector – have you considered including this in your display?
 
Top