コード例 #1
0
    public static HypPoint ParallelTransform(HypPoint Pstart, HypPoint Pend, HypPoint P)
    {
        if (!Pstart.InWorld() || !Pend.InWorld() || !P.InWorld())
        {
            Debug.Log("error occurs at ParallelTransform: A");
            Debug.Log("Pstart:" + Pstart.GetX() + "," + Pstart.GetY() + "(" + Pstart.X + ":" + Pstart.Y + ":" + Pstart.Z + ")");
            Debug.Log("Pend:" + Pend.GetX() + "," + Pend.GetY() + "(" + Pend.X + ":" + Pend.Y + ":" + Pend.Z + ")");
            Debug.Log("error occurs at ParallelTransform ここまで");
            return(P);
        }
        if (GetEDistanceOfTwoPoints(Pstart, Pend) < 0.001f)
        {
            //Debug.Log("error occurs at ParallelTransform: B");
            //Debug.Log("Pstart:" + Pstart.GetX() + "," + Pstart.GetY() + "(" + Pstart.X + ":" + Pstart.Y + ":" + Pstart.Z + ")");
            //Debug.Log("Pend:" + Pend.GetX() + "," + Pend.GetY() + "(" + Pend.X + ":" + Pend.Y + ":" + Pend.Z + ")");
            //Debug.Log("error occurs at ParallelTransform ここまで");
            return(P);
        }
        HypLine L1 = GetHLineThruTwoPoints(Pstart, Pend);
        HypLine L2 = GetHBisectorOfTwoPoints(Pstart, Pend);
        //L2.Println("---L2");
        HypLine L3 = GetHPerpendicularThruAPoint(L1, Pend);
        //L3.Println("---L3");
        HypPoint P1 = GetInversionAlongHLine(L2, P);
        HypPoint P2 = GetInversionAlongHLine(L3, P1);

        if (P2.InWorld())
        {
            return(P2);
        }
        else
        {
            Debug.Log("error occurs at ParallelTransform: C");
            Debug.Log("Pstart:" + Pstart.GetX() + "," + Pstart.GetY() + "(" + Pstart.X + ":" + Pstart.Y + ":" + Pstart.Z + ")");
            Debug.Log("Pend:" + Pend.GetX() + "," + Pend.GetY() + "(" + Pend.X + ":" + Pend.Y + ":" + Pend.Z + ")");
            Debug.Log("L1:" + L1.GetX() + "," + L1.GetY() + "," + L1.R + "(" + L1.X + ":" + L1.Y + ":" + L1.Z + ")");
            Debug.Log("L2:" + L2.GetX() + "," + L2.GetY() + "," + L2.R + "(" + L2.X + ":" + L2.Y + ":" + L2.Z + ")");
            Debug.Log("L3:" + L3.GetX() + "," + L3.GetY() + "," + L3.R + "(" + L3.X + ":" + L3.Y + ":" + L3.Z + ")");
            Debug.Log("P1:" + P1.GetX() + "," + P1.GetY() + "(" + P1.X + ":" + P1.Y + ":" + P1.Z + ")");
            Debug.Log("P2:" + P2.GetX() + "," + P2.GetY() + "(" + P2.X + ":" + P2.Y + ":" + P2.Z + ")");
            P1 = GetInversionAlongHLine(L2, P);
            P2 = GetInversionAlongHLine(L3, P1);
            Debug.Log("P2:" + P2.GetX() + "," + P2.GetY() + "(" + P2.X + ":" + P2.Y + ":" + P2.Z + ")");
            if (P2.InWorld())
            {
                return(P2);
            }
            Debug.Log("error occurs at ParallelTransform ここまで");
            return(P);
        }
    }
コード例 #2
0
    public static void GetIdealPointsFromTwoPoints(HypPoint P1, HypPoint P2, out HypPoint Out1, out HypPoint Out2)
    {
        HypLine L = GetHLineThruTwoPoints(P1, P2);

        //L.Println("L");
        if (L.R > 300f || L.Z == 0f)
        {
            float X1  = -L.Y;
            float Y1  = L.X;
            float mag = Mathf.Sqrt(X1 * X1 + Y1 * Y1);
            Out1 = new HypPoint(X1, Y1, mag);
            Out2 = new HypPoint(-X1, -Y1, mag);
        }
        else
        {
            float midT = Mathf.Atan2(L.Y, L.X);
            float widT = Mathf.Asin(1f / Mathf.Sqrt(L.GetX() * L.GetX() + L.GetY() * L.GetY()));
            float t1   = midT - widT;
            Out1 = new HypPoint(L.GetX() - L.R * Mathf.Cos(t1), L.GetY() - L.R * Mathf.Sin(t1));
            float t2 = midT + widT;
            Out2 = new HypPoint(L.GetX() - L.R * Mathf.Cos(t2), L.GetY() - L.R * Mathf.Sin(t2));
        }
    }
