![]() |
Desktop Development »
Miscellaneous »
Custom Controls
Beginner
License: The Code Project Open License (CPOL)
C# avionic instrument controlsBy ChootairThe aim of this C# project is to purpose six aircraft cockpit instruments usable in forms as any other C# controls |
C# (C# 2.0), .NET (.NET 2.0)
|
||||||||||
|
Advanced Search |
|
|
|
||||||||||||||||
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 instuments.
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 his dedicated parameters (related
to a physical signification) in order to manipulates the images .
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)
Second : the drowing 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 applies the translation correction
Corresponding code sample :
// Dispay 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 explain 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 identified the G1G0 translation and applied the corresponding offset in order to
draw the rotation point as if it has not moved.
a)
c)
d)
As a result the offset coefficients are :
Corresponding
code sample :
// 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
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 17 Jul 2008 Editor: |
Copyright 2008 by Chootair Everything else Copyright © CodeProject, 1999-2009 Web13 | Advertise on the Code Project |