Exemplo n.º 1
0
 public void GetNormal_PlanarPolygon_ReturnsCorrectResult()
 {
     var p = new Polygon3D();
     p.Points.Add(new Point3D(0, 0, 0));
     p.Points.Add(new Point3D(1, 0, 0));
     p.Points.Add(new Point3D(1, 1, 0));
     p.Points.Add(new Point3D(0, 1, 0));
     Assert.AreEqual(new Vector3D(0, 0, 1), p.GetNormal());
 }
Exemplo n.º 2
0
 public void IsPlanar_NotPlanarPolygon_ReturnsFalse()
 {
     var p = new Polygon3D();
     p.Points.Add(new Point3D(0, 0, 0));
     p.Points.Add(new Point3D(1, 0, 0));
     p.Points.Add(new Point3D(1, 1, 0));
     p.Points.Add(new Point3D(0, 1, 0.3));
     Assert.IsFalse(p.IsPlanar());
 }
Exemplo n.º 3
0
 public void IsPlanar_PlanarPolygon_ReturnsTrue()
 {
     var p = new Polygon3D();
     p.Points.Add(new Point3D(0, 0, 0));
     p.Points.Add(new Point3D(1, 0, 0));
     p.Points.Add(new Point3D(1, 1, 0.76));
     p.Points.Add(new Point3D(0, 1, 0.76));
     Assert.IsTrue(p.IsPlanar());
 }
Exemplo n.º 4
0
 public void Flatten_PlanarPolygon2_ReturnsCorrectResult()
 {
     var p = new Polygon3D();
     p.Points.Add(new Point3D(0, 0, 4));
     p.Points.Add(new Point3D(1, 0, 4));
     p.Points.Add(new Point3D(1, 1, 4.01));
     p.Points.Add(new Point3D(0, 1, 4.01));
     var p2 = p.Flatten();
     Assert.AreEqual(p2.Points.Count, 4);
     var tri = p2.Triangulate();
     Assert.AreEqual(6, tri.Count);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Adds a polygon defined by vertex indices (uses the sweep line algorithm).
        /// </summary>
        /// <param name="vertexIndices">The vertex indices.</param>
        public void AddPolygonByTriangulation(IList<int> vertexIndices)
        {
            var points = vertexIndices.Select(vi => this.positions[vi]).ToList();

            var poly3D = new Polygon3D(points);

            // Transform the polygon to 2D
            var poly2D = poly3D.Flatten();

            // Triangulate
            var triangulatedIndices = poly2D.Triangulate();
            if (triangulatedIndices != null)
            {
                foreach (var i in triangulatedIndices)
                {
                    this.triangleIndices.Add(vertexIndices[i]);
                }
            }
        }
Exemplo n.º 6
0
 private static void OnDPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     var refPlane = d as RefPlane;
     if (refPlane.Plane == null) return;
     var center = refPlane.Plane.Position;
     var normal = refPlane.ReverseSide ? refPlane.Plane.Normal : -refPlane.Plane.Normal;
     var xVector = refPlane.ReverseSide ? refPlane.XAxis : -refPlane.XAxis; //refPlane.Plane.Normal.FindAnyPerpendicular();
     var yVector = Vector3D.CrossProduct(xVector, normal);
     var poly3D = new Polygon3D(new List<Point3D>() { center - refPlane.Size * (xVector - yVector) / 2,
         center - refPlane.Size * (xVector + yVector) / 2, center + refPlane.Size * (xVector - yVector) / 2,
         center + refPlane.Size * (xVector + yVector) / 2 });
     var points = new List<Point3D>() { poly3D.Points[0] };
     for (int i = 1; i < 7; i++)
         points.Add(!i.IsEven() ? poly3D.Points[(i + 1) / 2] : points[i - 1]);
     points.Add(poly3D.Points[0]);
     points.AddMany(poly3D.Points[0] - refPlane.Size / 16 * yVector, poly3D.Points[0] - refPlane.Size / 16 * yVector + refPlane.Size / 4 * xVector);
     points.AddMany(points.Last<Point3D>(), poly3D.Points[0] + refPlane.Size / 4 * xVector);
     refPlane.Points = points;
     //Fill
     refPlane.quad.Point1 = poly3D.Points[0];
     refPlane.quad.Point2 = poly3D.Points[1];
     refPlane.quad.Point3 = poly3D.Points[2];
     refPlane.quad.Point4 = poly3D.Points[3];
 }