常见速度术语,速度单位有马赫,节,码,迈,千米/时(公里/时),米/秒.
千米/时(公里/时:km/h),米/秒:(m/s)
1m/s=3.6km/h
最常用的速度单位,汽车中多用码来代表千米每小时,比如72码就是72千米每小时,也就是20米每秒
马赫(Mach)
多用于战机,导弹,火箭的速度
马赫(Mach)是表示速度相对于声速的倍数的单位。1马赫等于声速的速度,在标准大气压和温度为15摄氏度时,声速大约为1225.1千米每小时,或者约为340.3米每秒。
一马赫即一倍音速:马赫数小于1者为亚音速,马赫数大于5左右为超高音速;马赫数是飞行的速度和当时飞行的音速之比值,大于1表示比音速快,同理,小于1是比音速慢。
节(knot)
多用于舰船,民航速度
节(knot)是航海和航空中常用的速度单位,1节等于1海里每小时。1海里等于1852米,因此1节相当于1852米每小时,或者大约0.5144米每秒。
码(yard)
多用于汽车速度
码,就是千米每小时 或者公里每小时. 时速60码其意思就是60公里每小时,这也是最常用的时速单位
迈(mph)
多用于汽车速度
表示英里每小时(mph,全称miles-per-hour,俗称“迈”)。是一速度计量单位,表示英里/每小时。1迈=1.609344公里/小时。
为了方便运算,这里,我们全部以千米每时(km/h)作为统一单位,
规定声速为340m/s,海里为1852m/h,迈为1609m/h
新建窗体应用程序SpeedUnitDemo,将默认的Form1重命名为FormSpeedUnit
窗体FormSpeedUnit设计如下:
窗体设计器代码如下:
文件FormSpeedUnit.Designer.cs
namespace SpeedUnitDemo
{
partial class FormSpeedUnit
{
///
/// 必需的设计器变量。
///
private System.ComponentModel.IContainer components = null;
///
/// 清理所有正在使用的资源。
///
/// 如果应释放托管资源,为 true;否则为 false。
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
///
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
///
private void InitializeComponent()
{
this.dgvSpeed = new System.Windows.Forms.DataGridView();
this.dgvcSpare = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dgvcKmh = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dgvcMs = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dgvcMach = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dgvcKnot = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dgvcYard = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dgvcMph = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.rtxtMessage = new System.Windows.Forms.RichTextBox();
((System.ComponentModel.ISupportInitialize)(this.dgvSpeed)).BeginInit();
this.SuspendLayout();
//
// dgvSpeed
//
this.dgvSpeed.AllowUserToAddRows = false;
this.dgvSpeed.AllowUserToDeleteRows = false;
this.dgvSpeed.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvSpeed.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.dgvcSpare,
this.dgvcKmh,
this.dgvcMs,
this.dgvcMach,
this.dgvcKnot,
this.dgvcYard,
this.dgvcMph});
this.dgvSpeed.Location = new System.Drawing.Point(12, 12);
this.dgvSpeed.Name = "dgvSpeed";
this.dgvSpeed.ReadOnly = true;
this.dgvSpeed.RowHeadersWidth = 23;
this.dgvSpeed.RowTemplate.Height = 23;
this.dgvSpeed.Size = new System.Drawing.Size(1042, 300);
this.dgvSpeed.TabIndex = 0;
this.dgvSpeed.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvSpeed_CellContentClick);
this.dgvSpeed.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvSpeed_CellContentClick);
//
// dgvcSpare
//
this.dgvcSpare.HeaderText = "速度单位A/速度单位B";
this.dgvcSpare.Name = "dgvcSpare";
this.dgvcSpare.ReadOnly = true;
this.dgvcSpare.Width = 160;
//
// dgvcKmh
//
this.dgvcKmh.HeaderText = "千米/时(km/h)";
this.dgvcKmh.Name = "dgvcKmh";
this.dgvcKmh.ReadOnly = true;
this.dgvcKmh.Width = 150;
//
// dgvcMs
//
this.dgvcMs.HeaderText = "米/秒(m/s)";
this.dgvcMs.Name = "dgvcMs";
this.dgvcMs.ReadOnly = true;
this.dgvcMs.Width = 140;
//
// dgvcMach
//
this.dgvcMach.HeaderText = "马赫(Mach)";
this.dgvcMach.Name = "dgvcMach";
this.dgvcMach.ReadOnly = true;
this.dgvcMach.Width = 140;
//
// dgvcKnot
//
this.dgvcKnot.HeaderText = "节(knot)";
this.dgvcKnot.Name = "dgvcKnot";
this.dgvcKnot.ReadOnly = true;
this.dgvcKnot.Width = 140;
//
// dgvcYard
//
this.dgvcYard.HeaderText = "码(yard)";
this.dgvcYard.Name = "dgvcYard";
this.dgvcYard.ReadOnly = true;
this.dgvcYard.Width = 140;
//
// dgvcMph
//
this.dgvcMph.HeaderText = "迈(mph)";
this.dgvcMph.Name = "dgvcMph";
this.dgvcMph.ReadOnly = true;
this.dgvcMph.Width = 140;
//
// rtxtMessage
//
this.rtxtMessage.Location = new System.Drawing.Point(12, 318);
this.rtxtMessage.Name = "rtxtMessage";
this.rtxtMessage.ReadOnly = true;
this.rtxtMessage.Size = new System.Drawing.Size(1040, 188);
this.rtxtMessage.TabIndex = 1;
this.rtxtMessage.Text = "";
//
// FormSpeedUnit
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1064, 531);
this.Controls.Add(this.rtxtMessage);
this.Controls.Add(this.dgvSpeed);
this.Name = "FormSpeedUnit";
this.Text = "速度单位换算表格(行列式)";
this.Load += new System.EventHandler(this.FormSpeedUnit_Load);
((System.ComponentModel.ISupportInitialize)(this.dgvSpeed)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataGridView dgvSpeed;
private System.Windows.Forms.DataGridViewTextBoxColumn dgvcSpare;
private System.Windows.Forms.DataGridViewTextBoxColumn dgvcKmh;
private System.Windows.Forms.DataGridViewTextBoxColumn dgvcMs;
private System.Windows.Forms.DataGridViewTextBoxColumn dgvcMach;
private System.Windows.Forms.DataGridViewTextBoxColumn dgvcKnot;
private System.Windows.Forms.DataGridViewTextBoxColumn dgvcYard;
private System.Windows.Forms.DataGridViewTextBoxColumn dgvcMph;
private System.Windows.Forms.RichTextBox rtxtMessage;
}
}
FormSpeedUnit相关代码如下:
文件FormSpeedUnit.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SpeedUnitDemo
{
public partial class FormSpeedUnit : Form
{
///
/// 声速为340m/s
///
const decimal soundVelocity = 340M;//声速为340m/s
///
/// 1海里=1852m
///
const decimal mile = 1852M;//1海里=1852m
///
/// 1迈=1609m
///
const decimal mph = 1609M;//1迈=1609m
///
/// 米每秒 与 千米每小时的换算关系 1m/s=3.6km/h
///
const decimal rate = 3.6M;//1m/s=3.6km/h
public FormSpeedUnit()
{
InitializeComponent();
/*
* 为了方便运算,这里,我们全部以千米每时(km/h)作为统一单位,
* 规定声速为340m/s,
* 海里为1852m/h,
* 迈为1609m/h
*/
dgvSpeed.AutoGenerateColumns = false;
dgvcSpare.DataPropertyName = "SpeedUnit";
dgvcKmh.DataPropertyName = "Kmh";
dgvcMs.DataPropertyName = "Ms";
dgvcMach.DataPropertyName = "Mach";
dgvcKnot.DataPropertyName = "Knot";
dgvcYard.DataPropertyName = "Yard";
dgvcMph.DataPropertyName = "Mph";
}
private void FormSpeedUnit_Load(object sender, EventArgs e)
{
DataTable dataTable = new DataTable("SpeedUnit");
dataTable.Columns.Add("SpeedUnit", typeof(string));
dataTable.Columns.Add("Kmh", typeof(decimal));
dataTable.Columns.Add("Ms", typeof(decimal));
dataTable.Columns.Add("Mach", typeof(decimal));
dataTable.Columns.Add("Knot", typeof(decimal));
dataTable.Columns.Add("Yard", typeof(decimal));
dataTable.Columns.Add("Mph", typeof(decimal));
//全部换算为千米每小时,统一单位km/h
decimal oneKmh = 1M;//千米每小时
decimal oneMs = rate;//米每秒
decimal oneMach = rate * soundVelocity;//马赫
decimal oneKnot = mile / 1000;//节
decimal oneYard = oneKmh;//码,就是千米每小时
decimal oneMph = mph / 1000;//迈
dataTable.Rows.Add("千米/时(km/h)", oneKmh / oneKmh, oneKmh / oneMs, oneKmh / oneMach, oneKmh / oneKnot, oneKmh / oneYard, oneKmh / oneMph);
dataTable.Rows.Add("米/秒(m/s)", oneMs / oneKmh, oneMs / oneMs, oneMs / oneMach, oneMs / oneKnot, oneMs / oneYard, oneMs / oneMph);
dataTable.Rows.Add("马赫(Mach)", oneMach / oneKmh, oneMach / oneMs, oneMach / oneMach, oneMach / oneKnot, oneMach / oneYard, oneMach / oneMph);
dataTable.Rows.Add("节(knot)", oneKnot / oneKmh, oneKnot / oneMs, oneKnot / oneMach, oneKnot / oneKnot, oneKnot / oneYard, oneKnot / oneMph);
dataTable.Rows.Add("码(yard)", oneYard / oneKmh, oneYard / oneMs, oneYard / oneMach, oneYard / oneKnot, oneYard / oneYard, oneYard / oneMph);
dataTable.Rows.Add("迈(mph)", oneMph / oneKmh, oneMph / oneMs, oneMph / oneMach, oneMph / oneKnot, oneMph / oneYard, oneMph / oneMph);
dgvSpeed.DataSource = dataTable;
}
private void dgvSpeed_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
rtxtMessage.Clear();
if (e.ColumnIndex <= 0 || e.RowIndex < 0)
{
//不考虑列头【RowIndex为-1】、不考虑速度单位描述列【ColumnIndex为0】
return;
}
rtxtMessage.AppendText($"1{dgvSpeed["dgvcSpare", e.RowIndex].Value}={dgvSpeed[e.ColumnIndex, e.RowIndex].Value}{dgvSpeed.Columns[e.ColumnIndex].HeaderText}");
}
}
}
运行如图: