//todo: FINISH THIS TEST
        public void CreateLineFromFacetAtZIndex_CreatesAccurateLine()
        {
            var l1 = new SliceLine
            {
                Points = new List <SlicePoint>
                {
                    new SlicePoint(2, 2),
                    new SlicePoint(-2, -2)
                },
                Normal = new SlicePoint(-1, 1)
            };
            var f1 = new Facet
            {
                Vertices = new List <Vertex>
                {
                    new Vertex {
                        X = 0, Y = 0, Z = 0
                    },
                    new Vertex {
                        X = 5, Y = 5, Z = 5
                    },
                    new Vertex {
                        X = -5, Y = -5, Z = 5
                    }
                },
                Normal = new Normal {
                    X = 1, Y = -1, Z = 0
                }
            };

            var fN = f1.Normal;
        }
Пример #2
0
        public static SliceLine CreateLineFromFacetAtZIndex(Facet facet, float z)
        {
            // This won't work for flat horizontal plane vertices, so throw if that's what we've got
            if (Math.Abs(facet.Normal.Z) == 1)
            {
                throw new Exception("Cannot create lines for flat horizontal planes");
            }
            var verts      = facet.Vertices;
            var returnLine = new SliceLine();

            // If any vertices are ON the z-index, just return that line
            returnLine.Points.AddRange(verts.Where(v => v.Z == z).Select(v => new SlicePoint(v.X, v.Y)));
            // For uniformity, I'm representing a point as a "line" between two of the same point
            // It's janky, I'll refactor later
            if (returnLine.Points.Count == 1)
            {
                returnLine.Points.Add(returnLine.Points[0]);
            }
            if (returnLine.Points.Count == 2)
            {
                returnLine.Normal = new SlicePoint(facet.Normal.X, facet.Normal.Y);
                return(returnLine);
            }
            // If no vertices are ON the z-index, find the two points where they CROSS it
            if ((verts[0].Z - z) / (verts[1].Z - z) < 0)
            {
                returnLine.Points.Add(CalculateZIntercept(verts[0], verts[1], z));
            }
            if ((verts[2].Z - z) / (verts[1].Z - z) < 0)
            {
                returnLine.Points.Add(CalculateZIntercept(verts[2], verts[1], z));
            }

            if (returnLine.Points.Count < 2)
            {
                returnLine.Points.Add(CalculateZIntercept(verts[0], verts[2], z));
            }

            returnLine.Normal = new SlicePoint(facet.Normal.X, facet.Normal.Y);

            if (!returnLine.Validate())
            {
                throw new InvalidOperationException("Invalid Point Data");
            }

            return(returnLine);
        }
Пример #3
0
        private void FindSelfCollisions()
        {
            for (var i = 0; i < Lines.Count; i++)
            {
                var line1 = Lines[i];
                for (var j = i + 1; j < Lines.Count; j++)
                {
                    var     line2 = Lines[j];
                    Vector2 point;
                    if (CollisionSegments(line1, line2, out point))
                    {
                        Lines.Add(new Line2d
                        {
                            Point0 = point,
                            Point1 = line1.Point1
                        });
                        line1.Point1 = point;
                        Lines.Add(new Line2d
                        {
                            Point0 = point,
                            Point1 = line2.Point1
                        });
                        line2.Point1 = point;
                    }
                }
            }
            var tmpIndices = new List <int>();

            slicePointsDictionary.Clear();
            foreach (var line in Lines)
            {
                line.UpdateDirection();
                for (var i = 0; i < 2; i++)
                {
                    if (line.Point0[i] < line.Point1[i])
                    {
                        line.A[i] = line.Point0[i];
                        line.B[i] = line.Point1[i];
                    }
                    else
                    {
                        line.A[i] = line.Point1[i];
                        line.B[i] = line.Point0[i];
                    }
                }
                tmpIndices.Clear();
                for (var i = 0; i < 2; i++)
                {
                    var point = i == 0 ? line.Point0 : line.Point1;
                    var index = slicePoints.Count;
                    if (!slicePointsDictionary.TryGetValue(point, out index))
                    {
                        index = slicePoints.Count;
                        slicePoints.Add(new SlicePoint
                        {
                            Coordinate = point
                        });
                        slicePointsDictionary.Add(point, index);
                    }
                    tmpIndices.Add(index);
                }
                var sliceLine = new SliceLine
                {
                    Point0 = slicePoints[tmpIndices[0]],
                    Point1 = slicePoints[tmpIndices[1]],
                    Line   = line
                };
                sliceLine.Point0.Lines.Add(sliceLine);
                sliceLine.Point1.Lines.Add(sliceLine);
                sliceLines.Add(sliceLine);
            }
        }
Пример #4
0
 private void FindSelfCollisions()
 {
     for (var i = 0; i < Lines.Count; i++)
     {
         var line1 = Lines[i];
         for (var j = i + 1; j < Lines.Count; j++)
         {
             var line2 = Lines[j];
             Vector2 point;
             if (CollisionSegments(line1, line2, out point))
             {
                 Lines.Add(new Line2d
                 {
                     Point0 = point,
                     Point1 = line1.Point1
                 });
                 line1.Point1 = point;
                 Lines.Add(new Line2d
                 {
                     Point0 = point,
                     Point1 = line2.Point1
                 });
                 line2.Point1 = point;
             }
         }
     }
     var tmpIndices = new List<int>();
     slicePointsDictionary.Clear();
     foreach (var line in Lines)
     {
         line.UpdateDirection();
         for (var i = 0; i < 2; i++)
         {
             if (line.Point0[i] < line.Point1[i])
             {
                 line.A[i] = line.Point0[i];
                 line.B[i] = line.Point1[i];
             }
             else
             {
                 line.A[i] = line.Point1[i];
                 line.B[i] = line.Point0[i];
             }
         }
         tmpIndices.Clear();
         for (var i = 0; i < 2; i++)
         {
             var point = i == 0 ? line.Point0 : line.Point1;
             var index = slicePoints.Count;
             if (!slicePointsDictionary.TryGetValue(point, out index))
             {
                 index = slicePoints.Count;
                 slicePoints.Add(new SlicePoint
                 {
                     Coordinate = point
                 });
                 slicePointsDictionary.Add(point, index);
             }
             tmpIndices.Add(index);
         }
         var sliceLine = new SliceLine
         {
             Point0 = slicePoints[tmpIndices[0]],
             Point1 = slicePoints[tmpIndices[1]],
             Line = line
         };
         sliceLine.Point0.Lines.Add(sliceLine);
         sliceLine.Point1.Lines.Add(sliceLine);
         sliceLines.Add(sliceLine);
     }
 }