void centerAttractor (struct attractor *a) { int i, j; point m = _middle (a->bound[0], a->bound[1]); for (i = 0; i < a->numPoints; i++) { for (j = 0; j < fset.dimension; j++) { a->array[i][j] -= m[j]; } } for (i = 0; i < 2; i++) { for (j = 0; j < fset.dimension; j++) { a->bound[i][j] -= m[j]; } } free (m); }
//-------------------------------------------------------------------------------------- bool Bline::build(const Real* keyPoints, unsigned int keyCounts) { release(); assert(keyCounts >=3); m_keyCounts = keyCounts; m_keyPoints = new Point[keyCounts]; const Real* k = keyPoints; for (unsigned int i = 0; i < keyCounts; i++) { Real& x = m_keyPoints[i].x = *k++; Real& y = m_keyPoints[i].y = *k++; Real& z = m_keyPoints[i].z = *k++; if (x > m_bounderMax.x) m_bounderMax.x = x; if (x < m_bounderMin.x) m_bounderMin.x = x; if (y > m_bounderMax.y) m_bounderMax.y = y; if (y < m_bounderMin.y) m_bounderMin.y = y; if (z > m_bounderMax.z) m_bounderMax.z = z; if (z < m_bounderMin.z) m_bounderMin.z = z; } m_totalLength = (Real)0.0; m_partCounts = keyCounts - 2; m_parts = new LinePart[m_partCounts]; for (size_t i = 0; i < m_partCounts; i++) { LinePart& lp = m_parts[i]; if (i == 0) { lp.pt0 = m_keyPoints[i]; } else { _middle(m_keyPoints[i], m_keyPoints[i + 1], lp.pt0); } lp.pt1 = m_keyPoints[i + 1]; if (i == m_partCounts - 1) { lp.pt2 = m_keyPoints[i + 2]; } else { _middle(m_keyPoints[i + 1], m_keyPoints[i + 2], lp.pt2); } Real ax = lp.pt0.x - 2 * lp.pt1.x + lp.pt2.x; Real ay = lp.pt0.y - 2 * lp.pt1.y + lp.pt2.y; Real bx = 2 * lp.pt1.x - 2 * lp.pt0.x; Real by = 2 * lp.pt1.y - 2 * lp.pt0.y; lp.A = 4 * (ax*ax + ay*ay); lp.B = 4 * (ax*bx + ay*by); lp.C = bx*bx + by*by; lp.sqrt_A = sqrt(lp.A); lp.sqrt_C = sqrt(lp.C); lp.D = log(lp.B + 2 * lp.sqrt_A*lp.sqrt_C); lp.E = (lp.B*lp.B - 4*lp.A*lp.C); lp.length = _getlength(lp, (Real)1.0); m_totalLength += lp.length; } Real lengthAddup = (Real)0.0; for (size_t i = 0; i < m_partCounts; i++) { LinePart& lp = m_parts[i]; lengthAddup += lp.length; lp.percent = lp.length / m_totalLength; lp.percentAddup = lengthAddup / m_totalLength; } return true; }