//public static void GetHMoveAlongTwoPoints(float x1, float y1, float x2, float y2, float d, out float X, out float Y)
 public static HypPoint GetHMoveAlongTwoPoints(HypPoint P1, HypPoint P2, float d)
 {
     if (!P1.InWorld() || !P2.InWorld())
     {
         return(P1);
     }
     if (P1 != HypPoint.Zero())
     {
         //X1をOへ移す直線L1
         HypLine L1 = GetHBisectorOfTwoPoints(P1, HypPoint.Zero());
         //点X2をL1で線対称移動
         HypPoint XY2 = GetInversionAlongHLine(L1, P2);
         if (XY2.Z == 0f)
         {
             P1.Println("---P1");
             P2.Println("---P2");
             L1.Println("---L1");
             XY2.Println("--XY2");
         }
         float magXY2 = Mathf.Sqrt(XY2.GetX() * XY2.GetX() + XY2.GetY() * XY2.GetY());
         float ed     = H2EFromOrigin(d);
         //原点からX2へ向かう線分で、双曲長がdであるような点
         XY2.X *= ed;
         XY2.Y *= ed;
         XY2.Z *= magXY2;
         //点X2をL1で線対称移動
         HypPoint P3 = GetInversionAlongHLine(L1, XY2);
         if (P3.InWorld())
         {
             return(P3);
         }
         else
         {
             Debug.Log("error occurs at GetHMoveAlongTwoPoints");
             P1.Println("P1");
             P2.Println("P2");
             Debug.Log("magXY2=" + magXY2);
             Debug.Log("ed=" + ed);
             XY2.Println("XY2");
             P3.Println("P3");
             return(P1);
         }
     }
     else
     {
         HypPoint XY2    = P2;
         float    magXY2 = Mathf.Sqrt(XY2.GetX() * XY2.GetX() + XY2.GetY() * XY2.GetY());
         float    ed     = H2EFromOrigin(d);
         //原点からX2へ向かう線分で、双曲長がdであるような点
         XY2.X *= ed;
         XY2.Y *= ed;
         XY2.Z *= magXY2;
         HypPoint P3 = XY2;
         return(P3);
     }
 }
    public static HypLine GetHBisectorOfTwoPoints(HypPoint P1, HypPoint P2)
    {
        HypLine ret = new HypLine
        {
            X = 1f,
            Y = 1f,
            Z = 0f,
            R = 0f
        };

        if (P1 != P2)
        {
            EucLine   L     = GetLineByTwoPoints(P1, P2);
            HypPoint  P3    = new HypPoint(L.a, L.b, Mathf.Sqrt(L.a * L.a + L.b * L.b));
            EucLine   L12   = GetBisectorLine(P1, P2);
            EucLine   L23   = GetBisectorLine(P2, P3);
            HypPoint  P123  = GetCrossingPointOfTwoLines(L12, L23);
            float     C123R = GetEDistanceOfTwoPoints(P123, P1);
            HypCircle C1    = new HypCircle
            {
                EX = P123.GetX(),
                EY = P123.GetY(),
                ER = C123R
            };// P1,P2,P3を通る円。
            EucLine L2 = new EucLine
            {
                a = -2 * C1.EX,
                b = -2 * C1.EY,
                p = C1.ER * C1.ER - C1.EX * C1.EX - C1.EY * C1.EY - 1f
            };                                              //単位円とC1の共通弦(接するならば共通接線)
            HypPoint P = GetCrossingPointOfTwoLines(L, L2); //L1とL2の交点(無限遠点もありうる)
            ret = GetHLineFromCenter(P);                    //Pを中心とする双曲直線
        }
        else
        {
            Debug.Log("GetHBisectorOfTwoPoints error: P1==P2");
            P1.Println("P1");
            P2.Println("P2");
        }
        return(ret);
    }
Exemplo n.º 3
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();
            }
        }
    }