Jump to content
The simFlight Network Forums

Traffic Radar


Recommended Posts

Pete

I am making a Traffic radar program just like TrafficLook, however my radar screen is "plane is north". If you get what I mean. I have been using the Aviation Formulary at http://williams.best.vwh.net/avform.htm.

I can work out the distance and the bearing from the current aircraft to the AI traffic, however I am unable to present it on the Radar screen. I have also been using trigonometry, however I am not familiar with it.

I was wondering if you could show me an example of how you present the traffic in TrafficLook. It would be much appriated. Thanks

CRaig

Link to comment
Share on other sites

I can work out the distance and the bearing from the current aircraft to the AI traffic, however I am unable to present it on the Radar screen. I have also been using trigonometry, however I am not familiar with it.

If you have distance and bearing (d, b) then you can convert that to some x, y coordinates for a Radar screen. It's simple trig isn't it? Tell me where you are stuck.

To keep things easy I tend to do this sort of trig in the four quadrants separately -- saves confusion with signs and so on. For the first quadrant (bearing 0-90, Forward/Right), the (x,y) plot position would be:

x = d * cos(b)

y = d * sin(b)

after converting b to radians of course ( *PI / 180).

The other quadrants are variations of this with different sinces and +/-90 sort of fixes.

On the other hand, just to map positions relative to the aircraft you don't need distance and bearing. Just use the Lat/Long values, made relative to the user aircraft by subtracting the latter. However, then you'd need to rotate the relative (x,y) coordinates to get bearing up, so you might be better off using distance and bearing in any case.

I was wondering if you could show me an example of how you present the traffic in TrafficLook.

But TrafficLook merely lists the data, including distance and bearing. it doesn't draw a map. You already have the data that TrafficLook has.

Regards,

Pete

Link to comment
Share on other sites

I have already used the functions to find out each X and Y, however it does not seem to work.Are the X and Y formulas the same for each quadrant? For example: Bearing > 0 and <90

b=Bearing

nm = Distance (nm)

x=Cos(b / (180/PI)) * nm

y=Sin(b/ (180/PI)) * nm

I am stuck on finding the x and y lengths. What are the other X and Y formulas for each quadrant?

Thanks

Craig

Link to comment
Share on other sites

I have already used the functions to find out each X and Y, however it does not seem to work.Are the X and Y formulas the same for each quadrant? For example: Bearing > 0 and <90

b=Bearing

nm = Distance (nm)

x=Cos(b / (180/PI)) * nm

y=Sin(b/ (180/PI)) * nm

I am stuck on finding the x and y lengths. What are the other X and Y formulas for each quadrant?

Thanks

Craig

For 90-180 you can either use the formae exactly as above (sin goes -ve from 90-180), or, for clarity of thought, subtract the bearing from 180 and then do as above, but reversing the sign of y.

Draw yourself a little picture. It will all be clear then

180-270 is similar, just subtract 180 and reverse signs on both x and y.

270-360 subtract from 360, reverse the sign of the x value.

Regards,

Pete

Link to comment
Share on other sites

Yep done all that and it still is not working. Any other suggestions?

There's nothing to go wrong if you got the trig correct. What does "not working" mean? I assume you've scaled it to fit your graphics. Don't ask me about graphics, i've no idea about that.

Pete

Link to comment
Share on other sites

I did notice a problem that I had with retreiving the traffic data, however that is now resolved.

Here is a snipbit of the code, it is in Visual Basic, but it should be easy enough to understand:

gcbearing = the bearing from current plane to one of the traffic

nmm = is the distance between the two planes in Nautical Miles

The Mod function cancels a number down, for example:

369 Mod 360 = 9

180 Mod 90 = 90

181 Mod 90 = 1

(180 / (4 * Atn(1))) = is the radians

127.5 = is the ratio to draw on the radar

po = gcbearing Mod 90
po = gcbearing / (180 / (4 * Atn(1)))

'Find the height
hi = (Sin(po) * nmm) * 127.3125 

'Find the length
lo = (Cos(po) * nmm) * 127.3125


'Plot the planes on the radar screen
If gcbearing &gt; 0 And gcbearing &lt; 90 Then
plane1(i).Top = (plane1(0).Top + hi + (plane1(i).Height / 2)) * 1
plane1(i).Left = (plane1(0).Left + lo + (plane1(i).Width / 2)) * 1
ElseIf gcbearing &gt; 90 And gcbearing &lt; 180 Then
plane1(i).Top = (plane1(0).Top + hi + (plane1(i).Height / 2)) * 1
plane1(i).Left = (plane1(0).Left + lo + (plane1(i).Width / 2)) * 1
ElseIf gcbearing &gt; 180 And gcbearing &lt; 270 Then
plane1(i).Top = (plane1(0).Top + hi + (plane1(i).Height / 2)) * 1
plane1(i).Left = (plane1(0).Left + lo + (plane1(i).Width / 2)) * 1
ElseIf gcbearing &gt; 270 And gcbearing &lt; 360 Then
plane1(i).Top = (plane1(0).Top + hi - (plane1(i).Height / 2)) * 1
plane1(i).Left = (plane1(0).Left + lo - (plane1(i).Width / 2)) * 1
End If

I hope this is understandable.

Thanks

Craig

Link to comment
Share on other sites

The Mod function cancels a number down, for example:

369 Mod 360 = 9

180 Mod 90 = 90

181 Mod 90 = 1

I'm pretty sure the middle one is wrong. 180 Mod 90 should be 0. This is the same as the % operation in C/C++.

(180 / (4 * Atn(1))) = is the radians

What an odd way to do it. Don't you have PI defined as a constant? An angle of 45 degrees provides a Tan of 1.0, so the ATAN of 1 will give the radian equivalent of 45 degrees, but it's an odd way.

127.5 = is the ratio to draw on the radar

Don't know what that means. And it isn't used below. You use 127.3125 instead?

If gcbearing > 0 And gcbearing < 90 Then

ElseIf gcbearing > 90 And gcbearing < 180 Then

ElseIf gcbearing > 180 And gcbearing < 270 Then

ElseIf gcbearing > 270 And gcbearing < 360 Then

You exclude exactly 0, 90, 180, 270 from possibility?

Sorry, but you need to use a debugger to find out what is wrong. I assume VB comes with a debugger so you can trace through the results? If not, I would strongly advise a change of language. debuggers are essential.

Regards,

Pete

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.