예제 #1
0
    void ModuleUpdatePerpendicular()
    {
        HLine    HLN1 = VA.GetComponent <HLine>(); //対象となる直線1
        HLine    HLN2 = VB.GetComponent <HLine>(); //対象となる直線2
        HypLine  HL1  = HLN1.HL;
        HypLine  HL2  = HLN2.HL;
        Vertex   V11  = HLN1.VA.GetComponent <Vertex>();
        Vertex   V12  = HLN1.VB.GetComponent <Vertex>();
        Vertex   V21  = HLN2.VA.GetComponent <Vertex>();
        Vertex   V22  = HLN2.VB.GetComponent <Vertex>();
        HypPoint P11  = new HypPoint(V11.XY);
        HypPoint P12  = new HypPoint(V12.XY);
        HypPoint P21  = new HypPoint(V21.XY);
        HypPoint P22  = new HypPoint(V22.XY);

        HypPoint C = HTransform.GetCrossingPointOfTwoHLines2(HL1, HL2);

        if (C != new HypPoint(1f, 1f, 0f))
        {
            //float angle = HTransform.GetAngleOfTwoLines(HL1, HL2, C);
            float angle = HTransform.GetAngleOfTwoLines(P11, P12, P21, P22, C);
            //Debug.Log("angle="+angle);
            float error = (Mathf.PI / 2f - angle) * 0.25f;
            if (angle < 0f)
            {
                error = (-Mathf.PI / 2f - angle) * 0.25f;
            }
            HypPoint P1m  = HTransform.GetMidPointOfTwoPoint(P11, P12);
            HypPoint P11T = HTransform.GetRotationOfPoint(P1m, -error, P11);
            HypPoint P12T = HTransform.GetRotationOfPoint(P1m, -error, P12);
            //HypLine L1T = HTransform.GetHLineThruTwoPoints(P11T, P12T);
            HypPoint P2m  = HTransform.GetMidPointOfTwoPoint(P21, P22);
            HypPoint P21T = HTransform.GetRotationOfPoint(P2m, error, P21);
            HypPoint P22T = HTransform.GetRotationOfPoint(P2m, error, P22);
            //HypLine L2T = HTransform.GetHLineThruTwoPoints(P21T, P22T);
            if (!V11.Fixed && P11T.InWorld())
            {
                V11.XY.x = P11T.GetX();
                V11.XY.y = P11T.GetY();
            }
            if (!V12.Fixed && P12T.InWorld())
            {
                V12.XY.x = P12T.GetX();
                V12.XY.y = P12T.GetY();
            }
            if (!V21.Fixed && P21T.InWorld())
            {
                V21.XY.x = P21T.GetX();
                V21.XY.y = P21T.GetY();
            }
            if (!V22.Fixed && P22T.InWorld())
            {
                V22.XY.x = P22T.GetX();
                V22.XY.y = P22T.GetY();
            }
        }
    }