void PointSetWithCollisions::CheckCollisions(double deltaTime) { for(unsigned int i = 0; i < m_count; i++) { double mI = m_points[i].m_mass; for(unsigned int j = i + 1; j < m_count; j++) { double nextDistance = (m_points[i].m_nextPos - m_points[j].m_nextPos).Length(); if(nextDistance < (m_points[i].m_radius + m_points[j].m_radius)) { Vec3d n = m_points[j].m_pos - m_points[i].m_pos; n.Normalize(); double mJ = m_points[j].m_mass; double mReduced = (mI*mJ)/(mI+mJ); double Dvn = DotProduct(m_points[i].m_vel - m_points[j].m_vel, n); double J = -mReduced*(m_epsilon+1)*Dvn; m_points[i].m_vel = m_points[i].m_vel + n * (J/mI); m_points[j].m_vel = m_points[j].m_vel - n * (J/mJ); m_points[i].PrepareMoveEuler(deltaTime, Force(i)); m_points[j].PrepareMoveEuler(deltaTime, Force(j)); } } } }
/* Philippose Rajan - 11 June 2009 Function to calculate the surface normal at a given vertex of a surface element, with respect to that surface element. This function is used by the boundary layer generation function, in order to calculate the effective direction in which the prismatic layer should grow */ void GetSurfaceNormal(Mesh & mesh, Element2d & el, int Vertex, Vec3d & SurfaceNormal) { int Vertex_A; int Vertex_B; Vertex_A = Vertex + 1; if(Vertex_A > el.GetNP()) Vertex_A = 1; Vertex_B = Vertex - 1; if(Vertex_B <= 0) Vertex_B = el.GetNP(); Vec3d Vect_A,Vect_B; Vect_A = mesh.Point(el.PNum(Vertex_A)) - mesh.Point(el.PNum(Vertex)); Vect_B = mesh.Point(el.PNum(Vertex_B)) - mesh.Point(el.PNum(Vertex)); SurfaceNormal = Cross(Vect_A,Vect_B); SurfaceNormal.Normalize(); }