Beispiel #1
0
        public static bool TrianglePlane(Triangle3D t, Plane3D plane, out Line3D intersect)
        {
            var abLine = new Line3D(t.A, t.B);
            var acLine = new Line3D(t.A, t.C);
            var bcLine = new Line3D(t.B, t.C);

            if (plane.IntersectLine(abLine, out var abIntersect))
            {
                if (plane.IntersectLine(acLine, out var acIntersect))
                {
                    intersect = new Line3D(
                        abLine.PointAt(abIntersect),
                        acLine.PointAt(acIntersect));
                    return(true);
                }
                else if (plane.IntersectLine(bcLine, out var bcIntersect))
                {
                    intersect = new Line3D(
                        abLine.PointAt(abIntersect),
                        bcLine.PointAt(bcIntersect));
                    return(true);
                }
                else
                {
                    intersect = new Line3D();
                    return(false);
                }
            }
            else if (plane.IntersectLine(bcLine, out var bcIntersect))
            {
                if (plane.IntersectLine(acLine, out var acIntersect))
                {
                    intersect = new Line3D(
                        bcLine.PointAt(bcIntersect),
                        acLine.PointAt(acIntersect));
                    return(true);
                }
                else
                {
                    throw new ArgumentException("triangle appears invalid");
                }
            }
            else
            {
                intersect = new Line3D();
                return(false);
            }
        }
Beispiel #2
0
        public Arrow3D(Vector3d p1, Vector3d p2, Vector3d normal)
        {
            this.u = new Vector3d(p1);
            this.v = new Vector3d(p2);
            // triangle
            double d = (p2 - p1).Length() / 10;

            d = Math.Max(d, min_dcap);
            d = Math.Min(d, max_dcap);
            Vector3d lineDir = (p2 - p1).normalize();
            Vector3d c       = p2 - lineDir * d;
            Vector3d dir     = normal.Cross(lineDir).normalize();

            dir = normal;
            if (double.IsNaN(dir.x) || double.IsNaN(dir.y) || double.IsNaN(dir.z))
            {
                dir = normal.Cross(lineDir).normalize();
            }
            double   d2 = d * 0.6;
            Vector3d v1 = c + dir * d2;
            Vector3d v2 = c - dir * d2;

            this.cap = new Triangle3D(v1, p2, v2);
        }