Exemple #1
0
        public Direction2D To2D(Direction direction)
        {
            var result = Direction2D.Create(direction.DotProduct(XAxis), direction.DotProduct(YAxis));

            if (direction != To3D(result))
            {
                throw new ArgumentException("The direction does not lie within the embedded space.");
            }
            return(result);
        }
Exemple #2
0
        public static void ThirtyDegreesFromDirection2DTest()
        {
            // This can be relaxed slightly if needed.
            var precision = Math.Pow(2, -53);

            var direction     = Direction2D.Create(Math.Sqrt(3), 1);
            var thirtyDegrees = direction.AngleFromPositiveX();

            thirtyDegrees.CosineOfAngle.Should().BeApproximately(Math.Sqrt(3) / 2, precision);
            thirtyDegrees.SineOfAngle.Should().BeApproximately(0.5, precision);
            thirtyDegrees.ToProperAngle().Should().Be(30 * Unit.Degrees);
            thirtyDegrees.ToSignedAngle().Should().Be(30 * Unit.Degrees);

            var negativeThirtyDegrees = thirtyDegrees.Negate();

            negativeThirtyDegrees.CosineOfAngle.Should().BeApproximately(Math.Sqrt(3) / 2, precision);
            negativeThirtyDegrees.SineOfAngle.Should().BeApproximately(-0.5, precision);
            negativeThirtyDegrees.ToProperAngle().Should().Be(330 * Unit.Degrees);
            negativeThirtyDegrees.ToSignedAngle().Should().Be(-30 * Unit.Degrees);
        }
 public Direction2D ProjectTo2D(Direction direction) =>
 Direction2D.Create(direction.DotProduct(XAxis), direction.DotProduct(YAxis));