using System.Collections; using System.Collections.Generic; using UnityEngine; public class Plane { public string name; List points; public Vector3 normal; public Plane(List ps) { name = ""; points = new List(); foreach(Point p in ps) { points.Add(p); name += p.name; } updateNormal(); } public void updateNormal() { List vector3s = new List(); for (int i = 1; i < points.Count; ++i) { Vector3 tmp = new Vector3(points[i].x - points[0].x, points[i].y - points[0].y, points[i].z - points[0].z); vector3s.Add(tmp); } List normals = new List(); for (int i = 0; i < vector3s.Count; ++i) { for (int j = i + 1; j < vector3s.Count; ++j) { Vector3 tmp = Vector3.Cross(vector3s[i], vector3s[j]).normalized; if (tmp.magnitude != 0) normals.Add(tmp); } } bool flag = true; for (int i = 1; i < normals.Count; ++i) { if (normals[i - 1] != normals[i] && normals[i - 1] != -normals[i]) { flag = false; break; } } if (flag && normals.Count != 0) { normal = normals[0]; } else { Debug.Log("wrong plane"); } } }