programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Liutauras Vilda
• Paul Clapham
Sheriffs:
• paul wheaton
• Tim Cooke
• Henry Wong
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Piet Souris
Bartenders:
• Mike London

# [Math] Draw Line Yaw

Greenhorn
Posts: 13
• Number of slices to send:
Optional 'thank-you' note:
Hello!

I'm in the middle of developing SWING panel based flight attitude indicator, and I'm having trouble with the yaw.

So basically, I need a line to change it's orientation based on the yaw. The yaw will go between -60 (turning far left) and +60 (turning far right) with 0 being level.

How would I draw a line to change the line based on the yaw?

Marshal
Posts: 27536
88
• Number of slices to send:
Optional 'thank-you' note:
Hi Brandon, welcome to the Ranch!

I think the short answer is, you're going to have to use some trigonometry.

But that probably isn't too helpful. We need more details to give a better answer. I'm guessing you want something like a dial displaying a yaw value and you want a needle in that dial. With 0 you'd have the needle pointing straight up, and with -60 you'd have it pointing horizontally to the left, and so on. Is that right?

And would it be fair to assume that your code is just getting a yaw number as input from some other part of the code? Or is part of your problem getting that number in the first place?

author
Posts: 23931
142
• Number of slices to send:
Optional 'thank-you' note:

Brandon Johnson wrote:Hello!

I'm in the middle of developing SWING panel based flight attitude indicator, and I'm having trouble with the yaw.

So basically, I need a line to change it's orientation based on the yaw. The yaw will go between -60 (turning far left) and +60 (turning far right) with 0 being level.

How would I draw a line to change the line based on the yaw?

First, it has been many many years since I sat in a cockpit, so much stuff may have changed since then... Anyway, I thought the attitude indicator was good for pitch and bank only. For yaw, I remember using mainly the turn and slip indicator -- that's assuming that I even cared much about yaw ...

Henry

Brandon Johnson
Greenhorn
Posts: 13
• Number of slices to send:
Optional 'thank-you' note:

Henry Wong wrote:

Brandon Johnson wrote:Hello!

I'm in the middle of developing SWING panel based flight attitude indicator, and I'm having trouble with the yaw.

So basically, I need a line to change it's orientation based on the yaw. The yaw will go between -60 (turning far left) and +60 (turning far right) with 0 being level.

How would I draw a line to change the line based on the yaw?

First, it has been many many years since I sat in a cockpit, so much stuff may have changed since then... Anyway, I thought the attitude indicator was good for pitch and bank only. For yaw, I remember using mainly the turn and slip indicator -- that's assuming that I even cared much about yaw ...

Henry

Paul Clapham
Marshal
Posts: 27536
88
• Number of slices to send:
Optional 'thank-you' note:

Henry Wong wrote:that's assuming that I even cared much about yaw ...

When I see "yaw" I always have to pause and figure out what it is. Basically it's the direction which isn't pitch or roll. Not that you need to know that to answer the OP's question, at least not at this point.

Brandon Johnson
Greenhorn
Posts: 13
• Number of slices to send:
Optional 'thank-you' note:

Paul Clapham wrote:Hi Brandon, welcome to the Ranch!

I think the short answer is, you're going to have to use some trigonometry.

But that probably isn't too helpful. We need more details to give a better answer. I'm guessing you want something like a dial displaying a yaw value and you want a needle in that dial. With 0 you'd have the needle pointing straight up, and with -60 you'd have it pointing horizontally to the left, and so on. Is that right?

And would it be fair to assume that your code is just getting a yaw number as input from some other part of the code? Or is part of your problem getting that number in the first place?

Hi, and thanks!

