Esempio n. 1
0
    void ModuleUpdateTangentCircleToLine()
    {
        HCircle hcircle = VA.GetComponent <HCircle>(); //対象となる円
        HLine   hline   = VB.GetComponent <HLine>();   //対象となる直線

        if (hcircle != null && hline != null)
        {
            HypCircle C1 = hcircle.GetHCR();
            HypLine   L1 = hline.GetHL();
            HypPoint  P1 = new HypPoint(hcircle.VA.GetComponent <Vertex>().XY);
            HypLine   L2 = HTransform.GetHPerpendicularThruAPoint(L1, P1);
            HypPoint  P2 = HTransform.GetCrossingPointOfTwoHLines(L1, L2);
            //P2.println("P2");
            float error = (HTransform.GetHDistanceOfTwoPoints(P1, P2) - C1.HR) * 0.1f;
            //Debug.Log(error);
            if (0.001f < error || error < -0.001f)
            {
                HypPoint P3 = HTransform.GetHMoveAlongTwoPoints(P2, P1, error);
                HypPoint P4 = HTransform.GetHMoveAlongTwoPoints(P1, P2, error);
                //円の半径を変える
                C1.HR += error;
                ////円を直線に寄せる
                Vertex C1V = hcircle.VA.GetComponent <Vertex>();
                if (!C1V.Fixed && P4.InWorld())
                {
                    C1V.XY.x = P4.GetX();
                    C1V.XY.y = P4.GetY();
                }
                //直線を円に寄せる
                Vertex   L1V1   = hline.VA.GetComponent <Vertex>(); //動かすべき点1
                Vertex   L1V2   = hline.VB.GetComponent <Vertex>(); //動かすべき点2
                HypPoint PL1    = new HypPoint(L1V1.XY);
                HypPoint PL2    = new HypPoint(L1V2.XY);
                HypPoint NewPL1 = HTransform.ParallelTransform(P2, P3, PL1);
                HypPoint NewPL2 = HTransform.ParallelTransform(P2, P3, PL2);
                //NewPL1.println("NewPL1");
                if (!L1V1.Fixed && NewPL1.InWorld())
                {
                    L1V1.XY.x = NewPL1.GetX();
                    L1V1.XY.y = NewPL1.GetY();
                }
                if (!L1V2.Fixed && NewPL2.InWorld())
                {
                    L1V2.XY.x = NewPL2.GetX();
                    L1V2.XY.y = NewPL2.GetY();
                }
                hline.GetHLineFromTwoVertices();
            }
        }
    }
Esempio n. 2
0
    void ModuleUpdatePointToCircle()
    {
        Vector2 vtx     = VA.GetComponent <Vertex>().XY; //対象となる点
        HCircle hcircle = VB.GetComponent <HCircle>();   //対象となる円

        if (vtx != null && hcircle != null)
        {
            HypCircle cr   = hcircle.GetHCR();                                       //円の円データ
            HypPoint  HPcr = new HypPoint(cr.HX, cr.HY);                             //円の中心
            HypPoint  Pvtx = new HypPoint(vtx.x, vtx.y);                             //対象となる点
            float     dist = HTransform.GetHDistanceOfTwoPoints(HPcr, Pvtx) - cr.HR; //誤差
            //Debug.Log(HTransform.GetHDistanceOfTwoPoints(HPcr, Pvtx)+"->");
            if (Mathf.Abs(dist) > 0.0001f)
            {
                //円を点に寄せる
                HypPoint P1 = HTransform.GetHMoveAlongTwoPoints(HPcr, Pvtx, dist * 0.5f);
                //点を円に寄せる
                HypPoint P2 = HTransform.GetHMoveAlongTwoPoints(Pvtx, HPcr, dist * 0.5f);
                //Debug.Log("*:"+dist+" "+ X+" "+ Y);
                if (!VB.GetComponent <HCircle>().VA.GetComponent <Vertex>().Fixed&& P1.InWorld())
                {
                    VB.GetComponent <HCircle>().VA.GetComponent <Vertex>().XY.x = P1.GetX();
                    VB.GetComponent <HCircle>().VA.GetComponent <Vertex>().XY.y = P1.GetY();
                }
                if (!VA.GetComponent <Vertex>().Fixed&& P2.InWorld())
                {
                    VA.GetComponent <Vertex>().XY.x = P2.GetX();
                    VA.GetComponent <Vertex>().XY.y = P2.GetY();
                }
                //円の半径を調整する
                VB.GetComponent <HCircle>().HCR.HR += (dist * 0.1f);
                cr   = hcircle.HCR;                //円の円データ
                HPcr = new HypPoint(cr.HX, cr.HY); //円の中心
                Pvtx = new HypPoint(vtx.x, vtx.y); //対象となる点
            }
        }
    }