
Who is this man and what does he have to do with qualifying at Talladega? (Hint: he’s the greatest mathematician of all time)
One of the strangest story lines in the history of iRacing is the Q circle phenomenon. It is an eerie tale, and if words like quaternion and eigenvalue send shivers up your spine, then you might do well to stop reading, toss some salt over your shoulder, and just walk away.
Our story begins many years ago, during the development of Grand Prix Legends, when unbeknownst to anyone, an insidious, barely perceptible flaw was introduced into the physics code. It lay dormant for several years until the release of Nascar 4. Sometime after that, astute oval racers discovered something very odd: laptimes at Talladega and Daytona had a strange tendency to bounce up and down every other lap, even though the car was being driven nearly identically. The time variation was small, mere hundredths of a second. When I first heard about it, I was skeptical. Surely these drivers were just seeing patterns where there weren’t any; superstition was slowly growing into urban legend. I figured the non-issue would soon go away, unreproducible in true, scientific, back to back tests. After all, what on earth could explain such a bizarre claim?

William Rowan Hamilton, the guy pretty much responsible for Q circles.
And yet, the issue didn’t go away. iRacing competition director Shannon Whitmore showed me one day how it worked, and sure enough, his laptimes fluctuated up and down, every other lap, by a few hundredths. Even more worrisome was the fact that this could be used to advantage in qualifying. Apparently, simply pretending to do a lap, by driving in a circle in pitlane before qualifying, would shift the good laptime/bad laptime fluctuation from odd/even laps to even/odd! This was key in qualifying at the superspeedways, since the best laptime is usually obtained on the second flying lap, after the car has had a longer time to reach top speed. By shifting the bizarre good laptime to the second qualifying lap, you could gain an advantage of a few hundredths, which is a pretty significant time difference, especially at the top levels of simracing.
And so the “Q circle” was born. Racers being racers, constantly on the lookout for a competitive advantage of any kind, we began to see the ritual of driving in a circle before qualifying at the superspeedways. It became downright embarrassing. People took sides, and argued vehemently for or against the practice. Was it a legitimate competitive advantage, or an unsporting cheat that should be banned? In the Nascar World Championship Races, the Q circle issue exploded into a contentious debate, with the solution being to have the drivers all send in a replay of their qualifying laps so we could insure that nobody was Q circling!
How could this be addressed? How could we even detect that it was being done? If someone happened to spin on their outlap, thereby gaining the Q circle advantage, how could we legitimately disqualify them? We needed to solve the mystery of the Q circles. We had quite a few discussions amongst the engineers, but to no avail. We couldn’t figure out how it could be happening. Theories abounded, but none, when researched, could explain it. Subtle differences in lap timing and scoring? Couldn’t find anything. Some fluctuation in air density or some other calculations every minute or so? Nope. How could the millions of calculations that were being done every second lead to behavior that was so predictable based on the mere number of laps completed—or actually the mere number of circles completed? It was a complete and utter mystery, and a very bizarre one at that.
Apparently, simply pretending to do a lap, by driving in a circle in pitlane before qualifying, would shift the good laptime/bad laptime fluctuation from odd/even laps to even/odd!
One day iRacing president Tony Gardner and Shannon came into my office and said we needed to establish a ruling on the Q circles. Should we allow them or not? Things were coming to a head. Tempers were rising. The legitimacy of iRacing as a fair arbiter of competition was being called into question. Things looked bad. I envisioned my career in a shambles, derailed by the Q circle conundrum. What could they be? What could be causing them?

