Пример #1
0
double
squaredAngle(
    const MappedColumnVector& inX,
    const MappedColumnVector& inY) {

    double cosine = dot(inX, inY) / (inX.norm() * inY.norm());
    if (cosine > 1)
        cosine = 1;
    else if (cosine < -1)
        cosine = -1;
    double angle = std::acos(cosine);
    return angle * angle;
}
Пример #2
0
double
distAngle(
    const MappedColumnVector& inX,
    const MappedColumnVector& inY) {

	// Deal with the undefined case where one of the norm is zero
	// Angle is not defined. Just return \pi.
	double xnorm = inX.norm(), ynorm = inY.norm();
	if (xnorm < std::numeric_limits<double>::denorm_min()
		|| ynorm < std::numeric_limits<double>::denorm_min())
		return std::acos(-1);
	
    double cosine = dot(inX, inY) / (xnorm * ynorm);
    if (cosine > 1)
        cosine = 1;
    else if (cosine < -1)
        cosine = -1;
    return std::acos(cosine);
}