So here are some examples (Just realized I wrote right instead of left in the image, it's supposed to be left).

As you can see on the bank left photo, it's at a weird angle, and the red line is much longer than it should be. I want it to scale, stay the same length, and turn completely vertical to show a vertical bank. The bank variable at -60 is full bank left (vertical, wings straight up), 0 is level flight, then +60 is full bank rhgt vertical wings straight up.

Paul Clapham
Marshal
Posts: 27536
88
• Number of slices to send:
Optional 'thank-you' note:
So you want the red line to always be the same length, and to just rotate about its centre point?

If that's the case, then it's like this. When the line is horizontal, then it extends from (-1, 0) to (1, 0) if you put the origin of the coordinate system at the centre of the red line and scale the size appropriately. Then to draw a line of the same length which is rotated by an angle A, the line extends from (-cos A, -sin A) to (cos A, sin A).

Bear in mind that the methods in the Math class (like Math.sin) require a number of radians as their argument, not degrees. (The Math class has methods to convert between degrees and radians.) You'll also have to convert your coordinate system where 60 is a quarter of a circle into degrees, where 90 is a quarter of a circle.

The math is picky in that it's easy to get signs wrong and things like that.

Brandon Johnson
Greenhorn
Posts: 13
• Number of slices to send:
Optional 'thank-you' note:

Paul Clapham wrote:So you want the red line to always be the same length, and to just rotate about its centre point?

If that's the case, then it's like this. When the line is horizontal, then it extends from (-1, 0) to (1, 0) if you put the origin of the coordinate system at the centre of the red line and scale the size appropriately. Then to draw a line of the same length which is rotated by an angle A, the line extends from (-cos A, -sin A) to (cos A, sin A).

Bear in mind that the methods in the Math class (like Math.sin) require a number of radians as their argument, not degrees. (The Math class has methods to convert between degrees and radians.) You'll also have to convert your coordinate system where 60 is a quarter of a circle into degrees, where 90 is a quarter of a circle.

The math is picky in that it's easy to get signs wrong and things like that.

I hate to ask like this, but could you by chance give me an example of what you mean? I'm ready to pull my hair out with this.

The Jpanel bounds are 720x320.

This is why I am using currently:

This has to be dead accurate, it's going to be used in flying a drone. I appreciate your help!

Henry Wong
author
Posts: 23931
142
• Number of slices to send:
Optional 'thank-you' note:

Brandon Johnson wrote:
As you can see on the bank left photo, it's at a weird angle, and the red line is much longer than it should be. I want it to scale, stay the same length, and turn completely vertical to show a vertical bank. The bank variable at -60 is full bank left (vertical, wings straight up), 0 is level flight, then +60 is full bank rhgt vertical wings straight up.

Actually, this is not correct. A left turn, with the plane's wings vertical relative to the ground, is a 90 degree turn -- not a 60 degree turn. Also, very few planes can do that -- as the wings are no longer holding the plane up anymore.

Henry

Brandon Johnson
Greenhorn
Posts: 13
• Number of slices to send:
Optional 'thank-you' note:

Henry Wong wrote:

Brandon Johnson wrote:
As you can see on the bank left photo, it's at a weird angle, and the red line is much longer than it should be. I want it to scale, stay the same length, and turn completely vertical to show a vertical bank. The bank variable at -60 is full bank left (vertical, wings straight up), 0 is level flight, then +60 is full bank rhgt vertical wings straight up.

Actually, this is not correct. A left turn, with the plane's wings vertical relative to the ground, is a 90 degree turn -- not a 60 degree turn. Also, very few planes can do that -- as the wings are no longer holding the plane up anymore.

Henry

Well I know that being technical, but not in the scale I'm using.

Also, this aircraft doesn't have wings, I was just explaining :).

I'm OK with staying on the proper scale of 90 degrees, but I'll have to rework some stuff.

Henry Wong
author
Posts: 23931
142
• Number of slices to send:
Optional 'thank-you' note:

Brandon Johnson wrote:
Well I know that being technical, but not in the scale I'm using.

Also, this aircraft doesn't have wings, I was just explaining .

I'm OK with staying on the proper scale of 90 degrees, but I'll have to rework some stuff.

One more nitpick... ... With attitude indicators, the "plane" component doesn't move. It is always level and center on the indicator. In fact, many older indicators, the plane is drawn on the glass panel itself. Anyway, it is the background that moves -- meaning when the actual plane turns left, on the indicator, it is the horizon (sky/ground color stuff) that rotates clockwise. Remember that the indicator is designed to show the attitude from the pilot's point of reference -- and most pilots fly planes from inside the plane.

Henry

Brandon Johnson
Greenhorn
Posts: 13
• Number of slices to send:
Optional 'thank-you' note:

Henry Wong wrote:

Brandon Johnson wrote:
Well I know that being technical, but not in the scale I'm using.

Also, this aircraft doesn't have wings, I was just explaining :).

I'm OK with staying on the proper scale of 90 degrees, but I'll have to rework some stuff.

One more nitpick... :) ... With attitude indicators, the "plane" component doesn't move. It is always level and center on the indicator. In fact, many older indicators, the plane is drawn on the glass panel itself. Anyway, it is the background that moves -- meaning when the actual plane turns left, on the indicator, it is the horizon (sky/ground color stuff) that rotates clockwise. Remember that the pilot should be inside the plane, and the indicator is designed to show the attitude from his/her point of reference.

