internal static Distance DotProduct(this FreeVector thisVector, DoubleVector otherVector)
        {
            var vector1 = thisVector;
            var vector2 = otherVector;

            return(vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z);
        }
示例#2
0
        /// <summary>
        /// Left to right composition.
        /// <remarks>Optimized version of the more general overload: Compose(Shift, Shift)</remarks>
        /// </summary>
        public static Shift ComposeLeftToRight(FreeVector translation, Shift shift)
        {
            var matrix = shift.Matrix.Copy();

            matrix.PreTranslateBy(translation);
            return(new Shift(matrix));
        }
示例#3
0
        /// <summary>
        /// For compatibility with old tests
        /// </summary>
        internal Shift(FreeVector translation)
        {
            var matrix = IdentityMatrix(4);

            matrix.PostTranslateBy(translation);
            this.Matrix = matrix;
        }
示例#4
0
        /// <summary>
        /// Translates the vector the given distance in the given direction
        /// </summary>
        public Vector Translate(FreeVector translation)
        {
            Point newBasePoint = this.BasePoint.Translate(translation);
            Point newEndPoint  = this.EndPoint.Translate(translation);

            return(new Vector(newBasePoint, newEndPoint));
        }
        internal static void PreTranslateBy(this double[,] matrix, FreeVector vector)
        {
            var x = vector.X.InInches();
            var y = vector.Y.InInches();
            var z = vector.Z.InInches();

            matrix[0, 3] += matrix[0, 0] * x + matrix[0, 1] * y + matrix[0, 2] * z;
            matrix[1, 3] += matrix[1, 0] * x + matrix[1, 1] * y + matrix[1, 2] * z;
            matrix[2, 3] += matrix[2, 0] * x + matrix[2, 1] * y + matrix[2, 2] * z;
        }
示例#6
0
        /// <summary>
        /// Adds the two vectors and returns the resultant vector
        /// </summary>
        public static Vector operator +(Vector vector1, Vector vector2)
        {
            Distance x = vector1.XComponent + vector2.XComponent;
            Distance y = vector1.YComponent + vector2.YComponent;
            Distance z = vector1.ZComponent + vector2.ZComponent;

            var v = new FreeVector(x, y, z);

            return(new Vector(vector1.BasePoint, v + vector1.BasePoint));
        }
示例#7
0
        /// <summary>
        /// Creates a parralelepiped.
        /// shifts the vectors so their basepoints are the passed basepoint, and creates the parralelepiped spanned by those vectors.
        /// </summary>
        public static Polyhedron MakeParallelepiped(
            FreeVector vector1,
            FreeVector vector2,
            FreeVector vector3,
            [NotNull] Point basePoint)
        {
            Polygon    bottom = Polygon.Parallelogram(vector1, vector2, basePoint);
            Polyhedron solid  = bottom.Extrude(vector3);

            return(solid);
        }
示例#8
0
        /// <summary>
        /// Creates a parallelogram.
        /// shifts both vectors so their basepoints are the passed basepoint, and creates the parallelogram spanned by
        /// those sides.
        /// </summary>
        public static Polygon Parallelogram(FreeVector vector1, FreeVector vector2, Point basePoint = null)
        {
            if (basePoint == null)
            {
                basePoint = Point.Origin;
            }
            LineSegment segment1 = new LineSegment(basePoint, vector1);
            LineSegment segment2 = new LineSegment(basePoint, vector2);
            LineSegment segment3 = new LineSegment(segment2.EndPoint, vector1);
            LineSegment segment4 = new LineSegment(segment1.EndPoint, vector2);

            return(new Polygon(new List <LineSegment> {
                segment1, segment2, segment3, segment4
            }));
        }
        private static Polyhedron _makeSolid(Distance length, Distance width, Distance height, Point basePoint = null)
        {
            if (basePoint == null)
            {
                basePoint = Point.Origin;
            }
            Distance zero = Unit.ZeroDistance;

            var vector1 = new FreeVector(zero, width, zero);
            var vector2 = new FreeVector(length, zero, zero);
            var vector3 = new FreeVector(zero, zero, height);

            var solid = MakeParallelepiped(vector1, vector2, vector3, basePoint);

            return(solid);
        }
示例#10
0
        /// <summary>
        /// Extends a polygon to a 3 dimensional solid.
        /// Makes a copy of the polygon shifted over by the extrusion vector, then connects corresponding vertices.
        /// </summary>
        public Polyhedron Extrude(FreeVector extrusionVector)
        {
            if (this.IsParallelTo(extrusionVector))
            {
                throw new Exception("Extrusion vector cannot be parallel to extruding face");
            }

            if (extrusionVector.ScalarProjection(NormalDirection).AbsoluteValue() < Inches.Tolerance * Inches)
            {
                throw new Exception("Extrusion vector is too small in the normal direction.");
            }
            ;

            var baseFace = extrusionVector.ScalarProjection(NormalDirection) < ZeroDistance
                ? this
                : this.ReverseOrientation();

            var faces = new List <Polygon> {
                baseFace
            };
            var oppositeFace = new List <LineSegment>();

            foreach (var segment in baseFace.Edges)
            {
                var opposite = segment.Translate(extrusionVector);

                var sideFace = new Polygon
                               (
                    ValidateOption.Dont,
                    opposite.BasePoint,
                    opposite.EndPoint,
                    segment.EndPoint,
                    segment.BasePoint
                               );

                faces.Add(sideFace);
                oppositeFace.Add(opposite.Reverse());
            }
            oppositeFace.Reverse();
            faces.Add(new Polygon(oppositeFace, ValidateOption.Dont));

            var solid = new Polyhedron(faces, ValidateOption.Dont);

            return(solid);
        }
