The source code
It is a Microsoft Visual Studio 2012 project with the name
WindowsFormsApplication1
The zip file is here:
Calculate-bicycle-speed.zip
Since I don't use C++, I could not figure out how to access the data
fields outside of the header file, so the calculations are done inside
Form1.h
The formula my software uses
In the 1980s, I read the book Bicycling
Science, which had a formula for calculating the speed of a bicycle.
I wrote three BASIC programs to do the calculations and create tables of
data.
I converted one of those basic programs into this C++ software in order
to make it more practical for modern computers.
The formula in the book (click
here for a scanned image of it) takes acceleration into account,
which I didn't want to deal with, so I simplified it to the following:
P: the power of the rider
V: the velocity of the bike
W: the weight of the bike and rider
E: the mechanical efficiency of the bike
R: the rolling resistance coefficient of the tires
S: the slope of the hill
H: the speed of the headwind (tailwinds are negative values)
d: the density of the air
c: effective aerodynamic cross sectional area of bike and rider. This
is the actual cross sectional area of the bike and rider multiplied by
the drag coefficient. You have to guess at the value to use for this variable
based on tables from wind tunnel experiments.
The problem with this formula is that you have to solve it for the variable
V in order to calculate the speed of a bicycle based on different weights,
etc. Not being much of a mathematician, it took me quite a while, and I
had to look in some math books for ideas on how to do it. The function
CalculateVelocity() does that calculation.
Is C++ truly an improvement over C?
Software is becoming increasingly complex. Ideally, we would
develop computer programming languages that make it easier for us
to develop software, but are we doing that right now?
In the 1980s, I wrote three simple BASIC programs to calculate
the effect of weight, tires, and air resistance on a bicycle, and to create
tables of data, and I decided to make a version that can run on modern
computers. So I decided to use Microsoft Visual Studio to create a more
modern version of the program.
To make the conversion easy, I wanted to use some of the tools that
Visual Studio provides, such as buttons and data entry fields. Unfortunately,
that required that I use the C++ language and the "classes" that Microsoft
created for those data-entry fields.
I consider the C++ "classes" to be a confusing variation of the
"structures" in C. Has anybody found proof that programmers who
use classes are more productive than those who use structures?
In the C language, the data entry fields would be "character" fields,
but Visual Studio describes them as "string" fields. What is a "string"?
How do I get access to the characters in the string?
I had to search the Internet to figure out how to do operations that
are extremely easy to do in C, and I noticed a lot of other people were
asking the same questions. How is this an improvement over character fields?
I also had to search the Internet to figure out how to set a label field.
I eventually found out that I can do it with these statements, even though
I don't know what the "^" means:
|
char tempBuf[88];
sprintf( tempBuf, "%.4f %s", velocity, labelPtr
);
String^ strNew = gcnew String( tempBuf );
Form1::outVelocityLabel->Text = strNew; |
I would need only one statement in C, such as:
sprintf( outVelocityLabel->Text,
"%.4f %s", velocity, labelPtr );
I also had to search the Internet to figure out how to access the data
in a data field. I found that I needed to use "Marshal":
|
char *ptr;
ptr = (char*) Marshal::StringToHGlobalAnsi( effBox->Text
).ToPointer();
efficiency = atof( (const char*)ptr );
Marshal::FreeHGlobal( IntPtr( ptr ) ); |
What is "Marshal"?
How is this an improvement over the C language?
In the C language, I would need only one simple statement:
efficiency = atof ( effBox->Text
);
Ideally, instead of following the latest programming language like we
follow the latest hairstyle, we would analyze programming languages in
a more serious manner, such as observing different groups of people who
use different languages, and determining which language is the most productive
for different tasks.
The Microsoft DirectX SDK has an arcball function that is written in
C++. I converted it to C just to see what the difference would be, and
I think the C version is easier to understand and use.
Engineering drawings need
modernization
This concept applies to more than just computer programming
languages. For example, engineers are creating blueprints as if this is
the 18th century. Specifically, they put measurements on the drawing as
if a person is going to use a wooden ruler or piece of string to measure
distances.
In this modern world, however, machinists are cutting most parts with
CNC machines, and CNC machines don't want measurements. They want XYZ coordinates.
It is easy to tell a milling machine to go from one XYZ coordinate to another,
but in order to tell it to cut along a line of 4.0254 units, somebody has
to do some calculations to figure out the coordinates at the beginning
and end of the line.
When cutting circular arcs, the CNC machine wants the center point of
the arc, its radius, and its two end points. It doesn't want measurements.
Likewise, it is easy to tell a milling machine to drill a hole when
the engineer specifies the coordinate of the center of the hole, but if
he says that the edge of the hole starts 4.0254 units away from some other
feature, somebody has to do some calculations to figure out where the center
of that hole is.
Machinists frequently have to waste time converting the measurements
of engineering drawings to XYZ coordinates. Engineers would reduce the
time it takes to make a part if they would put their drawings in a form
that was more appropriate to a modern CNC machinist.
|