The online racing simulator
Drift Angle algorithm help
(14 posts, started )
#1 - vane
Drift Angle algorithm help
I have been attempting to work out an algorithm for working out the drift angle but have as of yet been unsuccessful working it out. I have a vague idea that the angular velocity and heading come into it at some point but i think my brain is going weird :s

I couldn't see myself doing coding as a job

any help would be greatly appreciated!
based on what data? outsim?
#3 - vane
No i was thinking of insim
insim.txt

struct CompCar // Car info in 28 bytes - there is an array of these in the MCI (below)
{
word Node; // current path node
word Lap; // current lap
byte PLID; // player's unique id
byte Position; // current race position : 0 = unknown, 1 = leader, etc...
byte Info; // flags and other info - see below
byte Sp3;
int X; // X map (65536 = 1 metre)
int Y; // Y map (65536 = 1 metre)
int Z; // Z alt (65536 = 1 metre)
word Speed; // speed (32768 = 100 m/s)
word Direction; // direction of car's motion : 0 = world y direction, 32768 = 180 deg
word Heading; // direction of forward axis : 0 = world y direction, 32768 = 180 deg
short AngVel; // signed, rate of change of heading : (16384 = 360 deg/s)
};

Wouldn't it just be a case of the difference direction and heading? That should be the cars yaw angle.
#6 - vane
Hang on a sec, i swear my insim.txt doesn't have direction, either that or I'm blind lol my bad

Ok forget i ever made this thread

ill go sit in the corner
#7 - vane
Can i use the Math.Round() to round it to an integer?

EDIT: also do i need to do the difference or would heading minus direction work? only when i get the generic angle number and divide by 182.0444... to get it into degrees, at one point i actually get -330 degrees.
Lacking Math prowess
Digging up an old thread, but I don't think (heading - direction) is quite right when dealing with ISP_MCI.

My question is, when finding yaw, if my direction is something like seven degrees, and my heading is 355 degrees, how do I find the correct value?

To rephrase:
direction = 359
heading = 15
f(direction, heading) == 16

Define f
f is just a cheap way of saying function.

Direction is where your car is going. Heading is where your car is facing.

Absolute(Absolute(Heading) - Absolute(Direction)) = Drift Angle.
Quote from Dygear :f is just a cheap way of saying function.

Direction is where your car is going. Heading is where your car is facing.

Absolute(Absolute(Heading) - Absolute(Direction)) = Drift Angle.

That absolutely doesn't address the problem.

If a car's y axis is offset from the track's y axis by 2 degrees, and its direction of travel is offset from the track's y axis by 358 degrees, your method will return 356 degrees of yaw.

I don't want to throw these values away, I just need something a bit more robust than subtraction.
Gai-Luron has drift scoring enabled in his LFSLapper script.

I think it uses absangle.

What you could do, is something like I do in lapper, which (in very simple terms) is

Event OnDriftScore( $userName )
$Angle = GetCurrentPlayerVar( "Angle" );
IF( $Angle < 0 )
THEN
$Angle_Negative= -$Angle ;
ENDIF

If player gets positive drift angle, then use the $Angle variable, else use the $Angle_Negative variable.

EDIT: I took too long to answer (dealing with phone call after starting) - the previous answer is probably best anyway.
abs((abs(direction - heading) + 180) % 360 - 180)

Quote from filur :
abs((abs(direction - heading) + 180) % 360 - 180)


Thank you.
Quote from Rhama :maybe try this d for directn, h for heading

static double AbsoluteAngleDifference(double d, double h)
{
double absdiff = Math.Abs(d - h);

if (absdiff <= 180)
return absdiff;

if (d < 180)
{
h -= 360;
return d - h;
}
else
{
d -= 360;
return h - d;
}

}

Excellent! Your solution seems to work perfectly.

In Python, I've written it like this:

def Yaw(Direction,Heading):
"""
Derives yaw from ISP_MCI values
"""
Direction /= 182.04
Heading /= 182.04
absdiff = math.floor(abs(Direction - Heading))

if absdiff <= 180:
return absdiff
elif Direction < 180:
Heading -= 360
return math.floor(abs(Direction - Heading))
else:
Direction -= 360
return math.floor(abs(Heading - Direction))

I imagine this could be refined, but it works! Hooray!

Thank you all for your help :lovies3d:

Drift Angle algorithm help
(14 posts, started )
FGED GREDG RDFGDR GSFDG