double Angle(coor a, coor b, coor c) { double ang; double l1 = Math.Sqrt((b.x - c.x) * (b.x - c.x) + (b.y - c.y) * (b.y - c.y)); double l2 = Math.Sqrt((a.x - c.x) * (a.x - c.x) + (a.y - c.y) * (a.y - c.y)); double l3 = Math.Sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y)); ang = Math.Acos((l1 * l1 + l2 * l2 - l3 * l3) / (2 * l1 * l2)); return(ang); }
double Volume(int id1, int id2, int id3, double Height) { //coor zb = new coor(); coor a = zbArray[id1]; coor b = zbArray[id2]; coor c = zbArray[id3]; //double h1 = a.z; //double h2 = b.z; //double h3 = c.z; //double minHeight = a.z; //double maxHeight = a.z; #region //double maxHeight = (a.z > b.z ? a.z : b.z) > c.z ? (a.z > b.z ? a.z : b.z) : c.z; //double minHeight = (a.z < b.z ? a.z : b.z) < c.z ? (a.z < b.z ? a.z : b.z) : c.z; //double midHeight; //if (maxHeight==a.z) //{ //} //if (a.z<b.z&&b.z<c.z||c.z<b.z&&b.z<a.z) //{ // midHeight = b.z; //} //else if (b.z<a.z&&a.z<c.z||c.z<a.z&&a.z<b.z) //{ // midHeight = a.z; //} //else //{ // midHeight = c.z; //} //double S = ((a.x * b.y - b.x * a.y) + (b.x * c.y - c.x * b.y) + (c.x * a.y - a.x * c.y)) / 2; //double V1 = (S * maxHeight) / 3; #endregion double ab = Distance(a, b); double ac = Distance(a, c); double bc = Distance(b, c); double p = (ab + ac + bc) / 2; double S = Math.Sqrt(p * (p - ab) * (p - ac) * (p - bc)); double V1 = (S * (a.z + b.z + c.z) / 3) - Height * S; return(V1); }
int ZuoYou(coor a, coor b, coor c) { int youbian; double S; S = (a.x - c.x) * (b.y - c.y) - (a.y - c.y) * (b.x - c.x); if (S > 0) { youbian = 1; } else if (S < 0) { youbian = -1; } else { youbian = 0; } return(youbian); }
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); open.Filter = "Txt数据(*.txt)|*.txt"; if (open.ShowDialog() != DialogResult.OK) { return; } StreamReader sr = new StreamReader(open.FileName, Encoding.Default); coor zb = new coor(); while (true) { string strLine = sr.ReadLine(); if (strLine != null) { string[] H = strLine.Split(' '); zb.x = Convert.ToDouble(H[1]); zb.y = Convert.ToDouble(H[2]); zb.z = Convert.ToDouble(H[3]); zbArray.Add(zb); } else { break; } } for (int i = 0; i < zbArray.Count; i++) { dataGridView1.Rows.Add(); dataGridView1.Rows[i].Cells[0].Value = zbArray[i].x; dataGridView1.Rows[i].Cells[1].Value = zbArray[i].y; dataGridView1.Rows[i].Cells[2].Value = zbArray[i].z; } }
double Distance(coor a, coor b) { return(Math.Sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y))); }