Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Vector8l"/> using the specified vector and values.
 /// </summary>
 /// <param name="value">A vector containing the values with which to initialize the first 3 components</param>
 /// <param name="v3">Value for the V3 component of the vector.</param>
 /// <param name="v4">Value for the V4 component of the vector.</param>
 /// <param name="v5">Value for the V5 component of the vector.</param>
 /// <param name="v6">Value for the V6 component of the vector.</param>
 /// <param name="v7">Value for the V7 component of the vector.</param>
 public Vector8l(Vector3l value, long v3, long v4, long v5, long v6, long v7, long v8, long v9, long v10)
 {
     V0 = value.X;
     V1 = value.Y;
     V2 = value.Z;
     V3 = v3;
     V4 = v4;
     V5 = v5;
     V6 = v6;
     V7 = v7;
 }
Esempio n. 2
0
        public IEnumerable<Tuple<Point3l, Point3l>> Trace(Point3l start, Point3l end)
        {
            var x0 = start.X / GridSize.Width;
            var y0 = start.Y / GridSize.Height;
            var z0 = start.Z / GridSize.Depth;

            var x1 = end.X / GridSize.Width;
            var y1 = end.Y / GridSize.Height;
            var z1 = end.Z / GridSize.Depth;

            var dir = new Vector3l(end.X - start.X, end.Y - start.Y, end.Z - start.Z);

            var dx = Math.Sign(dir.X);
            var dy = Math.Sign(dir.Y);
            var dz = Math.Sign(dir.Z);

            var deltax = (double)GridSize.Width / Math.Abs(dir.X);
            var deltay = (double)GridSize.Height / Math.Abs(dir.Y);
            var deltaz = (double)GridSize.Depth / Math.Abs(dir.Z);

            var minx = x0 * GridSize.Width;
            var maxx = minx + GridSize.Width;

            var miny = y0 * GridSize.Height;
            var maxy = miny + GridSize.Height;

            var minz = z0 * GridSize.Depth;
            var maxz = minz + GridSize.Depth;

            var distx = ((dx >= 0) ? (maxx - start.X) : (start.X - minx)) / (double)GridSize.Width;
            var disty = ((dy >= 0) ? (maxy - start.Y) : (start.Y - miny)) / (double)GridSize.Height;
            var distz = ((dz >= 0) ? (maxz - start.Z) : (start.Z - minz)) / (double)GridSize.Depth;

            var tx = distx * deltax;
            var ty = disty * deltay;
            var tz = distz * deltaz;

            var prev = new Point3l(x0, y0, z0);
            var hit = start;
            while (true)
            {
                var grid = new Point3l(x0, y0, z0);
                yield return Tuple.Create(grid, hit);

                prev = grid;

                if (tx <= ty && tx <= tz)
                {
                    if (x0 == x1) break;

                    hit = new Point3l(
                        start.X + (long)(dir.X * tx),
                        start.Y + (long)(dir.Y * tx),
                        start.Z + (long)(dir.Z * tz));

                    tx += deltax;
                    x0 += dx;
                }
                else if(ty <= tz)
                {
                    if (y0 == y1) break;

                    hit = new Point3l(
                        start.X + (long)(dir.X * tx),
                        start.Y + (long)(dir.Y * tx),
                        start.Z + (long)(dir.Z * tz));

                    ty += deltay;
                    y0 += dy;
                }
                else 
                {
                    if (z0 == z1) break;

                    hit = new Point3l(
                        start.X + (long)(dir.X * tx),
                        start.Y + (long)(dir.Y * tx),
                        start.Z + (long)(dir.Z * tz));

                    tz += deltaz;
                    z0 += dz;
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Subtracts a vector from a point and returns the result.
 /// </summary>
 /// <param name="point">The point value to subtract from (the minuend).</param>
 /// <param name="vector">The vector value to subtract (the subtrahend).</param>
 /// <returns>The result of subtracting vector from point (the difference).</returns>
 public static Point3l Subtract(Point3l point, Vector3l vector)
 {
     return(new Point3l(point.X - vector.X, point.Y - vector.Y, point.Z - vector.Z));
 }
Esempio n. 4
0
 /// <summary>
 /// Adds a point and a vector and returns the result.
 /// </summary>
 /// <param name="point">The point value to add.</param>
 /// <param name="vector">The vector value to add.</param>
 /// <returns>The sum of left and right.</returns>
 public static Point3l Add(Point3l point, Vector3l vector)
 {
     return(new Point3l(point.X + vector.X, point.Y + vector.Y, point.Z + vector.Z));
 }
Esempio n. 5
0
 /// <summary>
 /// Projects a point onto a vector, returns the distance of the projection from the origin.
 /// </summary>
 /// <param name="vector">The vector to project onto.</param>
 /// <param name="point">The point to project.</param>
 /// <returns>The distance from the origin of the projection.</returns>
 public static long Project(Point3l point, Vector3l vector)
 {
     return(vector.X * point.X + vector.Y * point.Y + vector.Z * point.Z);
 }
Esempio n. 6
0
        public IEnumerable <Tuple <Point3l, Point3l> > Trace(Point3l start, Point3l end)
        {
            var x0 = start.X / GridSize.Width;
            var y0 = start.Y / GridSize.Height;
            var z0 = start.Z / GridSize.Depth;

            var x1 = end.X / GridSize.Width;
            var y1 = end.Y / GridSize.Height;
            var z1 = end.Z / GridSize.Depth;

            var dir = new Vector3l(end.X - start.X, end.Y - start.Y, end.Z - start.Z);

            var dx = Math.Sign(dir.X);
            var dy = Math.Sign(dir.Y);
            var dz = Math.Sign(dir.Z);

            var deltax = (double)GridSize.Width / Math.Abs(dir.X);
            var deltay = (double)GridSize.Height / Math.Abs(dir.Y);
            var deltaz = (double)GridSize.Depth / Math.Abs(dir.Z);

            var minx = x0 * GridSize.Width;
            var maxx = minx + GridSize.Width;

            var miny = y0 * GridSize.Height;
            var maxy = miny + GridSize.Height;

            var minz = z0 * GridSize.Depth;
            var maxz = minz + GridSize.Depth;

            var distx = ((dx >= 0) ? (maxx - start.X) : (start.X - minx)) / (double)GridSize.Width;
            var disty = ((dy >= 0) ? (maxy - start.Y) : (start.Y - miny)) / (double)GridSize.Height;
            var distz = ((dz >= 0) ? (maxz - start.Z) : (start.Z - minz)) / (double)GridSize.Depth;

            var tx = distx * deltax;
            var ty = disty * deltay;
            var tz = distz * deltaz;

            var prev = new Point3l(x0, y0, z0);
            var hit  = start;

            while (true)
            {
                var grid = new Point3l(x0, y0, z0);
                yield return(Tuple.Create(grid, hit));

                prev = grid;

                if (tx <= ty && tx <= tz)
                {
                    if (x0 == x1)
                    {
                        break;
                    }

                    hit = new Point3l(
                        start.X + (long)(dir.X * tx),
                        start.Y + (long)(dir.Y * tx),
                        start.Z + (long)(dir.Z * tz));

                    tx += deltax;
                    x0 += dx;
                }
                else if (ty <= tz)
                {
                    if (y0 == y1)
                    {
                        break;
                    }

                    hit = new Point3l(
                        start.X + (long)(dir.X * tx),
                        start.Y + (long)(dir.Y * tx),
                        start.Z + (long)(dir.Z * tz));

                    ty += deltay;
                    y0 += dy;
                }
                else
                {
                    if (z0 == z1)
                    {
                        break;
                    }

                    hit = new Point3l(
                        start.X + (long)(dir.X * tx),
                        start.Y + (long)(dir.Y * tx),
                        start.Z + (long)(dir.Z * tz));

                    tz += deltaz;
                    z0 += dz;
                }
            }
        }