Henry

Yeah I was thinking of ways to implement that, maybe later down the road. Right now I'm just trying to finish this rough draft, building a flight controller for a hexacopter drone I'm working on.

Bartender
Posts: 3323
86
• Number of slices to send:
Optional 'thank-you' note:
Another potential issue is if your full bank left and your full bank right are both represented as a vertical line, when you are looking at a vertical line you only know you are in a full bank but you don't know which way you are banking. You could draw the left half of the line in red and the right half in green to represent the port and starboard wings so when the line is vertical you can see which wing is pointing up and which is pointing down and hence which way you are banking.

Paul Clapham
Marshal
Posts: 27536
88
• Number of slices to send:
Optional 'thank-you' note:
Well, let's start by simplifying your code a bit. It can be reduced to this:

So, you want your line to be 100 units long and you want it to be centred at (360, 160). And you want it to rotate based on the value of the "bank" variable. So the value you're looking for is (360, 160) + 50 * (cos(bank in radians), sin(bank in radians)) for one of the ends.

Brandon Johnson
Greenhorn
Posts: 13
• Number of slices to send:
Optional 'thank-you' note:

Paul Clapham wrote:Well, let's start by simplifying your code a bit. It can be reduced to this:

So, you want your line to be 100 units long and you want it to be centred at (360, 160). And you want it to rotate based on the value of the "bank" variable. So the value you're looking for is (360, 160) + 50 * (cos(bank in radians), sin(bank in radians)) for one of the ends.

Cool thanks :). I'll try it out.

Brandon Johnson
Greenhorn
Posts: 13
• Number of slices to send:
Optional 'thank-you' note:

Tony Docherty wrote:Another potential issue is if your full bank left and your full bank right are both represented as a vertical line, when you are looking at a vertical line you only know you are in a full bank but you don't know which way you are banking. You could draw the left half of the line in red and the right half in green to represent the port and starboard wings so when the line is vertical you can see which wing is pointing up and which is pointing down and hence which way you are banking.

I've put in place audible warnings to prevent this, thanks though!

Brandon Johnson
Greenhorn
Posts: 13
• Number of slices to send:
Optional 'thank-you' note:
Instead of adding the line rotation, I decided to use Graphics2D AffineTransform's and rotate the background as well as the degree indicators, while having the plane line remain static. Thanks guys! Now to find a better looking way to draw the degrees/make them move fluidly.

Henry Wong
author
Posts: 23931
142
• Number of slices to send:
Optional 'thank-you' note:

Brandon Johnson wrote:

Tony Docherty wrote:Another potential issue is if your full bank left and your full bank right are both represented as a vertical line, when you are looking at a vertical line you only know you are in a full bank but you don't know which way you are banking. You could draw the left half of the line in red and the right half in green to represent the port and starboard wings so when the line is vertical you can see which wing is pointing up and which is pointing down and hence which way you are banking.

I've put in place audible warnings to prevent this, thanks though!

Brandon Johnson wrote:Instead of adding the line rotation, I decided to use Graphics2D AffineTransform's and rotate the background as well as the degree indicators, while having the plane line remain static. Thanks guys! Now to find a better looking way to draw the degrees/make them move fluidly.

BTW, your new change also solves the previous issue. A full right bank has the ground on the right, while a full left bank has the sky on the right. It is now easy to tell the two apart. Heck, if you like, you can even do a barrel roll and the indicator can be correct throughout the whole maneuver (meaning that there is a representation for everything in the maneuver).

