#include

#include

typedef float Real; // change this to double to get a high accuracy result

inline float Sqrt(float s)

{

return sqrtf(s);

}

inline double Sqrt(double s)

{

return sqrt(s);

}

struct Vec

{

Vec() {}

Vec(Real x_, Real y_, Real z_) { x = x_; y = y_; z = z_; }

Real x, y, z;

};

inline Vec operator-(const Vec& a, const Vec& b)

{

return Vec(a.x - b.x, a.y - b.y, a.z - b.z);

}

inline Vec operator+(const Vec& a, const Vec& b)

{

return Vec(a.x + b.x, a.y + b.y, a.z + b.z);

}

inline Vec Cross(const Vec& a, const Vec& b)

{

return Vec(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);

}

inline Vec Newell(const Vec& a, const Vec& b)

{

return Vec((a.y - b.y) * (a.z + b.z), (a.z - b.z) * (a.x + b.x), (a.x - b.x) * (a.y + b.y));

}

inline Vec Normalize(const Vec& a)

{

float d = Sqrt(a.x * a.x + a.y * a.y + a.z * a.z);

return Vec(a.x/d, a.y/d, a.z/d);

}

inline Real Length(const Vec& a)

{

return Sqrt(a.x * a.x + a.y * a.y + a.z * a.z);

}

int main()

{

Vec p1(0.331916571f, 0.382771939f, -0.465963870f);

Vec p2(0.378853887f, -0.246981591f, -0.440359056f);

Vec p3(0.331879079f, 0.382861078f, -0.465974003f);

Vec newell = Normalize(Newell(p1, p2) + Newell(p2, p3) + Newell(p3, p1));

Vec e1 = p2 - p1;

Vec e2 = p3 - p2;

Vec e3 = p1 - p3;

Real d1 = Length(e1);

Real d2 = Length(e2);

Real d3 = Length(e3);

Vec n1 = Cross(e3, e1);

Vec n2 = Cross(e1, e2);

Vec n3 = Cross(e2, e3);

Real s1 = Length(n1);

Real s2 = Length(n2);

Real s3 = Length(n3);

n1 = Normalize(n1);

n2 = Normalize(n2);

n3 = Normalize(n3);

Vec shift1 = Normalize(Newell(p1-p1, p2-p1) + Newell(p2-p1, p3-p1) + Newell(p3-p1, p1-p1));

Vec shift2 = Normalize(Newell(p1-p2, p2-p2) + Newell(p2-p2, p3-p2) + Newell(p3-p2, p1-p2));

Vec shift3 = Normalize(Newell(p1-p3, p2-p3) + Newell(p2-p3, p3-p3) + Newell(p3-p3, p1-p3));

Vec c = p1 + p2 + p3;

c.x = c.x / 3.0f;

c.y = c.y / 3.0f;

c.z = c.z / 3.0f;

Vec shiftc = Normalize(Newell(p1-c, p2-c) + Newell(p2-c, p3-c) + Newell(p3-c, p1-c));

printf("%g %g %g\n", newell.x, newell.y, newell.z);

printf("%g %g %g\n", n1.x, n1.y, n1.z);

printf("%g %g %g\n", n2.x, n2.y, n2.z);

printf("%g %g %g\n", n3.x, n3.y, n3.z);

printf("%g %g %g\n", shift1.x, shift1.y, shift1.z);

printf("%g %g %g\n", shift2.x, shift2.y, shift2.z);

printf("%g %g %g\n", shift3.x, shift3.y, shift3.z);

printf("%g %g %g\n", shiftc.x, shiftc.y, shiftc.z);

}