利用SuperMap iObjects.NET控件模拟小球平抛运动

喜夏-厌秋 提交于 2020-01-21 04:17:09

利用SuperMap iObjects.NET控件模拟小球平抛运动

1.部署SuperMap iObjects.NET控件

    相关控件部署参考博客:SuperMap开发入门2——环境部署——我也是个傻瓜

2.Github项目地址

    小球平抛运动项目源码

3.项目描述

3.1. 创建小球
geoStyle_P.MarkerAngle = 14.0;
geoStyle_P.MarkerSize = new Size2D(5, 5);
geoStyle_P.LineColor = Color.Red;
GeoPoint point = new GeoPoint();
point.X = Xx[hh];
point.Y = Yy[hh];
point.Style = geoStyle_P;
3.2. 创建轨迹线
Point2D p = map.Center;
Point2D pl = map.Center;
int m = 0;
Xx = ts.Keys.ToList<double>();
Yy = ts.Values.ToList<double>();

Point2Ds point2Ds = new Point2Ds();
for (int i = 0; i < Xx.Count; i++)
{
	Point2D point2D = new Point2D(Xx[i], Yy[i]);
	point2Ds.Add(point2D);
}
GeoLine geoLine = new GeoLine(point2Ds);
mapControl1.Map.TrackingLayer.Add(geoLine, "线");
mapControl1.Map.Refresh();
3.3. 平抛运动参数输入
		private double Xs(double t)
        {
            double v0 = double.Parse(textBox1.Text);
            return v0 * t;
        }
        private double Ys(double t)
        {
            double g = double.Parse(textBox3.Text);
            return 0.5 * g * t * t;
        }
        Dictionary<double, double> ts = new Dictionary<double, double>();
        string str;
   
        public Dictionary<double, double> con()
        {
            return ts;
        }
        public string name()
        {
            return str;
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            double t;
            double ht = Math.Sqrt(2 * double.Parse(textBox2.Text) / double.Parse(textBox3.Text));
            for (t = 0; t <= ht; t += 0.1)
            {
                double x = Xs(t) + 300;
                double y = Ys(t) - 400;
                ts.Add(x, -y);
            }
            str = string.Format("当地重力加速度:{0}\n小球水平方向初速度:{1}\n小球下落高度:{2}\n小球落地时间:{3}\n小球水平方向位移:{4}\n小球总位移:{5}\n小球平抛运动轨迹方程:y=-({6})*x^2", double.Parse(textBox3.Text), double.Parse(textBox1.Text), double.Parse(textBox2.Text), ht, double.Parse(textBox1.Text) * ht, Math.Sqrt(Math.Pow(double.Parse(textBox1.Text) * ht, 2) + Math.Pow(double.Parse(textBox2.Text), 2)), 0.5 * double.Parse(textBox3.Text) / Math.Pow(double.Parse(textBox1.Text), 2));
            this.Hide();
        }
3.4. 利用timer控件和MapControl的跟踪层模拟小球平抛运动
		private void timer1_Tick(object sender, EventArgs e)
        {
            if (n)
            {
                m = timer1.Interval;
                n = false;
            }
            if (this.timer1.Interval % 2 == 0)
            {
                GeoPoint point = new GeoPoint();
                point.X = Xx[hh];
                point.Y = Yy[hh];
                point.Style = geoStyle_P;
                mapControl1.Map.TrackingLayer.Add(point, "点");
                mapControl1.Map.Refresh();
                hh++;
            }
            m++;
            if (hh == Xx.Count)
            {
                this.richTextBox1.Show();
                richTextBox1.Text = str;
                this.timer1.Interval = 100;
                n = true;
                hh = 0;
                this.timer1.Enabled = false;

            }
        }

4.操作说明

4.1. 输入参数

在这里插入图片描述

4.2. 模拟效果

在这里插入图片描述

5.项目总结

    利用SuperMap iObject.NET的MapControl控件的跟踪层TackingLayer可以动态完成小球的创建,结合Timer控件控制创建时间,达到模拟小球平抛运动的效果。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!