Good job...

Henry

Brandon Johnson
Greenhorn
Posts: 13
• Number of slices to send:
Optional 'thank-you' note:

Henry Wong wrote:

Brandon Johnson wrote:

Tony Docherty wrote:Another potential issue is if your full bank left and your full bank right are both represented as a vertical line, when you are looking at a vertical line you only know you are in a full bank but you don't know which way you are banking. You could draw the left half of the line in red and the right half in green to represent the port and starboard wings so when the line is vertical you can see which wing is pointing up and which is pointing down and hence which way you are banking.

I've put in place audible warnings to prevent this, thanks though!

Brandon Johnson wrote:Instead of adding the line rotation, I decided to use Graphics2D AffineTransform's and rotate the background as well as the degree indicators, while having the plane line remain static. Thanks guys! Now to find a better looking way to draw the degrees/make them move fluidly.

BTW, your new change also solves the previous issue. A full right bank has the ground on the right, while a full left bank has the sky on the right. It is now easy to tell the two apart. Heck, if you like, you can even do a barrel roll and the indicator can be correct throughout the whole maneuver (meaning that there is a representation for everything in the maneuver).

Good job...

Henry

Now Henry, I'm hoping you can help me with one last thing.

So here's my current code for displaying pitch degrees:

I'm trying to think of an efficient way to have the lines move as the pitch moves, instead of staying static and just having the numbers change. Any thoughts?

Henry Wong
author
Posts: 23931
142
• Number of slices to send:
Optional 'thank-you' note:

Brandon Johnson wrote:
I'm trying to think of an efficient way to have the lines move as the pitch moves, instead of staying static and just having the numbers change. Any thoughts?

Well, it is more than just lines, you need to move the horizon too -- meaning you should see more sky in a climb, and more ground in a dive.

Unfortunately, I don't know of an efficient way to do this in one pass, but with two passes, I guess you can shift the background up or down to account for pitch, and then rotate it to account for bank.

Henry

Brandon Johnson
Greenhorn
Posts: 13
• Number of slices to send:
Optional 'thank-you' note:

Henry Wong wrote:

Brandon Johnson wrote:
I'm trying to think of an efficient way to have the lines move as the pitch moves, instead of staying static and just having the numbers change. Any thoughts?

Well, it is more than just lines, you need to move the horizon too -- meaning you should see more sky in a climb, and more ground in a dive.

Unfortunately, I don't know of an efficient way to do this in one pass, but with two passes, I guess you can shift the background up or down to account for pitch, and then rotate it to account for bank.

Henry

The background already moves as it's supposed to. I'm just trying to figure out the lines themselves.

Henry Wong
author
Posts: 23931
142
• Number of slices to send:
Optional 'thank-you' note:

Brandon Johnson wrote:
The background already moves as it's supposed to. I'm just trying to figure out the lines themselves.

Aren't the lines in a fixed position relative to the background? Meaning is drawing the lines onto the background buffer, and then shift and rotate the background (with the lines) an option?

Henry

Brandon Johnson
Greenhorn
Posts: 13
• Number of slices to send:
Optional 'thank-you' note:

Henry Wong wrote:

Brandon Johnson wrote:
The background already moves as it's supposed to. I'm just trying to figure out the lines themselves.

Aren't the lines in a fixed position relative to the background? Meaning is drawing the lines onto the background buffer, and then shift and rotate the background (with the lines) an option?

Henry

Yes Henry.

Here, I'll upload a video of how it currently operates. It will be easier to explain.

Brandon Johnson
Greenhorn
Posts: 13
• Number of slices to send:
Optional 'thank-you' note:

Brandon Johnson wrote:

Henry Wong wrote:

Brandon Johnson wrote:
The background already moves as it's supposed to. I'm just trying to figure out the lines themselves.

Aren't the lines in a fixed position relative to the background? Meaning is drawing the lines onto the background buffer, and then shift and rotate the background (with the lines) an option?

Henry

Yes Henry.

Here, I'll upload a video of how it currently operates. It will be easier to explain.