As far as the math for determining this, it gets very involved and complicated. The basic formula is the same though, the cards you can hit to win / the total remaining cards unseen.
Now I'm sure the problem your having in the situation you posted is that you don't know the other players hole cards. That throws a wrench in the works.
Since you don't know the other players cards, the best way to calculate this would be to calculate all the other players chances of winning (using your hole cards to offset the available card pool).
Now, there is one piece of critical data you will need to get based on your hole cards before this will work, and that is what is the WEAKEST possible hand you can hit. This is the hand that the other player must beat to be included in your calculations. So when you run the calcs for the opponents, you must also include a check for every hand that says "can this beat our players weakest hand". Also, another check will be required that says "will this hand improve our players hand as such that it will beat this hand". If it will not beat our weakest hand or it will improve our hand enough to beat the opponents hand in that particular situation, we exclude it from the calculations described in the next paragraph.
Pre-flop you will have the same formula for opponent odds every time because you don't know the opponents hole cards and you don't know what's going to flop. So you simply create a function that calculates all the hands and what the odds are of hitting them, be sure to include a way to remove your hole cards (the only known cards at this time) from the available card pool. You then run the checks described in the above paragraph, removing any hands that don't qualify.
Then you aggregate the remaining data to determine each opponents chance of beating our player. You then only want to take the opponent with the highest chance of winning and compare with your player. As this type of calculation does not take into account players bets, bluffs, etc.. and only calculates based on the cards and their chance to hit so basically assumes every player is all in pre-flop if you want to simplify it. So you only need to compare with the guy who has the best chance of winning. It's hard to explain why, but its right. (I think, maybe, but not really. haha) :)
I really like the wizard of odds site, it has some great info...
as well as a calculator that i have been using myself when coding little programs and helpers and stuff to analyze my game...
Hope this helps a little, it's a big undertaking for sure as the calculations involved are pretty complicated. I'm probably going to play around with trying to code something like this just for my own personal education so keep us updated with your progress on this and I'll help along the way as much as I can with the math, calculations, etc..