Пример #1
0
 internal bool SaveTriangleToNode(SphereNode sn, int idx)
 {
     if (!sn.triangle_Idx.Contains(idx))
     {
         sn.triangle_Idx.Add(idx);
     }
     return(true);
 }
Пример #2
0
 internal bool CreateSphereNodes()
 {
     for (int i = 0; i < this._mesh.TriangleCount; i++)
     {
         List <int> triIndexes = vertexIndexByTri[i];
         SphereNode sp         = SphereNode.ByThreePoints(this.vertices[triIndexes[0]], this.vertices[triIndexes[1]], this.vertices[triIndexes[2]]);
         SaveTriangleToNode(sp, i);
         this.nodes.Add(sp);
     }
     return(true);
 }
Пример #3
0
        public static IList <SphereNode> SphereNodesByMesh(MeshToolkit mesh)
        {
            List <Point>      vertices     = mesh.Vertices();
            List <int>        vertexIndex  = mesh.VertexIndicesByTri();
            var               setOfIndexes = Core.List.Chop <int>(vertexIndex, 3);
            List <SphereNode> sphereNodes  = new List <SphereNode>();

            foreach (var ind in setOfIndexes)
            {
                sphereNodes.Add(SphereNode.ByThreePoints(vertices[ind[0]], vertices[ind[1]], vertices[ind[2]]));
            }

            return(sphereNodes);
        }
Пример #4
0
        //TODO: Simplify method to translate point without using point geometries.
        public static SphereNode BoundingSphereNode(SphereNode sphere1, SphereNode sphere2)
        {
            SphereNode minSp           = (sphere1.radius < sphere2.radius) ? sphere1 : sphere2;
            SphereNode maxSp           = (sphere1.radius < sphere2.radius) ? sphere2 : sphere1;
            double     centersDistance = DistanceBetweenCenters(minSp, maxSp);

            double[] vectorCoord = minSp.center.Zip(maxSp.center, (sp1, sp2) => sp2 - sp1).ToArray();
            using (Point minCenter = SphereNode.Center(minSp))
                using (Point maxCenter = SphereNode.Center(maxSp))
                {
                    Vector v = Vector.ByTwoPoints(minCenter, maxCenter);
                    double translationDist = (centersDistance + (maxSp.radius - minSp.radius)) * 0.5;

                    Point  center = (Point)minCenter.Translate(v, translationDist);
                    double radius = (centersDistance + minSp.radius + maxSp.radius) * 0.5;
                    return(new SphereNode(new double[3] {
                        center.X, center.Y, center.Z
                    }, radius));
                }
        }
Пример #5
0
        public void Tessellate(IRenderPackage package, TessellationParameters parameters)
        {
            package.RequiresPerVertexColoration = true;
            Point center = SphereNode.Center(this);

            Autodesk.DesignScript.Geometry.Geometry geometry = Sphere.ByCenterPointRadius(center, this.radius);
            byte[] color = new byte[] { 0, 200, 200, 50 };
            // As you add more data to the render package, you need
            // to keep track of the index where this coloration will
            // start from.

            geometry.Tessellate(package, parameters);

            if (package.MeshVertexCount > 0)
            {
                package.ApplyMeshVertexColors(CreateColorByteArrayOfSize(package.MeshVertexCount, color[0], color[1], color[2], color[3]));
            }
            center.Dispose();
            geometry.Dispose();
        }
Пример #6
0
 public static double DistanceBetweenCenters(SphereNode sphere1, SphereNode sphere2)
 {
     double[] sq = sphere1.center.Zip(sphere2.center, (s1, s2) => Math.Pow((s2 - s1), 2)).ToArray();
     return(Math.Sqrt(sq.Sum()));
 }
Пример #7
0
 public static Point Center(SphereNode sphereNode)
 {
     return(Point.ByCoordinates(sphereNode.center[0], sphereNode.center[1], sphereNode.center[2]));
 }