日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

【C#】多边形面积

發布時間:2023/12/14 C# 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【C#】多边形面积 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Vector2類見前文

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 多邊形面積 {public partial class Form1 : Form{public Form1(){InitializeComponent();}int clickCount = 0;Point[] d = new Point[100];List<PointF> PointList = new List<PointF>();private void Form1_MouseDown(object sender, MouseEventArgs e){Graphics g = this.CreateGraphics();Pen pen = new Pen(Color.Blue, 2);Brush brush = new SolidBrush(Color.Blue);g.DrawEllipse(pen, e.X, e.Y, 7, 7);g.FillEllipse(brush, e.X, e.Y, 7, 7);d[clickCount] = e.Location;if (clickCount >= 1){g.DrawLine(pen, d[clickCount], d[clickCount - 1]);PointF pPoint = new PointF(d[clickCount - 1].X, d[clickCount - 1].Y);PointList.Add(pPoint);}clickCount++;}public static float CalculateArea(List<PointF> vectorPoints){int iCycle, iCount;iCycle = 0;iCount = vectorPoints.Count;float iArea = 0;for (iCycle = 0; iCycle < iCount; iCycle++){iArea = iArea + (vectorPoints[iCycle].X * vectorPoints[(iCycle + 1) % iCount].Y - vectorPoints[(iCycle + 1) % iCount].X * vectorPoints[iCycle].Y);}float area = (float)Math.Abs(0.5 * iArea);return area;}private void button1_Click(object sender, EventArgs e){Graphics g = this.CreateGraphics();Pen pen = new Pen(Color.Blue, 2);g.DrawLine(pen, PointList[PointList.Count - 1], PointList[0]); //?-1就連錯點了,不-1又有溢出錯誤,咋辦捏float S = CalculateArea(PointList);MessageBox.Show("多邊形面積為:" + S);}} }

(最后連線時有錯誤)

總結

以上是生活随笔為你收集整理的【C#】多边形面积的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。