Esempio n. 1
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static List <int> Side(this Plane plane, List <Point> points, double tolerance = Tolerance.Distance)
        {
            List <double> result = points.Select(x => Create.Vector(x).DotProduct(plane.Normal)).ToList();

            int[] sameSide = new int[result.Count];

            double d = -plane.Normal.DotProduct(Create.Vector(plane.Origin));

            for (int i = 0; i < result.Count; i++)
            {
                if (result[i] + d > tolerance)
                {
                    sameSide[i] = 1;
                }
                else if (result[i] + d < -tolerance)
                {
                    sameSide[i] = -1;
                }
                else
                {
                    sameSide[i] = 0;
                }
            }

            return(sameSide.ToList());
        }
Esempio n. 2
0
        /***************************************************/

        public static List <IntegrationSlice> IntegrationSlices(List <ICurve> edges, Vector direction, double increment = 0.001, double tolerance = Tolerance.Distance)
        {
            List <IntegrationSlice> slices = new List <IntegrationSlice>();

            List <double> cutAt         = new List <double>();
            List <double> sliceSegments = new List <double>();
            Plane         p             = new Plane {
                Origin = oM.Geometry.Point.Origin, Normal = direction
            };

            for (int i = 0; i < edges.Count; i++)
            {
                for (int j = 0; j < edges[i].IControlPoints().Count; j++)
                {
                    cutAt.Add(Query.DotProduct(Create.Vector(edges[i].IControlPoints()[j]), p.Normal));
                }
            }

            cutAt.Sort();
            cutAt = cutAt.Distinct <double>().ToList();

            double currentValue = Query.DotProduct(Create.Vector(Query.Bounds(new PolyCurve {
                Curves = edges
            }).Min), p.Normal);
            double max = Query.DotProduct(Create.Vector(Query.Bounds(new PolyCurve {
                Curves = edges
            }).Max), p.Normal);
            int index = 0;

            while (currentValue < max)
            {
                if (cutAt.Count > index && currentValue > cutAt[index])
                {
                    sliceSegments.Add(cutAt[index]);
                    index++;
                }
                else
                {
                    sliceSegments.Add(currentValue);
                    currentValue += increment;
                }
            }

            sliceSegments.Add(max);

            for (int i = 0; i < sliceSegments.Count - 1; i++)
            {
                if (sliceSegments[i] == sliceSegments[i + 1])
                {
                    continue;
                }

                currentValue = (sliceSegments[i] + sliceSegments[i + 1]) / 2;
                slices.Add(Query.SliceAt(edges, currentValue, -sliceSegments[i] + sliceSegments[i + 1], p, tolerance));
            }

            return(slices);
        }
Esempio n. 3
0
        /***************************************************/
        /**** public Methods - Vectors                  ****/
        /***************************************************/

        //TODO: Testing needed!!
        public static Line PlaneIntersection(this Plane plane1, Plane plane2, double tolerance = Tolerance.Distance)
        {
            if (plane1.Normal.IsParallel(plane2.Normal) != 0)
            {
                return(null);
            }

            //Calculate tangent of line perpendicular to the normal of the two planes
            Vector tangent = plane1.Normal.CrossProduct(plane2.Normal).Normalise();

            //d-values from plane equation: ax+by+cz+d=0
            double d1 = -plane1.Normal.DotProduct(Create.Vector(plane1.Origin));
            double d2 = -plane2.Normal.DotProduct(Create.Vector(plane2.Origin));

            Point orgin;

            Vector n1 = plane1.Normal;
            Vector n2 = plane2.Normal;

            if (Math.Abs(tangent.Z) >= Tolerance.Angle)
            {
                double x0 = (n1.Y * d2 - n2.Y * d1) / (n1.X * n2.Y - n2.X * n1.Y);
                double y0 = (n2.X * d1 - n1.X * d2) / (n1.X * n2.Y - n2.X * n1.Y);

                orgin = new Point {
                    X = x0, Y = y0, Z = 0
                };
            }
            else if (Math.Abs(tangent.Y) >= Tolerance.Angle)
            {
                double x0 = (n1.Z * d2 - n2.Z * d1) / (n1.X * n2.Z - n2.X * n1.Z);
                double z0 = (n2.X * d1 - n1.X * d2) / (n1.X * n2.Z - n2.X * n1.Z);
                orgin = new Point {
                    X = x0, Y = 0, Z = z0
                };
            }
            else
            {
                double y0 = (n1.Z * d2 - n2.Z * d1) / (n1.Y * n2.Z - n2.Y * n1.Z);
                double z0 = (n2.Y * d1 - n1.Y * d2) / (n1.Y * n2.Z - n2.Y * n1.Z);
                orgin = new Point {
                    X = 0, Y = y0, Z = z0
                };
            }

            Line result = new Line {
                Start = orgin, End = orgin + tangent
            };

            result.Infinite = true;
            return(result);
        }