Beispiel #1
0
    //string MyDebug_Backup="";
    void ModuleUpdatePointToLine2()
    {
        Vertex VTX = VA.GetComponent <Vertex>(); //対象となる点
        HLine  HLN = VB.GetComponent <HLine>();  //対象となる直線

        if (VTX != null && HLN != null)
        {
            HypLine  L1    = HLN.HL;
            HypPoint P1    = new HypPoint(VTX.XY);
            HypLine  L2    = HTransform.GetHPerpendicularThruAPoint(L1, P1);
            HypPoint P2    = HTransform.GetCrossingPointOfTwoHLines(L1, L2);
            float    error = HTransform.GetHDistanceOfTwoPoints(P1, P2) * 0.2f;
            //Debug.Log(error);
            if (0.001f < error || error < -0.001f)
            {
                //string MyDebug = "";
                HypPoint P3 = HTransform.GetHMoveAlongTwoPoints(P2, P1, error);
                HypPoint P4 = HTransform.GetHMoveAlongTwoPoints(P1, P2, error);
                ////点を直線に寄せる
                if (!VTX.Fixed && P4.InWorld())
                {
                    //MyDebug += "P4:" + P4.GetX() + "," + P4.GetY();
                    VTX.XY.x = P4.GetX();
                    VTX.XY.y = P4.GetY();
                }
                //直線を円に寄せる
                Vertex   L1V1   = HLN.VA.GetComponent <Vertex>(); //動かすべき点1
                Vertex   L1V2   = HLN.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())
                {
                    //MyDebug += "L1:" + NewPL1.GetX() + "," + NewPL1.GetY();
                    L1V1.XY.x = NewPL1.GetX();
                    L1V1.XY.y = NewPL1.GetY();
                }
                if (!L1V2.Fixed && NewPL2.InWorld())
                {
                    //MyDebug += "L2:" + NewPL2.GetX() + "," + NewPL2.GetY();
                    L1V2.XY.x = NewPL2.GetX();
                    L1V2.XY.y = NewPL2.GetY();
                }
                HLN.GetHLineFromTwoVertices();
                //if (MyDebug != MyDebug_Backup)
                //{
                //    Debug.Log(MyDebug);
                //    MyDebug_Backup = MyDebug;
                //}
            }
        }
    }
Beispiel #2
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();
            }
        }
    }