Click here to Skip to main content
15,880,427 members
Articles / Programming Languages / C#

C# Avionic Instrument Controls

Rate me:
Please Sign up or sign in to vote.
4.91/5 (72 votes)
17 Jul 2008CPOL2 min read 336.4K   25.2K   197   63
The aim of this C# project is to purpose six aircraft cockpit instruments usable in forms as any other C# controls.
Image 1

Introduction

The aim of this C# project is to purpose six aircraft cockpit instruments usable in forms as any other C# controls and to define a generic instrument class in order to design any kind of dashboard instruments.

Description

The controls are built with bitmaps which are rotated, translated or scaled before to be displayed. The basic methods for rotate, translate and scale images are defined in the mother class. Each control then uses its dedicated parameters (related to a physical signification) in order to manipulates the images.

Aircraft Instruments

  • Air speed indicator: airspeed (kts)
  • Attitude Indicator: pitch (deg), roll (deg)
  • Altimeter: altitude (ft)
  • Turn Coordinator: turn rate (deg/min)
  • Vertical speed indicator: vertical speed (ft/min)
  • Heading indicator: heading (deg)

Details of the Key Functions

This section explains in detail the implementation of the basic functions defined in the InstrumentControl class.

Rotate Image

Implementation

The rotation of the image is divided in two main parts:

First, the rotation of the PaintEventArgs coordinate system around the upper left corner of the drawing area.

Second, the drawing of the image corrected by translation offset in order to display the image as if it has turned around a user defined point.

AvionicsControlDemo_RotationMainSteps.JPG

Let’s see step by step:

Step 0: Initial situation.

AvionicsControlDemo_RotationPhase0.JPG

Step 1: Rotate the PaintEventArgs coordinate system around the left upper corner of the paint area.

AvionicsControlDemo_RotationPhase1.JPG

Corresponding code sample:

C#
// Rotate image support
pe.Graphics.RotateTransform((float)(alpha * 180 / Math.PI));

Step 2: Draw the image and apply the translation correction.

AvionicsControlDemo_RotationPhase2.JPG

Corresponding code sample:

C#
// Display image
pe.Graphics.DrawImage(img, (ptImg.X + deltaX) * scaleFactor, (ptImg.Y + deltaY) * 
	scaleFactor, img.Width * scaleFactor, img.Height * scaleFactor);

Step 3 (Final step): Put the PainEventArgs coordinate system as found.

AvionicsControlDemo_RotationPhase3.JPG

Corresponding code sample:

C#
// Put image support as found
pe.Graphics.RotateTransform((float)(-alpha * 180 / Math.PI));

The key point in those operations is the calculation of the translation correction coefficients.

The next figure explains the geometrics considerations:

AvionicsControlDemo_RotationDetailedScheme.JPG

G0 is the user defined rotation center
G1 is the G0 position after the step 1.

The aim of this section is to identify the G1G0 translation and apply the corresponding offset in order to draw the rotation point as if it has not moved.

Then we work with the geometrics definitions:

a. AvionicsControlDemo_RotationCalcs1.JPG
b. AvionicsControlDemo_RotationCalcs2.JPG
c. AvionicsControlDemo_RotationCalcs3.JPG
d. AvionicsControlDemo_RotationCalcs4.JPG

As a result, the offset coefficients are:

AvionicsControlDemo_RotationCalcs5.JPG

The corresponding code sample is as follows:

C#
// Computed offset
deltaX = (float)(d * (Math.Cos(alpha - beta) - Math.Cos(alpha)* 
	Math.Cos(alpha + beta) - Math.Sin(alpha) * Math.Sin(alpha+ beta)));
deltaY = (float)(d * (Math.Sin(beta - alpha) + Math.Sin(alpha)* 
	Math.Cos(alpha + beta) - Math.Cos(alpha) * Math.Sin(alpha + beta)));

Parameters

  • "pe": The paint area event where the image will be displayed
  • "img": The image to display
  • "alpha": The angle of rotation in radian
  • "ptImg": The location of the left upper corner of the image to display in the paint area in nominal situation
  • "ptRot": The location of the rotation point in the paint area
  • "scaleFactor": Multiplication factor on the display image

AvionicsControlDemo_RotationFunctionParameters.JPG

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer
France France
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Fantastic job.... But there is something missing... Pin
Bill SerGio, The Infomercial King18-Jul-08 9:55
Bill SerGio, The Infomercial King18-Jul-08 9:55 
GeneralRe: Fantastic job.... But there is something missing... Shudder? Pin
Destiny77718-Sep-12 8:46
Destiny77718-Sep-12 8:46 
GeneralRe: Fantastic job.... But there is something missing... Shudder? Pin
Bill SerGio, The Infomercial King18-Sep-12 10:14
Bill SerGio, The Infomercial King18-Sep-12 10:14 
GeneralRe: Fantastic job.... But there is something missing... Shudder? Pin
Destiny7779-Oct-12 17:38
Destiny7779-Oct-12 17:38 
GeneralRe: Fantastic job.... But there is something missing... Shudder? Pin
Bill SerGio, The Infomercial King10-Oct-12 1:05
Bill SerGio, The Infomercial King10-Oct-12 1:05 
GeneralRe: Fantastic job.... But there is something missing... Shudder? Pin
Destiny77730-Dec-12 21:39
Destiny77730-Dec-12 21:39 
GeneralAH for 90 degree pitch Pin
jknickel8-Jul-08 0:24
professionaljknickel8-Jul-08 0:24 
GeneralRe: AH for 90 degree pitch Pin
Chootair17-Jul-08 11:59
Chootair17-Jul-08 11:59 
Thank you for your improvements on the code, it is cool.
About the altimeter scrolling it is true that is not as smooth as on real instrument. I tried several solution and I finally chose to just offset the draw of the "9". In fact my main constraint was that the number of digits could be defined as a function parameter so I do not difference the unit digit, the ten digit, the hundred digit ect... there are draw equals.
But I'll try to improve that, inspired by your solution.

Merci,
A plus.
GeneralGreat stuff Pin
jknickel7-Jul-08 22:54
professionaljknickel7-Jul-08 22:54 
GeneralSuperb but... Pin
Joe Sonderegger7-Jul-08 22:01
Joe Sonderegger7-Jul-08 22:01 
GeneralGreat work.... Pin
Peter Villadsen7-Jul-08 14:33
Peter Villadsen7-Jul-08 14:33 
GeneralRe: Great work.... Pin
Chootair17-Jul-08 12:03
Chootair17-Jul-08 12:03 
JokeImpressive Pin
Ivertheengine7-Jul-08 9:32
Ivertheengine7-Jul-08 9:32 
GeneralWow! Pin
Rafferty Uy3-Jul-08 15:48
Rafferty Uy3-Jul-08 15:48 
GeneralVery nice indeed. Question... Pin
thompsons2-Jul-08 6:42
thompsons2-Jul-08 6:42 
GeneralVery Good Pin
JBAK_CP2-Jul-08 3:41
JBAK_CP2-Jul-08 3:41 
GeneralRemarkable! Pin
LastZolex1-Jul-08 23:15
LastZolex1-Jul-08 23:15 
GeneralExcellento! Pin
Tage Lejon1-Jul-08 21:08
Tage Lejon1-Jul-08 21:08 
GeneralThis could be very cool Pin
Bert delaVega1-Jul-08 17:28
Bert delaVega1-Jul-08 17:28 
GeneralAlitmeter Pin
sgenie681-Jul-08 14:17
sgenie681-Jul-08 14:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.