Eeeeek!!! It’s a quaternion!
It was at this very moment that a flash of realization came to me. It had to do with quaternions, I was almost sure of it! I said so to Tony and Shannon, but this did not seem to register with them. Shannon gave me a look that said, “stop joking around,” and Tony muttered, “what the heck is a Q-bonian?” While they continued to talk about how we should address the Q circle “exploit” I fired up the sim in the debugger and set a breakpoint (a way to stop the sim in mid-computation) where I knew I could get a look at the player car’s quaternion.
Of course, I should explain what a quaternion is. It is a mathematical entity (invented by the mathematician William Rowan Hamilton, famous for the Hamiltonian matrix) that provides a very useful way to represent the 3D orientation of an object. You are more likely to have heard about Euler angles, the well known yaw, pitch, and roll. These were invented by Leonhard Euler, the greatest mathematician of all time, who probably did more to change the modern world than any other human you can think of. If you’ve heard about race cars being pitch-sensitive, or having too much body roll in the turns, you know about Euler angles. Euler angles work for representing the rotation of an object in 3D, but they have some serious shortcomings. It’s difficult to take an object’s angular velocity (how fast it’s spinning) and update the object’s orientation using Euler angles. Also, there are orientations (the dreaded gimbal lock) where Euler angles suddenly change direction in a very non-linear way. A better way to represent orientations lies in a theorem that was proved by none other than…Euler. He showed how any rotation of an object in 3D can be accomplished by picking some axis through the object, and rotating it by some angle around that axis. Euler had discovered the basic idea behind quaternions, but it would take more than sixty years after Euler’s death for William Hamilton to turn this idea into something useful (in 1843).
A quaternion is made up of four numbers. Three of them specify the axis (a vector) about which an object is rotated, and one specifies the single angle of rotation about that axis, basically. They work very nicely for representing rotations, since they can be easily rotated by an object’s angular velocity, plus they don’t have a gimbal lock orientation. Quaternions are actually a little more complicated than that, and the reason I’m going on about this is that you need to know more to understand Q circles. The single angle number is actually the cosine of half the angle of rotation. The vector part representing the axis is scaled by the sine of half the angle of rotation. How Hamilton dreamed all this up, I have no idea. But the key thing is that it takes 720 degrees of rotation of an object, or two full circles, to take the cosine and sine parts through a complete cycle. Quaternions are not unique, that is, there are two quaternions representing any given rotation. Think about it: if you rotate an object by some angle around some axis, then that’s the same as rotating the object around the axis pointing exactly in the opposite direction by the negative of the same angle. So for a given orientation of your race car, there are two ways to specify it: with the positive or negative version of some quaternion. So this is what I was looking for in the debugger. I wanted to see if the player car’s quaternion was the positive or negative version. The sim stopped at my breakpoint and I looked at the values. Quaternion was positive. Then I restarted the sim, and drove in a circle. Sure enough, my quaternion had become negative, just as I suspected, since I hadn’t gone through 720 degrees of rotation! Another circle and it was positive again. So at last it seemed I had found something that could potentially be related to the Q circles. But the hunt wasn’t over yet. This was certainly something that varied every other lap, and could be affected by driving a Q circle. But the quaternions aren’t used for much except generating a rotation matrix (more math for handling rotations), and the positive and negative version of a quaternion both generate identical rotation matrices, according to the math. It shouldn’t matter whether your quaternion is positive or negative, the formulas give the same matrix, and that matrix is used everywhere else to actually rotate all the vectors used by the physics. Aerodynamic drag and downforce, tire forces, and even gravity are all manipulated using this identical rotation matrix. But maybe there was a bug—a mistake in the formulas coded in the simulation that would give a slightly different matrix for the positive and negative quaternion. With any luck, there might be a bug, and I could fix it!
A quaternion is made up of four numbers. Three of them specify the axis (a vector) about which an object is rotated, and one specifies the single angle of rotation about that axis, basically.
Unfortunately, there didn’t appear to be a bug. I pored over the matrix from quaternion routines and they were just what they were supposed to be. Still, I needed to check by running the code. I set another breakpoint, and stopped the code just at the instant the player’s car was placed on track. I wrote down all nine numbers from the rotation matrix, and all four numbers from the quaternion. I changed the code so that the negative quaternion was generated first, instead of the positive, when the car was first placed on track. It occurred to me that I could “fix” the problem by randomly assigning each driver a positive or negative quaternion, so that nobody would know whether they should drive a Q circle or not! I had to laugh, knowing the controversy that would erupt. No, I would have to fix this the right way. If it turned out to be some difference between the positive and negative quaternion, then I could easily force the code to always use only the positive one. But if there was no difference, the Q circles would return to their legendary status as eerie mystery. I digress. So here I was, now looking at the rotation matrix generated by the negative quaternion. The numbers weren’t all exactly the same as those from the positive case, but they were so close that it couldn’t really matter. Less than one part in four million difference for the numbers that were different, and some of the numbers were exactly the same.

