Click here to Skip to main content
Click here to Skip to main content

C# Avionic Instrument Controls

, 17 Jul 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
The aim of this C# project is to purpose six aircraft cockpit instruments usable in forms as any other C# controls.


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.


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


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.


Let’s see step by step:

Step 0: Initial situation.


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


Corresponding code sample:

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

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


Corresponding code sample:

// 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.


Corresponding code sample:

// 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:


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:


The corresponding code sample is as follows:

// 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)));


  • "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



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


About the Author

France France
No Biography provided

Comments and Discussions

QuestionUpgraded altimeter PinmemberRedgum20-Nov-14 11:58 
Question!Need Help in Creating a VB.NET Avionics Intsrument Control Pinmemberschematicsman7-Jan-14 2:30 
QuestionHow to use these controls for an existing project PinmemberMember 1016504020-Jul-13 12:15 
QuestionHow to add these controls to my project? PinmemberBreaka18-Apr-13 16:34 
GeneralVery very nice Code Project sample... PinmemberDestiny77718-Sep-12 9:35 
QuestionAide Pinmemberbbjodel27-Jun-12 6:53 
QuestionVery nice controls PinmemberMike Hankey15-Apr-12 1:30 
QuestionImport to VB.Net PinmemberJTmetoo28-Aug-11 10:06 
QuestionGreat Job PinmemberLamar Seifuddin29-Jul-11 22:36 
GeneralRe: Great Job PinmemberDestiny77718-Sep-12 9:42 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150331.1 | Last Updated 17 Jul 2008
Article Copyright 2008 by Chootair
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid