void FDice::create(const XYZ& p0, const XYZ& p1, const XYZ& p2) { p_obj[0] = P[0] = p0; p_obj[1] = P[1] = p1; p_obj[2] = P[2] = p2; V[0] = p1 - p0; edge_length[0] = V[0].length(); V[1] = p2 - p1; edge_length[1] = V[1].length(); V[2] = p0 - p2; edge_length[2] = V[2].length(); area = 0.5*sqrt(edge_length[0]*edge_length[0]*edge_length[2]*edge_length[2] - (V[0].dot(V[2]))*(V[0].dot(V[2]))); V[0].normalize(); V[1].normalize(); V[2].normalize(); int a , b; if(edge_length[0] > edge_length[1] && edge_length[0] > edge_length[2]) { a = 0; b = 1; } else if(edge_length[1] > edge_length[2] && edge_length[1] > edge_length[0]) { a = 1; b = 2; } else { a = 2; b = 0; } XYZ side = V[a]; XYZ front = side^V[b]; front.normalize(); XYZ up = front^side; m_space.setOrientations(side, up, front); m_space.setTranslation(P[a]); m_space.inverse(); m_space.transform(p_obj[0]); m_space.transform(p_obj[1]); m_space.transform(p_obj[2]); f120 = barycentric_coord(p_obj[1].x, p_obj[1].y, p_obj[2].x, p_obj[2].y, p_obj[0].x, p_obj[0].y); f201 = barycentric_coord(p_obj[2].x, p_obj[2].y, p_obj[0].x, p_obj[0].y, p_obj[1].x, p_obj[1].y); f012 = barycentric_coord(p_obj[0].x, p_obj[0].y, p_obj[1].x, p_obj[1].y, p_obj[2].x, p_obj[2].y); }
// rotar p con eje de rotacion r XYZ rotate(XYZ p, XYZ r, double theta){ XYZ q(0,0,0); double costheta,sintheta; r.normalize(); costheta = cos(theta); sintheta = sin(theta); q.x += (costheta + (1 - costheta) * r.x * r.x) * p.x; q.x += ((1 - costheta) * r.x * r.y - r.z * sintheta) * p.y; q.x += ((1 - costheta) * r.x * r.z + r.y * sintheta) * p.z; q.y += ((1 - costheta) * r.x * r.y + r.z * sintheta) * p.x; q.y += (costheta + (1 - costheta) * r.y * r.y) * p.y; q.y += ((1 - costheta) * r.y * r.z - r.x * sintheta) * p.z; q.z += ((1 - costheta) * r.x * r.z - r.y * sintheta) * p.x; q.z += ((1 - costheta) * r.y * r.z + r.x * sintheta) * p.y; q.z += (costheta + (1 - costheta) * r.z * r.z) * p.z; return q; }