コード例 #1
0
        // The smaller of the two possible angles between the two vectors is returned, therefore the result will never be greater than 180 degrees or smaller than -180 degrees.
        // If you imagine the from and to vectors as lines on a piece of paper, both originating from the same point, then the /axis/ vector would point up out of the paper.
        // The measured angle between the two vectors would be positive in a clockwise direction and negative in an anti-clockwise direction.
        public static FP SignedAngle(FPVector from, FPVector to, FPVector axis)
        {
            FPVector fromNorm = from.normalized, toNorm = to.normalized;
            FP       unsignedAngle = FPMath.Acos(FPMath.Clamp(Dot(fromNorm, toNorm), -FP.ONE, FP.ONE)) * FPMath.Rad2Deg;
            FP       sign          = FPMath.Sign(Dot(axis, Cross(fromNorm, toNorm)));

            return(unsignedAngle * sign);
        }
コード例 #2
0
 // Returns the angle in degrees between /from/ and /to/. This is always the smallest
 public static FP Angle(FPVector from, FPVector to)
 {
     return(FPMath.Acos(FPMath.Clamp(Dot(from.normalized, to.normalized), -FP.ONE, FP.ONE)) * FPMath.Rad2Deg);
 }