private Vector3 Barycentre(Triangle triangle, float p1, float p2, float p3) { float x = (triangle.P1.X * p1 + triangle.P2.X * p2 + triangle.P3.X * p3) / p1 + p2 + p3; float y = (triangle.P1.Y * p1 + triangle.P2.Y * p2 + triangle.P3.Y * p3) / p1 + p2 + p3; float z = (triangle.P1.Z * p1 + triangle.P2.Z * p2 + triangle.P3.Z * p3) / p1 + p2 + p3; return new Vector3(x, y, z); }
public ITriangleInstance AddTriangle(Triangle triangle) { var instance = new TriangleInstance(this); m_instances.Add(instance); instance.P1 = triangle.P1; instance.P2 = triangle.P2; instance.P3 = triangle.P3; instance.Color = triangle.Color; return instance; }
private Vector3 Barycentre2(Triangle triangle, float p1, float p2, float p3) { return new Vector3(p1 * triangle.P1.X + p2 * triangle.P2.X + p3 * triangle.P3.X, p1 * triangle.P1.Y + p2 * triangle.P2.Y + p3 * triangle.P3.Y, p1 * triangle.P1.Z + p2 * triangle.P2.Z + p3 * triangle.P3.Z); }
private Vector3 Normal(Triangle t) { var u = new Vector3( t.P2.X - t.P1.X, t.P2.Y - t.P1.Y, t.P2.Z - t.P1.Z ); var v = new Vector3( t.P3.X - t.P1.X, t.P3.Y - t.P1.Y, t.P3.Z - t.P1.Z ); var normal = new Vector3( u.Y * v.Z - v.Y * u.Z, -(u.X * v.Z - v.X * u.Z), u.X * v.Y - v.X * u.Y); return normal.Normalize(); }
private List<Triangle> BuildIco(double R) { float phi = (float)((Math.Sqrt(5.0) - 1.0) / 2.0); float radius = (float)Math.Sqrt((5 - Math.Sqrt(5)) / 2.0); float A = (float)R / radius; float B = phi * A; var I0 = new Vector3(A, B, 0); var I1 = new Vector3(-A, B, 0); var I2 = new Vector3(-A, -B, 0); var I3 = new Vector3(A, -B, 0); var J0 = new Vector3(0, A, B); var J1 = new Vector3(0, -A, B); var J2 = new Vector3(0, -A, -B); var J3 = new Vector3(0, A, -B); var K0 = new Vector3(B, 0, A); var K1 = new Vector3(B, 0, -A); var K2 = new Vector3(-B, 0, -A); var K3 = new Vector3(-B, 0, A); var list = new List<Triangle>(); var t = new Triangle(I3, I0, K0); list.Add(t); t = new Triangle(I0, I3, K1); list.Add(t); t = new Triangle(I2, I1, K2); list.Add(t); t = new Triangle(I1, I2, K3); list.Add(t); t = new Triangle(J3, J0, I0); list.Add(t); t = new Triangle(J0, J3, I1); list.Add(t); t = new Triangle(J2, J1, I2); list.Add(t); t = new Triangle(J1, J2, I3); list.Add(t); t = new Triangle(K3, K0, J0); list.Add(t); t = new Triangle(K0, K3, J1); list.Add(t); t = new Triangle(K2, K1, J2); list.Add(t); t = new Triangle(K1, K2, J3); list.Add(t); t = new Triangle(I0, J0, K0); list.Add(t); t = new Triangle(I0, K1, J3); list.Add(t); t = new Triangle(I3, K0, J1); list.Add(t); t = new Triangle(I3, J2, K1); list.Add(t); t = new Triangle(I1, K3, J0); list.Add(t); t = new Triangle(I1, J3, K2); list.Add(t); t = new Triangle(I2, J1, K3); list.Add(t); t = new Triangle(I2, K2, J2); list.Add(t); return list; }