float Physics::angleBetween(const Vector& from, const Vector& to) { // float angle = acos(from.dotProduct(to) / (float) (from.getLength() * to.getLength())); float angle = safeAcos(from.dotProduct(to) / (float) (from.getLength() * to.getLength())); if(to.y < from.y) { angle = 2 * M_PI - angle; } return angle; }
float Quaternion::getRotationAngle() const { // Compute the half angle. w = cos(theta / 2) float thetahalf = safeAcos(w); // Return the rotation angle return thetahalf * 2.0f; }
float Quaternion::getRotationAngle() const { // Compute the half angle. Remember that w = cos(theta / 2) float thetaOver2 = safeAcos(w); // Return the rotation angle return thetaOver2 * 2.0f; }
float Physics::angleTo(const Vector& fromPoint, const Vector& toPoint) { // This method is a bottleneck, so using Vector is avoided. float diffX = toPoint.x - fromPoint.x; float diffY = toPoint.y - fromPoint.y; float length = sqrt(diffX*diffX + diffY*diffY); float angle = safeAcos(diffX / length); // float angle = acos(diffX / length); if(diffY < 0) { angle = 2 * M_PI - angle; } return angle; }
bool isConvex(const float3 pt[], std::size_t n) { float angleSum = 0.0f; for (std::size_t i = 0; i < n; i++) { Vector3t<float> e1; if (i == 0) { e1 = pt[n - 1] - pt[i]; } else { e1 = pt[i - 1] - pt[i]; } Vector3t<float> e2; if (i == n - 1) { e2 = pt[0] - pt[i]; } else { e2 = pt[i + 1] - pt[i]; } e1 = normalize(e1); e2 = normalize(e2); float d = dot(e1, e2); float theta = safeAcos(d); angleSum += theta; } float convexAngleSum = (float)(n - 2) * M_PI; if (angleSum < convexAngleSum - (float)n * 0.0001f) { return false; } return true; }
float Quaternion::getRotationAngle() const { float alpha = safeAcos(w); return alpha*2.0f; }
// 提取旋转角和旋转轴 float Quaternion::getRotateAngle()const { float thetaOver2 = safeAcos(w); return 2.0f*thetaOver2; }