예제 #1
0
파일: Geometry3D.cs 프로젝트: GMZ/fo-dicom
        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;
        }
예제 #2
0
 public bool IsParallel(Line3D line)
 {
     return(line.Vector.DotProduct(Normal) == 0.0);
 }
예제 #3
0
 public Line3D(Line3D line)
 {
     _point  = line.Point.Clone();
     _vector = line.Vector.Clone();
 }
예제 #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;
        }
예제 #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;
 }
예제 #6
0
 public bool IsParallel(Line3D line)
 {
     return line.Vector.DotProduct(Normal) == 0.0;
 }
예제 #7
0
 public Line3D(Line3D line)
 {
     _point = line.Point.Clone();
     _vector = line.Vector.Clone();
 }
예제 #8
0
 public Line3D(Line3D line)
 {
     Point  = line.Point.Clone();
     Vector = line.Vector.Clone();
 }