示例#11
0
 public Shift
 (
     FreeVector translationToOrigin,
     Angle xAxisRotationAngle,
     Angle yAxisRotationAngle,
     Angle zAxisRotationAngle
 )
     : this
     (
         new List <Rotation>
 {
     new Rotation(Line.XAxis, xAxisRotationAngle),
     new Rotation(Line.YAxis, yAxisRotationAngle),
     new Rotation(Line.ZAxis, zAxisRotationAngle)
 }, translationToOrigin
     )
 {
 }
        internal static FreeVector CrossProduct(this FreeVector thisVector, DoubleVector otherVector)
        {
            var v1 = thisVector;
            var v2 = otherVector;

            //Find each component

            var xProduct1 = v1.Y * v2.Z;
            var xProduct2 = v1.Z * v2.Y;

            var yProduct1 = v1.Z * v2.X;
            var yProduct2 = v1.X * v2.Z;

            var zProduct1 = v1.X * v2.Y;
            var zProduct2 = v1.Y * v2.X;

            var newX = (xProduct1) - (xProduct2);
            var newY = (yProduct1) - (yProduct2);
            var newZ = (zProduct1) - (zProduct2);

            return(new FreeVector(newX, newY, newZ));
        }
        /// <summary>
        /// Returns the cross product of the 2 vectors
        /// which is always perpendicular to both vectors
        /// and whose magnitude is the area of the parellelogram spanned by those two vectors
        /// Consequently if they point in the same (or opposite) direction, than the cross product is zero
        /// </summary>
        public static FreeVector CrossProduct(this FreeVector thisVector, FreeVector otherVector)
        {
            var v1 = thisVector;
            var v2 = otherVector;

            //Find each component

            double xProduct1 = v1.Y.InInches() * v2.Z.InInches();
            double xProduct2 = v1.Z.InInches() * v2.Y.InInches();

            double yProduct1 = v1.Z.InInches() * v2.X.InInches();
            double yProduct2 = v1.X.InInches() * v2.Z.InInches();

            double zProduct1 = v1.X.InInches() * v2.Y.InInches();
            double zProduct2 = v1.Y.InInches() * v2.X.InInches();

            double newX = (xProduct1) - (xProduct2);
            double newY = (yProduct1) - (yProduct2);
            double newZ = (zProduct1) - (zProduct2);

            return(FreeVector.MakeWithInches(newX, newY, newZ));
        }
示例#14
0
 /// <summary>
 /// Constructs the direction of the given vector.
 /// </summary>
 public Direction(FreeVector vector)
 {
     this._vector = new DoubleVector(vector.X.InInches(), vector.Y.InInches(), vector.Z.InInches());
     Normalized   = Normalize(_vector);
 }
示例#15
0
 /// <summary>
 /// Creates the corresponding bound vector using the origin as the base point.
 /// </summary>
 public Vector(FreeVector vector) : this(Point.Origin, vector.Direction, vector.GetMagnitude())
 {
 }
示例#16
0
 public static Shift FromVector(FreeVector translation) => new Shift(translation);
 /// <summary>
 /// Creates a new line segment with the given BasePoint in the same direction and magnitude as the passed vector
 /// </summary>
 public LineSegment([NotNull] Point basePoint, FreeVector passedVector)
     : this(basePoint, basePoint.Translate(passedVector), passedVector)
 {
 }
示例#18
0
 public new Rectangle Translate(FreeVector vector)
 {
     return(new Rectangle(this.Translate <Polygon>(vector), ValidateOption.Dont));
 }
示例#19
0
 public Polyhedron Translate(FreeVector translation)
 {
     return(new Polyhedron(this.Faces.Translate(translation), ValidateOption.Dont));
 }
示例#20
0
 /// <summary>
 /// Translates the line the given distance in the given direction
 /// </summary>
 /// <returns></returns>
 public Line Translate(FreeVector translation) =>
 ApplyAffineTransformation(translation.AsAffineTransformation());
示例#21
0
 public static List <T> Translate <T>(this IEnumerable <T> items, FreeVector translation)
     where T : IShift <T>
 {
     return(items.Select(item => item.Translate(translation)).ToList());
 }
示例#22
0
 public new Polygon Translate(FreeVector translation)
 {
     return(new Polygon(this.Vertices.Translate(translation), ValidateOption.Dont));
 }
 internal static void PostTranslateBy(this double[,] matrix, FreeVector vector)
 {
     matrix[0, 3] += vector.X.InInches();
     matrix[1, 3] += vector.Y.InInches();
     matrix[2, 3] += vector.Z.InInches();
 }
示例#24
0
 public Point Translate(FreeVector translation)
 {
     return(this + translation);
 }
 private LineSegment(Point basePoint, Point endPoint, FreeVector vector)
     : this(basePoint, endPoint, vector.Direction, vector.GetMagnitude())
 {
 }
示例#26
0
 public Plane Translate(FreeVector translation) => ApplyIsometry(translation);
 internal static void ConjugateByTranslation(this double[,] matrix, FreeVector vector)
 {
     matrix.PreTranslateBy(vector.Negate());
     matrix.PostTranslateBy(vector);
 }
示例#28
0
 public static DoubleVector ToVectorInInches(this FreeVector vector) =>
 new DoubleVector(vector.X.InInches(), vector.Y.InInches(), vector.Z.InInches());
示例#29
0
 public static T Translate <T>(this T item, FreeVector translation)
     where T : IShift <T>
 {
     return(item.Translate(translation));
 }