public void ComputeAngle()
        {
            var ind1 = Simplex1.Indices;
            var ind2 = Simplex2.Indices;

            var ind1_ext = ind2.Except(ind1).ToArray()[0];
            var vec1     = Simplex2.GetEdgeByIndex(ind1_ext);

            var ind2_ext = ind1.Except(ind2).ToArray()[0];
            var vec2     = Simplex1.GetEdgeByIndex(ind2_ext);

            var normal1 = VariousHelpers.GetNormalVector(Simplex1, vec1 - Simplex1.BasePoint);
            var normal2 = VariousHelpers.GetNormalVector(Simplex2, vec2 - Simplex2.BasePoint);

            var commonBasePoint = CommonBase.BasePoint;

            Angle = Math.PI - CommonBase.AmbiantSpace.Angle(commonBasePoint, normal1, normal2);
        }
예제 #2
0
    // Adds a ball and a halo at the input anchor position
    void AddBall(GameObject anchor)
    {
        // Instantiate ball at anchor position and add to list
        GameObject clone = (GameObject)Instantiate(ballPrefab, anchor.transform.position, anchor.transform.rotation);

        clone.name = num0.ToString();
        BList.Add(clone);
        // Instantiate halo at anchor position
        GameObject halo = (GameObject)Instantiate(haloPrefab, anchor.transform.position, anchor.transform.rotation);

        halo.name = num0.ToString();
        halo.transform.SetParent(clone.transform);
        HList.Add(halo);
        Simplex0 s = clone.AddComponent <Simplex0>();

        s.is_halo_shown = (halo_toggle % 2 == 0);
        UpdateSingle(clone);
        // Instantiate cylinder for every vertex in scene
        foreach (int b in BList_alive)
        {
            GameObject existingball = BList[b];
            GameObject cylinder     = (GameObject)Instantiate(cylinderPrefab, (anchor.transform.position + existingball.transform.position) / 2, Quaternion.FromToRotation(Vector3.up, anchor.transform.position - existingball.transform.position));
            cylinder.transform.localScale = new Vector3(0.015f, Vector3.Distance(existingball.transform.position / 2, anchor.transform.position / 2), 0.015f);
            cylinder.name = num1.ToString();
            CList.Add(cylinder);
            // Set cylinder attributes
            Simplex1 c     = cylinder.AddComponent <Simplex1>();
            Vector3  edger = clone.transform.position - existingball.transform.position;
            c.length   = edger.magnitude;
            c.is_shown = (cyl_tri_toggle % 3 < 2);
            c.is_drawn = (.05 * r >= c.length);
            UpdateSingle(cylinder);
            // Add edge index to neighbors
            s.neighbors1.Add(num1);
            existingball.GetComponent <Simplex0>().neighbors1.Add(num1);
            // Add vertex indices to neighbors
            c.neighbors0.Add(num0);
            existingball.GetComponent <Simplex0>().neighbors0.Add(num0);
            c.neighbors0.Add(System.Convert.ToInt32(existingball.name));
            s.neighbors0.Add(System.Convert.ToInt32(existingball.name));
            CList_alive.Add(num1);
            num1++;
        }
        if (!NoTriangles)
        {
            // Instantiate triangle for every pair of vertices in scene
            foreach (int c in CList_alive)
            {
                if (!CList[c].GetComponent <Simplex1>().neighbors0.Contains(num0))
                {
                    GameObject triangle = (GameObject)Instantiate(trianglePrefab, new Vector3(0, 0, 0), Quaternion.identity);
                    triangle.name = num2.ToString();
                    TList.Add(triangle);
                    triangle.transform.localScale = new Vector3(20f, 20f, 20f);
                    Simplex2   tri   = triangle.AddComponent <Simplex2>();
                    GameObject ball0 = BList[CList[c].GetComponent <Simplex1>().neighbors0[0]];
                    GameObject ball1 = BList[CList[c].GetComponent <Simplex1>().neighbors0[1]];
                    tri.newVertices = new Vector3[3] {
                        .05f * clone.transform.position, .05f * ball0.transform.position, .05f * ball1.transform.position
                    };
                    // Add triangle index to neighbors
                    s.neighbors2.Add(num2);
                    ball0.GetComponent <Simplex0>().neighbors2.Add(num2);
                    ball1.GetComponent <Simplex0>().neighbors2.Add(num2);
                    CList[c].GetComponent <Simplex1>().neighbors2.Add(num2);
                    GameObject cyl0 = CList[ball0.GetComponent <Simplex0>().neighbors1.Intersect(s.neighbors1).ToList()[0]];
                    GameObject cyl1 = CList[ball1.GetComponent <Simplex0>().neighbors1.Intersect(s.neighbors1).ToList()[0]];
                    cyl0.GetComponent <Simplex1>().neighbors2.Add(num2);
                    cyl1.GetComponent <Simplex1>().neighbors2.Add(num2);
                    // Add edge indices to neighbors
                    tri.neighbors1.Add(c);
                    tri.neighbors1.Add(System.Convert.ToInt32(cyl0.name));
                    tri.neighbors1.Add(System.Convert.ToInt32(cyl1.name));
                    // Add vertex indices to neighbors
                    tri.neighbors0 = new List <int> {
                        num0, System.Convert.ToInt32(ball0.name), System.Convert.ToInt32(ball1.name)
                    };
                    // Set triangle attributes
                    tri.is_shown = (cyl_tri_toggle % 3 < 1);
                    tri.is_drawn = (CList[c].GetComponent <Simplex1>().is_drawn & cyl0.GetComponent <Simplex1>().is_drawn & cyl1.GetComponent <Simplex1>().is_drawn);
                    UpdateSingle(triangle);
                    TList_alive.Add(num2);
                    num2++;
                }
            }
        }
        BList_alive.Add(num0);
        num0++;
    }