Esempio n. 1
0
        public bool ClosestPoints(Line3D b, out Point3D pa, out Point3D pb)
        {
            pa = null;
            pb = null;

            if (Vector == b.Vector || Vector == -b.Vector) return false;

            Vector3D p0 = Point.ToVector();
            Vector3D p1 = b.Point.ToVector();
            Vector3D d0 = Vector;
            Vector3D d1 = b.Vector;
            Vector3D d0n = d0.Normalize();

            Vector3D c = new Vector3D();
            Vector3D d = new Vector3D();

            d.X = d1.X - d0n.X * (d0.X * d1.X + d0.Y * d1.Y + d0.Z * d1.Z);
            c.X = p1.X - p0.X + d0n.X * (d0.X * p0.X + d0.Y * p0.Y + d0.Z * p0.Z);

            d.Y = d1.Y - d0n.Y * (d0.X * d1.X + d0.Y * d1.Y + d0.Z * d1.Z);
            c.Y = p1.Y - p0.Y + d0n.Y * (d0.X * p0.X + d0.Y * p0.Y + d0.Z * p0.Z);

            d.Z = d1.Z - d0n.Z * (d0.X * d1.X + d0.Y * d1.Y + d0.Z * d1.Z);
            c.Z = p1.Z - p0.Z + d0n.Z * (d0.X * p0.X + d0.Y * p0.Y + d0.Z * p0.Z);

            double t = -(c.X * d.X + c.Y * d.Y + c.Z * d.Z) / (d.X * d.X + d.Y * d.Y + d.Z * d.Z);

            pb = b.Point + (b.Vector * t);
            pa = ClosestPoint(pb);

            return true;
        }
Esempio n. 2
0
        public Slice3D(Vector3D normal, Point3D topLeft, double width, double height)
        {
            Vector3D right = normal.Rotate(Vector3D.AxisY, -90.0);
            Vector3D down = normal.Rotate(Vector3D.AxisX, -90.0);

            _topLeft = topLeft;
            _topRight = _topLeft + (right * width);
            _bottomLeft = _topLeft + (down * height);
            _bottomRight = _bottomLeft + (right * width);

            _normal = normal;
            _width = width;
            _height = height;
            _plane = new Plane3D(normal, _topLeft);
        }
Esempio n. 3
0
 public Point3D ClosestPoint(Point3D point)
 {
     Vector3D pv = point.ToVector();
     double d = Normal.DotProduct(pv - Point.ToVector());
     return (pv - (Normal * d)).ToPoint();
 }
Esempio n. 4
0
        public bool Intersect(Plane3D b, out Line3D intersection)
        {
            intersection = null;

            if (IsParallel(b)) return false;

            Point3D p;
            Vector3D v1 = Normal.CrossProduct(b.Normal);
            Vector3D v2 = new Vector3D(v1.X * v1.X, v1.Y * v1.Y, v1.Z * v1.Z);
            double w1 = -Distance;
            double w2 = -b.Distance;
            double id;

            if ((v2.Z > v2.Y) && (v2.Z > v2.X) && (v2.Z > Double.Epsilon))
            {
                // point on XY plane
                id = 1.0 / v1.Z;
                p = new Point3D(Normal.Y * w2 - b.Normal.Y * w1, b.Normal.X * w1 - Normal.X * w2, 0.0);
            }
            else if ((v2.Y > v2.X) && (v2.Y > Double.Epsilon))
            {
                // point on XZ plane
                id = -1.0 / v1.Y;
                p = new Point3D(Normal.Z * w2 - b.Normal.Z * w1, 0.0, b.Normal.Y * w1 - Normal.Y * w2);
            }
            else if (v2.X > Double.Epsilon)
            {
                // point on YZ plane
                id = 1.0 / v1.X;
                p = new Point3D(0.0, Normal.Z * w2 - b.Normal.Z * w1, b.Normal.Y * w1 - Normal.Y * w2);
            }
            else return false;

            p = (p.ToVector() * id).ToPoint();
            id = 1.0 / Math.Sqrt(v2.X + v2.Y + v2.Z);
            v1 *= id;

            intersection = new Line3D(p, p.ToVector() + v1);

            return true;
        }
Esempio n. 5
0
 public bool Intersect(Line3D line, out Point3D intersection)
 {
     if (IsParallel(line))
     {
         intersection = null;
         return false;
     }
     double t = (Distance - Normal.DotProduct(line.Point.ToVector())) / Normal.DotProduct(line.Vector);
     intersection = line.Point + (t * line.Vector);
     return true;
 }
Esempio n. 6
0
        public Plane3D(Point3D a, Point3D b, Point3D c)
        {
            Vector3D av = a.ToVector();
            Vector3D bv = b.ToVector();
            Vector3D cv = c.ToVector();

            _normal = (bv - av).CrossProduct(cv - av).Normalize();
            _point = a;
        }
Esempio n. 7
0
 public Plane3D(Vector3D normal, Point3D point)
 {
     _normal = normal;
     _point = point;
 }
Esempio n. 8
0
 public Segment3D(Point3D a, Point3D b)
 {
     _a = a.Clone();
     _b = b.Clone();
 }
Esempio n. 9
0
 public Segment3D()
 {
     _a = Point3D.Zero.Clone();
     _b = Point3D.Zero.Clone();
 }
Esempio n. 10
0
 public Point3D ClosestPoint(Point3D point)
 {
     double n = (point.ToVector() - Point.ToVector()).DotProduct(Vector);
     double d = Vector.Length();
     return Point + (Vector * (n / d));
 }
Esempio n. 11
0
 public Line3D(Line3D line)
 {
     _point = line.Point.Clone();
     _vector = line.Vector.Clone();
 }
Esempio n. 12
0
 public Line3D(Point3D p, Vector3D v)
 {
     _point = p.Clone();
     _vector = v.Clone();
 }
Esempio n. 13
0
 public Line3D()
 {
     _point = Point3D.Zero.Clone();
     _vector = Vector3D.Zero.Clone();
 }
Esempio n. 14
0
 public double Distance(Point3D b)
 {
     return Math.Sqrt((X - b.X) * (X - b.X) + (Y - b.Y) * (Y - b.Y) + (Z - b.Z) * (Z - b.Z));
 }
Esempio n. 15
0
 public Point3D(Point3D v)
 {
     _x = v.X;
     _y = v.Y;
     _z = v.Z;
 }
Esempio n. 16
0
 public Point3D Project(Point3D point)
 {
     Point3D p = Plane.ClosestPoint(point);
     //normal vector?
     throw new NotImplementedException();
     //return p;
 }