コード例 #3
0
    /// <summary>
    /// P1 = crossing point if exists.
    /// returns between 0 to PI/2
    /// </summary>
    /// <param name="L1"></param>
    /// <param name="L2"></param>
    /// <param name="P1"></param>
    /// <returns></returns>
    public static float GetAngleOfTwoLines(HypLine L1, HypLine L2, HypPoint P1)
    { // P1 = crossing point if exists
        if (L1.Z != 0f && L2.Z != 0f)
        {
            float u1 = L1.GetX() - P1.GetX();
            float v1 = L1.GetY() - P1.GetY();
            float u2 = L2.GetX() - P1.GetX();
            float v2 = L2.GetY() - P1.GetY();
            return(Mathf.Acos(Mathf.Abs(u1 * u2 + v1 * v2) / Mathf.Sqrt((u1 * u1 + v1 * v1) * (u2 * u2 + v2 * v2))));
        }
        else if (L1.Z == 0f && L2.Z != 0f)
        {
            float u1 = L2.GetX() - P1.GetX();
            float v1 = L2.GetY() - P1.GetY();
            float u2 = L1.X;
            float v2 = L1.Y;
            return(Mathf.Acos(Mathf.Abs(u1 * u2 + v1 * v2) / Mathf.Sqrt((u1 * u1 + v1 * v1) * (u2 * u2 + v2 * v2))));
        }
        else if (L1.Z != 0f && L2.Z == 0f)
        {
            float u1 = L1.GetX() - P1.GetX();
            float v1 = L1.GetY() - P1.GetY();
            float u2 = L2.X;
            float v2 = L2.Y;
            return(Mathf.Acos(Mathf.Abs(u1 * u2 + v1 * v2) / Mathf.Sqrt((u1 * u1 + v1 * v1) * (u2 * u2 + v2 * v2))));
        }
        else if (L1.Z == 0f && L2.Z == 0f)
        {
            float u1 = L1.X;
            float v1 = L1.Y;
            float u2 = L2.X;
            float v2 = L2.Y;
            return(Mathf.Acos(Mathf.Abs(u1 * u2 + v1 * v2) / Mathf.Sqrt((u1 * u1 + v1 * v1) * (u2 * u2 + v2 * v2))));
        }

        return(0f);
    }
コード例 #4
0
    void ModuleUpdatePointToLine()
    {
        Vector2 vtx   = VA.GetComponent <Vertex>().XY; //対象となる点
        HLine   hline = VB.GetComponent <HLine>();     //対象となる直線

        if (vtx != null && hline != null)
        {
            HypLine ln        = hline.HL;                          //直線の円データ
            Vector2 hlnCenter = new Vector2(ln.GetX(), ln.GetY()); //直線の円データの中心座標
            Vector2 direction = vtx - hlnCenter;                   //円の中心から対象となる点の方向
            float   dist      = direction.magnitude - ln.R;        //誤差
            if (Mathf.Abs(dist) > 0.001f)
            {
                direction.Normalize();
                //Vector2 newVtx = hlnCenter + (ln.R + 0.75f * dist) * direction;//新しい点の座標
                Vector2  newVtx = vtx - (0.1f * dist) * direction;//新しい点の座標
                HypPoint newPt  = new HypPoint(newVtx);
                if (!VA.GetComponent <Vertex>().Fixed&& newPt.InWorld())
                {
                    VA.GetComponent <Vertex>().XY = newVtx;
                }
                Vector2 startPos    = vtx - dist * direction;           //平行移動スタート点
                Vector2 endPos      = vtx - (0.8f * dist) * direction;  //平行移動ゴール点
                Vertex  lineVertex1 = hline.VA.GetComponent <Vertex>(); //動かすべき点1
                Vertex  lineVertex2 = hline.VB.GetComponent <Vertex>(); //動かすべき点2
                //new HypPoint(lineVertex1.XY).Println("LV1");
                //new HypPoint(lineVertex2.XY).Println("LV2");
                Vector2 XY1 = lineVertex1.XY;
                Vector2 XY2 = lineVertex2.XY;
                if (!lineVertex1.Fixed)
                {
                    HypPoint HP1    = new HypPoint(XY1);
                    HypPoint HPnew1 = HTransform.ParallelTransform(startPos, endPos, HP1);//点1を平行移動する
                    if (HPnew1.InWorld())
                    {
                        lineVertex1.XY.x = HPnew1.GetX();
                        lineVertex1.XY.y = HPnew1.GetY();
                    }
                    else
                    {
                        Debug.Log("error occurs at module P2L - 1A:" + HPnew1.X + "," + HPnew1.Y + "," + HPnew1.Z);
                        HP1.Println("HP1");
                        HPnew1.Println("HPnew1");
                        Debug.Log("dist " + dist);
                        Debug.Log("ln.R " + ln.R);
                        Debug.Log("direction " + direction.x + "," + direction.y);
                        Debug.Log("hlnCenter " + hlnCenter.x + "," + hlnCenter.y);
                        Debug.Log("startPos" + startPos.x + "," + startPos.y);
                        Debug.Log("endPos" + endPos.x + "," + endPos.y);
                        Debug.Log(XY1);
                    }
                }
                if (!lineVertex2.Fixed)
                {
                    HypPoint HP2    = new HypPoint(XY2);
                    HypPoint HPnew2 = HTransform.ParallelTransform(startPos, endPos, HP2);//点2を平行移動する
                    if (HPnew2.InWorld())
                    {
                        lineVertex2.XY.x = HPnew2.GetX();
                        lineVertex2.XY.y = HPnew2.GetY();
                    }
                    else
                    {
                        Debug.Log("error occurs at module P2L - 2A:" + HPnew2.X + "," + HPnew2.Y + "," + HPnew2.Z);
                    }
                }
                hline.GetHLineFromTwoVertices();
            }
        }
    }