Even half a cent added up for an entire lap is real money!
Some of you may be wondering why the numbers were different at all. Some of you may be wondering why you’re still reading this. Some of you aren’t still reading this. For the first group, I’ll tell you: round-off error. Arithmetic on a computer is almost always done with a limited amount of precision, and the precision used in iRacing is generally the twenty three bits of mantissa in an IEEE format floating point number. That jargon is pretty much demanding an explanation, but time is too short for that. The only important thing to know is that one part in four million is a difference of plus or minus one bit of precision in a floating point number. Round-off error is just what you get when you’re trying to split the bill for $25.85 at a restaurant two ways, and you get $12.92 and a half cent. There is no such thing as a half cent, just as there is no such thing as a twenty fourth bit of precision in an IEEE float. Someone’s going to have to pay $12.93, and someone gets a better deal at $12.92. In restaurant bill terms, the negative quaternion was getting stuck with $40,000.01, and the positive quaternion was getting off with $40,000.00. Round-off error just doesn’t matter, for the most part, since it tends to be random and cancel itself out. Split a million restaurant bills, and you’re not going to save a ton of money on the round-off . . . unless you always get to save the half cent. But here is the interesting thing: the negative quaternion was always getting the larger restaurant bill!
The reason that’s the case has to do with the computer’s “round-off” mode, which controls which way the half cent (half bit) gets rounded. And it turns out to be significant. Almost all the force vectors, velocity vectors, and acceleration vectors that are used to move the car in the simulation are multiplied by this rotation matrix. That means on average, when the quaternion is negative, all these vectors end up being about one bit of precision (one part in 4 million or so) longer than when the quaternion is positive. When you use all these very slightly longer vectors for an entire lap at Talladega, you get a measurable time difference. That’s because you’d have a teeny amount more downforce, and a teeny amount more cornering force, and a teeny amount more velocity, plus probably other effects that helped you go just a teeny amount faster! So there wasn’t a bug, but just a piling up of round-off error one way or another for an entire lap. Amazingly, the top twenty drivers in the Nascar iRacing Driver’s World Championship field qualified entirely within that accumulated round-off error!
So the mystery is now understood (and fixed with an update scheduled this week), and I can sleep better at night without these eerie Q circles interrupting my dreams. And you can just roll straight out of pitlane, confident that if other drivers are driving in a circle, they’re only making themselves dizzy.
What an amazing story. Sir, you are a freaking genius to have figured that all out. Wow.
Thats cool.
I’m so happy that you know math, love math and love racing.
Dave, I am a programmer by trade and had never, ever, heard of a q-bonian. A huge congratulations are in order, for correcting the problem and for explaining it in such an entertaining and informative way.
wow, that was some nice thinking and conclusion there – good job
Another head hurter VIA Kaemmer! I love it!
My head hurts.
My head hurts
Wow! I wish I was half that smart….. very gripping read too!
i love math.
Excellent read DK!!
Soooooo….. you left out the final conclusion!
Are we getting a positive or negative quaternion? Will we get the teeny bit faster or teeny bit slower lap now?
Excellent job at explaining a rather dry topic in an entertaining and informative fashion, Dave!
Couldn’t you just make that number a double or a decimal type?
Fantastic read and explantion. Everything made sense as I read it. Long live the King.
Nice job. Lucky you have Shannon there to hunt this kind of stuff down!
John: Sure, that may work by making the rounding error all that much smaller, but you would still have a (albeit much smaller) variance between odd and even laps. Not to mention now all the matrix math is using doubles causing performance slowdown. Also, I haven’t done game programming in a long time but I am guessing the Transformation matrices will still be floats at the graphics API level — you wouldn’t be able to throw the doubles at it.
Essentially your solution is like the “more power” approach: “This is running slow — instead of fixing the slow code lets just increase our minimum requirements!”
World’s greatest mathmetician, world’s worst choice in fashion accessories.
Awesome story…..even for us non-math types.
Searching for a hidden bug in code…. haha what fun. Read over it again and again, knowing you did it right, then all of a sudden it hits you what may be going on.
great read and explantion of the problem. Its good to see the developers explaining the problems and the way/time it took to debug the problem. Great work guys.
Dave you do know that you are nuts right?
Come on ! Descartes is the greatest !
The important question is: Why was Dave working on this and not the Tire Model!??!
j/k….great story and explanation!
and this will fix the guys that reset on pit road for Qualifying because when guys tow on pit road it simulates your truck being towed around the track there fore doing same thing as 1 circle
Great read hahaha. Thanks DK!
This blog made my evening. Thanks for sharing
you should be nominated for the noble prize…,. awsome job sir
Incredible story, thanks for sharing, it was amusing!
What a great math story. I’m dizzy from the math or the gimbal lock. Thanks, Dave. However, I say Tesla > Euler. But that’s subjective.
Thanks Dave, that was actually an awesome read, and I even understood most of it
Great to see the problem fixed.
Newton, Einstein, and now Kaemmer. That’s sweet man.
And iRacing thinks we have issues??? Pfft…:) WTG D\K
Unbelievable read sir! I now feel smarter for having read that, even though I didn’t understand a damn bit of what was said lol. All of this, just because of someone doing one small, little, itty, bitty circle and you have to bust out mathmatical formulas from the greatist mathmatician in history, to solve it. This whole write up is worth my year subscription plus content owned. Simply amaziing what you put into this company and hobby. Thank you for all you do Dave!
I kinda feel sick after reading all that.. a little dizzy too. Good find and thanks for taking care of the issue!
That is one of, if not the best article I have read here on iRacing so far as a member…Congrats on the find Dave!
from GPL to NASCAR4? wtf…if it only goes to nascar4 then why does iracing need updating?
weve been paying for this bug all along….
shouldnt ALL the iratings be reset?
who is to know who used this bug to gain irating?
makes me wonder what other bugs that are known by iracing
Now we can get back to racing.
Great hunting story Dave. I am glad I am here. Wish I knew where here is, but I am glad. LOL. Nice job, sir.
Great story! Thanks to as professional.
Years ago we played cards with guy thats turn around his chair to change his luck…. and its works!
I´ll go to look for quaternions and the rotation matrix of that chair right now!
can i sue for head trauma after reading that?………I settle for a free year, congrats on the finding that bugger
Thanks for writing this and letting us know that you figured it out… and how you figured it out. Perfect.
Great!! Brilliant! Now can you tackle the mystery of the “push all you want and yet go no where draft”.?
Please Please Pretty Please!!!
Now I an reminded of why I didn’t go to Rose-Hulman… And once again we all get another reminder of just how dedicated the iRacing staff is from the very top on down and what an immesne achievement this sim is… To any of you complaining about imperfections in iRacing, go develop your own sim!
Or do as I do and savor every moment immersed in (and never enough). I could never find a way to adequately thank those responsible for iRacing. It fills a void in my life i’ve had ever since I knew I would never be able to follow in my grandfathers and fathers tire tracks.
you should post this finding with the IEEE, I’m sure it would make for a great journal article and as a great tool for people who have overlooked this mistake. Congrats on the debug!
Told you so. :p
wow, congratulation, you must be really happy
and good story btw , thanks
LMFAO @ Paul Mahon.
Wow, the parts of that I could wrap my head around were gripping, congrats is definately due.
Who needs to drive in Circles?
I get dizzy just by reading this story.
You’ll sleep well. How about all of us, without knowing who the problem was fixed after all?
great captions on the pictures of mathematicians!
> So the mystery is now understood (and fixed with an update scheduled this week),
So how was it fixed? Always using one quaternation or using double precision math?
5 and 5 is 10 Dave!, i think!!. 15, plus years now in sim racing, and never gave up on you Bud. A 10+ Dave, and allway’s will be!!!. You are my Sim-Racing Hero!!!!!!!.
R John
Fixed it by always using the positive quaternion. The quaternion has to be “normalized” to unit length every time we update it, so now it just checks to see if the cosine part has become negative. If so, we flip the whole thing. Thanks for all the nice comments, guys–definitely is a lot of fun doing this work for an appreciative crowd!
That’s why I hate coding
Thanks for the great story about IRacing & Math. Nice to know that there are people out there who use math to create cool stuff.
Keep going on like this. Iracing is a great project
Thanks for posting this Dave. Its really nice to be treated as equal partners in IRacing, worthy of this level of explanation – rather than simply paying customers who aren’t expected to ask any awkward questions.
Well it’s not April 1st so I guess it must be true but I’m not going to pretend I understood any of it! Just Googled q-bonian and got no sensible results other than the article above so I’m not any clearer, other than impressed it got to be the 2nd result in a Google search in such a short period of time!!
Another problem explained by PI… PI is everything!
DK, you are a programming god and a genius! A metaphor of experience over youth in fixing the Q-circle mystery (though I hear Jesse Ventura has had to throw out an entire 40 minute show on account on this being snagged
)
THANK U!!!
u’re awesome Dave
Very enlightening. Never would have guessed that such a small variance would result in a very measurable change, overall. What an insight into the potential difficulty in creating an accurate model. Great read.
your my hero
It’s not hard to understand why this sim is so good.
We love you Dave!
The best mathematician this side of the Oxford campus. But even better – someone who can put it to use in very, very creative ways.
Amazing work Dave and a great read (even though I was lost with all the math jargin).
Damn, complex… Come to think of it it does remind me a little of a similar error in GPL’s times for uploading to GPLrank , where the thousandths could change sometimes or such. Glad the Q-circles have been fixed !
I have several friends who have zero interest in iRacing, yet keep bugging me as to when you’re going to write another technical piece Dave. They’re physics nuts who really enjoy reading about how you’re attacking and solving these physics issues in more then a theoretical way, since they are being used to represent things in a virtual reality. Its quite amazing.
They were big fans of the tyre piece and would love an even more detailed piece in that area if possible
I am am a Quaternion, the Planet Q-Bonian in the Rotation system. Resistance is futile.
In the real world programming, theres nothing as error propagation calculus I guess.
Just try and if the result is not correct, add some more digits to the presicion.
Is like this?
Hey Dave, great story & great work. THANK YOU!!!
Awsome work and a great read. I actually read it twice to let it sink in some more..
I wonder If William Rowan Hamilton is one of my distant relatives. Have to check the old family tree..
So in other words the top twenty fastest drivers in Iracing have used an exploit to get where they are. I think you need to hit the reset button.
Great stuff and good spot, coming from a fellow games programmer I know how hard it can be to sort that kind of problem, at least with crashes you usually know where to start looking
. Well done!
Must say I’m amazed at the accuracy of the top drivers, for a floating point error to make a noticeable difference to lap times is incredible.
I wanna go fast… thanks for doing the hard stuff.
I guess for some, the new advantage comes by using the identical rotation matrix in a reverse direction …drive the first qualifying lap in reverse, Of course that advantage goes to those who choose not to utilize this method of qualifying ![]()
By the way, Euler Rules!
I’ve been reading this very carefully well drinking some excellent west country English cider, and I must say: Very good indeed sir, Yes excellent.
Well… If you added a ‘tip’ to the $25.85 restaurant bill of let’s say… 20% (I’m a big tipper), then the total for the meal would be $31.02 with both paying $15.51 each. No negatives, leaving all parties (including the server) positive!! ![]()
So, is that how you fixed the problem? Leaving a ‘tip’ for the quaternion?
Seriously, a very interesting article. Great job and a great sense of humor!
awesome work sir…
I’m not even a member and stumbled across this article completely by accident. That, sir, was excellent debugging. My hat is off to you.
Great article, reminds me a bit of Star Trek TNG – Ship In A Bottle, where the ships holodeck spatial orientation system is malfuctioning and the characters catch objects in the incorrect hand. Anyway cheers for the read.
my eyes are bleeding and brain hurts. Great read. So the question remains. Was it cheating to use it or no? LOL
Thats what I have been trying to tell you….!
I simply love computers. I love also love programming them. I now realize I love simracers too. Without them we would never have discovered this mysterious and bizarre behaviour from iracing. I smile at the insight that racers always are trying to find an advantage, and then do so, if so in the most unthougt way -through a glitch in the code. I’m impressed by the fact that iracers found the glitch and especially the way to trick iracing that you´ve driven one extra lap by making a full circle in pit lane. The interesting thing is that it applies to every course, but was discovered by oval racers. How come none of the road track racers found out that every second lap was a little bit quicker?
Great read. It brings you an insight to the sometimes difficult to predict behaviour of computer programs. Good programming helps fixing and finding most flaws. But, as it seems, sim racers are needed to find all of them.:-)
Did you ever see that movie Office Space.. Didn’t rounding (errors) make the alot of money?
Great article! As someone who loves physics coding, Q-circling is probably the best math-related game exploit I’ve ever heard of.
I just renewed my subscription with a 3-months-for-$10 promotion code, and went to check the forums to see what’s new while the updates were downloaded and installed. I saw the link to this post, and let me tell you: this post alone was worth my $10! ![]()
Great job finding the bug, fixing it and writing this.
OK, off to the track…
If 1 bit is making noticeable difference then clearly you don’t use enough precision for important thing like that. You should use double float for it not just float (I believe that is 23bit mantissa not 24) and reduce the difference several million times.
Wikipedia + This article = 1+ IQ.
Thanks.
“I regard it as an inelegance, or imperfection, in quaternions, or rather in the state to which it has been hitherto unfolded, whenever it becomes or seems to become necessary to have recourse to x, y, z, etc.” — William Rowan Hamilton (ed. Quoted in a letter from Tait to Cayley).
Dave,
This is the most beautifully written story of a diabolical process I’ve ever seen. It should be clear to readers that the Q-Circle problem lay not the quaternion representation of rotation but in the construction of the rotation matrix from it.
It may be true that the transformation is demanded by the architecture of the current generation GPU, but if justice prevails, that will not always be the case. Some day, maybe closer now with the introduction of programming access to the GPU, vehicle state will be computed and maintained as a dual quaternion (the first one is the rotation quaternion that has become familiar to gamers and the second one expresses the position in space.) When the dual quaternion can be fed directly to the GPU and held in its registers, then the transformation to and from the abominable matrix will be unnecessary.
When that happens, I predict that Dave will do it first and iRacing will lead the chip manufacturers (by then both the graphics and physics – maybe soon after combined) into the necessary architecture changes.
Such great work, Dave.
Yes there should realize the opportunity to RSS commentary, quite simply, CMS is another on the blog.
- [...] [...]
- [...] full graphics, (i.e shadows, framerates, all the eye candy etc etc.) Minimum specs are listed on iRacings website, but it usually takes more than they recommend. And I should mention that iRacing is [...]
- I don't have much oval experience to make a comparison, but as far as road goes the new tire model is tons better. I hated flying off on an agricultural excursion after barely touching a gator. Once you lost grip after a certain point, it was like sliding on an oil slick and off you went. Now you can actually steer with the gas pedal. Great job!
- [...] found that I have achieved the "A" License in iRacing. An online simulated racing website(iRacing.com | The Premier Online Sim Racing Game). I went, in 5 months, from a Rookie License to the coveted "A" License. Now, on to the [...]
- iRacing: @kpulido315 You can run the Daytona 500 World Tour event on both Thursday night and Saturday afternoon. iRating on, Safety rating on.
- iRacing: COOL VIDEO: RT @vvvgamer: @iRacing Here's the link to the latest video http://t.co/4diKJjCs
- iRacing: iRacing @NASCAR Daytona 500 World Tour event begins tomorrow night. Will run on Saturday as well. Start time: see forum.
- iRacing: @vvvgamer Tweet us the video link : ) #welikecoolvids #iRacing
- No Pain, No Gain
- iRacing 2.0 update with Shane van Gisbergen
- The iRacing Stig Reviews the New Tire Model
- A Moving Experience
- The Mother of Sim Racing
Best round-off error story ever!!! Nice job debugging this one.
I love the evil fix idea too. That would’ve been one classy hack.