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(); } } }
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); //対象となる点 } } }
public override string ToString() { if (Mode == MODE.ADD_POINT) { Vertex VTX = ParentObj.GetComponent <Vertex>(); return("Point," + VTX.XY.x + "," + VTX.XY.y + "," + "1" + "," + VTX.ID + "," + VTX.Fixed + "," + Active + "," + VTX.VertexName); } else if (Mode == MODE.ADD_LINE) { HLine HLN = ParentObj.GetComponent <HLine>(); int Id1 = HLN.VA.GetComponent <Vertex>().ID; int Id2 = HLN.VB.GetComponent <Vertex>().ID; return("Line," + Id1 + "," + Id2 + "," + HLN.ID + "," + Active + "," + HLN.HLineName); } else if (Mode == MODE.ADD_CIRCLE) { HCircle HCI = ParentObj.GetComponent <HCircle>(); int Id1 = HCI.VA.GetComponent <Vertex>().ID; return("Circle," + Id1 + "," + HCI.HCR.HR + "," + HCI.ID + "," + Active + "," + HCI.HCircleName); } else if (Mode == MODE.ADD_MIDPOINT) { HModule HMD = ParentObj.GetComponent <HModule>(); return("Module," + Mode + "," + HMD.VA.GetComponent <Vertex>().ID + "," + HMD.VB.GetComponent <Vertex>().ID + "," + HMD.VC.GetComponent <Vertex>().ID + "," + HMD.ID + "," + Active); } else if (Mode == MODE.POINT_TO_POINT) { HModule HMD = ParentObj.GetComponent <HModule>(); return("Module," + Mode + "," + HMD.VA.GetComponent <Vertex>().ID + "," + HMD.VB.GetComponent <Vertex>().ID + "," + "ID3" + "," + HMD.ID + "," + Active); } else if (Mode == MODE.POINT_TO_LINE) { HModule HMD = ParentObj.GetComponent <HModule>(); return("Module," + Mode + "," + HMD.VA.GetComponent <Vertex>().ID + "," + HMD.VB.GetComponent <HLine>().ID + "," + "ID3" + "," + HMD.ID + "," + Active); } else if (Mode == MODE.POINT_TO_CIRCLE) { HModule HMD = ParentObj.GetComponent <HModule>(); return("Module," + Mode + "," + HMD.VA.GetComponent <Vertex>().ID + "," + HMD.VB.GetComponent <HCircle>().ID + "," + "ID3" + "," + HMD.ID + "," + Active); } else if (Mode == MODE.ISOMETRY) { HModule HMD = ParentObj.GetComponent <HModule>(); return("Module," + Mode + "," + HMD.VA.GetComponent <HLine>().ID + "," + HMD.VB.GetComponent <HLine>().ID + "," + "ID3" + "," + HMD.ID + "," + Active); } else if (Mode == MODE.PERPENDICULAR) { HModule HMD = ParentObj.GetComponent <HModule>(); return("Module," + Mode + "," + HMD.VA.GetComponent <HLine>().ID + "," + HMD.VB.GetComponent <HLine>().ID + "," + "ID3" + "," + HMD.ID + "," + Active); } else if (Mode == MODE.TANGENT_C2L) { HModule HMD = ParentObj.GetComponent <HModule>(); return("Module," + Mode + "," + HMD.VA.GetComponent <HCircle>().ID + "," + HMD.VB.GetComponent <HLine>().ID + "," + "ID3" + "," + HMD.ID + "," + Active); } else if (Mode == MODE.TANGENT_C2C) { HModule HMD = ParentObj.GetComponent <HModule>(); return("Module," + Mode + "," + HMD.VA.GetComponent <HCircle>().ID + "," + HMD.VB.GetComponent <HCircle>().ID + "," + "ID3" + "," + HMD.ID + "," + Active); } else { return(""); } }
public void ModuleUpdate() { for (int repeat = 0; repeat < 10; repeat++) { if (Mode == MODE.ADD_MIDPOINT) { HypPoint V1 = new HypPoint(VA.GetComponent <Vertex>().XY); HypPoint V2 = new HypPoint(VB.GetComponent <Vertex>().XY); HypPoint V3 = new HypPoint(VC.GetComponent <Vertex>().XY); HypPoint W1 = HTransform.ParallelTransform(V2, V3, V3); HypPoint W2 = HTransform.ParallelTransform(V1, V3, V3); HypPoint W3 = HTransform.GetMidPointOfTwoPoint(V1, V2); float dist1 = HTransform.GetHDistanceOfTwoPoints(V1, W1); float dist2 = HTransform.GetHDistanceOfTwoPoints(V2, W2); float dist3 = HTransform.GetHDistanceOfTwoPoints(V3, W3); HypPoint U1 = HTransform.GetHMoveAlongTwoPoints(V1, W1, dist1 * 0.1f); HypPoint U2 = HTransform.GetHMoveAlongTwoPoints(V2, W2, dist2 * 0.1f); HypPoint U3 = HTransform.GetHMoveAlongTwoPoints(V3, W3, dist3 * 0.1f); //if (!U1.InWorld() || !U2.InWorld() || !U3.InWorld()) //{ // V1.Println("V1:"); // V2.Println("V2:"); // V3.Println("V3:"); // W1.Println("W1:"); // Debug.Log("dist1:" + dist1); // U1.Println("U1:"); //} if (U1.InWorld() && U2.InWorld() && U3.InWorld()) { if (!VA.GetComponent <Vertex>().Fixed) { VA.GetComponent <Vertex>().XY.x = U1.GetX(); VA.GetComponent <Vertex>().XY.y = U1.GetY(); } if (!VB.GetComponent <Vertex>().Fixed) { VB.GetComponent <Vertex>().XY.x = U2.GetX(); VB.GetComponent <Vertex>().XY.y = U2.GetY(); } if (!VC.GetComponent <Vertex>().Fixed) { VC.GetComponent <Vertex>().XY.x = U3.GetX(); VC.GetComponent <Vertex>().XY.y = U3.GetY(); } } } else if (Mode == MODE.POINT_TO_POINT) { if (VA != null && VB != null) { Vector2 V1 = VA.GetComponent <Vertex>().XY; Vector2 V2 = VB.GetComponent <Vertex>().XY; Vector2 NewV1 = 0.75f * V1 + 0.25f * V2; Vector2 NewV2 = 0.25f * V1 + 0.75f * V2; if (!VA.GetComponent <Vertex>().Fixed) { VA.GetComponent <Vertex>().XY = NewV1; } if (!VB.GetComponent <Vertex>().Fixed) { VB.GetComponent <Vertex>().XY = NewV2; } } } else if (Mode == MODE.POINT_TO_LINE) { if (VA != null && VB != null) { ModuleUpdatePointToLine2(); } } else if (Mode == MODE.POINT_TO_CIRCLE) { if (VA != null && VB != null) { ModuleUpdatePointToCircle(); } } else if (Mode == MODE.ISOMETRY) { if (VA != null && VB != null) { ModuleUpdateIsometry(); } } else if (Mode == MODE.PERPENDICULAR) { if (VA != null && VB != null) { ModuleUpdatePerpendicular(); } } else if (Mode == MODE.ANGLE) { if (VA != null && VB != null && VC != null) { ModuleUpdateAngle(); } } else if (Mode == MODE.TANGENT_C2L) { if (VA != null && VB != null) { ModuleUpdateTangentCircleToLine(); } } else if (Mode == MODE.TANGENT_C2C) { if (VA != null && VB != null) { HCircle hcircle1 = VA.GetComponent <HCircle>(); //対象となる円1 HCircle hcircle2 = VB.GetComponent <HCircle>(); //対象となる円2 if (hcircle1 != null && hcircle2 != null) { HypCircle C1 = hcircle1.HCR; HypCircle C2 = hcircle2.HCR; HypPoint P1 = new HypPoint(hcircle1.VA.GetComponent <Vertex>().XY); HypPoint P2 = new HypPoint(hcircle2.VA.GetComponent <Vertex>().XY); //HypLine L1 = HTransform.GetHLineThruTwoPoints(P1,P2); float dist = HTransform.GetHDistanceOfTwoPoints(P1, P2); float errorOut = dist - (C1.HR + C2.HR); float errorIn = dist - Mathf.Abs(C1.HR - C2.HR); if (Mathf.Abs(errorOut) < Mathf.Abs(errorIn)) {// 外接と思われる float error = errorOut * 0.1f; //円C1を寄せる HypPoint P3 = HTransform.GetHMoveAlongTwoPoints(P1, P2, error); Vertex C1V = hcircle1.VA.GetComponent <Vertex>(); if (!C1V.Fixed && P3.InWorld()) { C1V.XY.x = P3.GetX(); C1V.XY.y = P3.GetY(); } //円C1の半径を調節する。 C1.HR += error; //円C2を寄せる HypPoint P4 = HTransform.GetHMoveAlongTwoPoints(P2, P1, error); Vertex C2V = hcircle2.VA.GetComponent <Vertex>(); if (!C2V.Fixed && P4.InWorld()) { C2V.XY.x = P4.GetX(); C2V.XY.y = P4.GetY(); } //円C2の半径を調節する。 C2.HR += error; } else {//内接と思われる float error = errorIn * 0.1f; bool C1Out = false; if (C1.HR > C2.HR) {// C1が外側と思われる C1Out = true; } //円C1を寄せる HypPoint P3 = HTransform.GetHMoveAlongTwoPoints(P1, P2, error); Vertex C1V = hcircle1.VA.GetComponent <Vertex>(); if (!C1V.Fixed && P3.InWorld()) { C1V.XY.x = P3.GetX(); C1V.XY.y = P3.GetY(); } if (C1Out) { C1.HR += error; } else { C1.HR -= error; } //円C2を寄せる HypPoint P4 = HTransform.GetHMoveAlongTwoPoints(P2, P1, error); Vertex C2V = hcircle2.VA.GetComponent <Vertex>(); if (!C2V.Fixed && P4.InWorld()) { C2V.XY.x = P4.GetX(); C2V.XY.y = P4.GetY(); } //円C2の半径を調節する。 if (C1Out) { C2.HR -= error; } else { C2.HR += error; } } } } } } }
// This is the actual window. void DialogWindow(int windowID) { float AlignX = 15; float AlignY = 20; float AlignStep = 30; float height = 28; float align = 60; float bigAlign = 72; float width = windowRect.width - 30; float halfAlign = width / 2f; if (LogObject.Mode == MODE.ADD_POINT) { Vertex VTX = Object.GetComponent <Vertex>(); if (VTX == null) { return; } Fixed = VTX.Fixed; // GUI.Label(new Rect(AlignX, AlignY, width, height), Text1, TextStyle); AlignY += AlignStep; // GUI.Label(new Rect(AlignX, AlignY, width, height), "Name ", TextStyle); ObjectName = GUI.TextField(new Rect(AlignX + align, AlignY, width - align, height), ObjectName, TextFieldStyle); AlignY += AlignStep; // 1列目 GUI.Label(new Rect(AlignX, AlignY, windowRect.width - align, height), Text2, TextStyle); AlignY += AlignStep; GUI.Label(new Rect(AlignX, AlignY, width, height), "X :", TextStyle); CoordX = GUI.TextField(new Rect(AlignX + align, AlignY, width - align, height), CoordX, TextFieldStyle); AlignY += AlignStep; GUI.Label(new Rect(AlignX, AlignY, width, height), "Y : ", TextStyle); CoordY = GUI.TextField(new Rect(AlignX + align, AlignY, width - align, height), CoordY, TextFieldStyle); AlignY += AlignStep; // 2列目 if (Fixed) { GUI.Label(new Rect(AlignX, AlignY, width, height), "Fixed ", TextStyle); if (GUI.Button(new Rect(AlignX + bigAlign, AlignY, width - bigAlign, height), "Unfixed", ButtonStyle)) { Fixed = VTX.Fixed = false; } } else { GUI.Label(new Rect(AlignX, AlignY, width, height), "Unfixed ", TextStyle); if (GUI.Button(new Rect(AlignX + bigAlign, AlignY, width - bigAlign, height), "Fixed", ButtonStyle)) { Fixed = VTX.Fixed = true; } } AlignY += AlignStep; if (GUI.Button(new Rect(AlignX, AlignY, width, height), "Delete", ButtonStyle)) { Objects.DraggedVertex = VTX; Objects.ExecuteDeletePoint(); show = false; } AlignY += AlignStep; if (GUI.Button(new Rect(AlignX, AlignY, halfAlign, height), "Cancel", ButtonStyle)) { show = false; } if (GUI.Button(new Rect(AlignX + halfAlign, AlignY, halfAlign, height), "OK", ButtonStyle)) { VTX.VertexName = ObjectName; VTX.XY.x = float.Parse(CoordX); VTX.XY.y = float.Parse(CoordY); show = false; } } else if (LogObject.Mode == MODE.ADD_LINE) { HLine HLN = Object.GetComponent <HLine>(); if (HLN == null) { return; } Clipped = HLN.Clipped; GUI.Label(new Rect(AlignX, AlignY, width, height), Text1, TextStyle); AlignY += AlignStep; // GUI.Label(new Rect(AlignX, AlignY, width, height), "Name ", TextStyle); ObjectName = GUI.TextField(new Rect(AlignX + align, AlignY, width - align, height), ObjectName, TextFieldStyle); AlignY += AlignStep; GUI.Label(new Rect(AlignX, AlignY, width, height), Text2, TextStyle); AlignY += AlignStep; if (Clipped) { GUI.Label(new Rect(AlignX, AlignY, width, height), "Clipped", TextStyle); if (GUI.Button(new Rect(AlignX + halfAlign, AlignY, width - halfAlign, height), "Unclipped", ButtonStyle)) { Clipped = HLN.Clipped = false; } } else { GUI.Label(new Rect(AlignX, AlignY, width, height), "Unclipped", TextStyle); if (GUI.Button(new Rect(AlignX + halfAlign, AlignY, width - halfAlign, height), "Clipped", ButtonStyle)) { Clipped = HLN.Clipped = true; } } AlignY += AlignStep; if (GUI.Button(new Rect(AlignX, AlignY, width, height), "Delete", ButtonStyle)) { Objects.ExecuteDeleteHLine(HLN); show = false; } AlignY += AlignStep; if (GUI.Button(new Rect(AlignX, AlignY, halfAlign, height), "Cancel", ButtonStyle)) { show = false; } if (GUI.Button(new Rect(AlignX + halfAlign, AlignY, halfAlign, height), "OK", ButtonStyle)) { HLN.HLineName = ObjectName; show = false; } } else if (LogObject.Mode == MODE.ADD_CIRCLE) { HCircle HCI = Object.GetComponent <HCircle>(); if (HCI == null) { return; } GUI.Label(new Rect(AlignX, AlignY, width, height), Text1, TextStyle); AlignY += AlignStep; GUI.Label(new Rect(AlignX, AlignY, width, height), "Name ", TextStyle); ObjectName = GUI.TextField(new Rect(AlignX + align, AlignY, width - align, height), ObjectName, TextFieldStyle); AlignY += AlignStep; GUI.Label(new Rect(AlignX, AlignY, width, height), Text2, TextStyle); AlignY += AlignStep; if (GUI.Button(new Rect(AlignX, AlignY, width, height), "Delete", ButtonStyle)) { Objects.ExecuteDeleteHCircle(HCI); show = false; } AlignY += AlignStep; if (GUI.Button(new Rect(AlignX, AlignY, halfAlign, height), "Cancel", ButtonStyle)) { show = false; } if (GUI.Button(new Rect(AlignX + halfAlign, AlignY, halfAlign, height), "OK", ButtonStyle)) { HCI.HCircleName = ObjectName; show = false; } } else { HModule HMD = Object.GetComponent <HModule>(); if (HMD != null) { GUI.Label(new Rect(AlignX, AlignY, width, height), Text1, TextStyle); AlignY += AlignStep; GUI.Label(new Rect(AlignX, AlignY, width, height), Text2, TextStyle); AlignY += AlignStep; if (GUI.Button(new Rect(AlignX, AlignY, width, height), "Delete", ButtonStyle)) { Objects.ExecuteDeleteHModule(HMD); show = false; } AlignY += AlignStep; } if (GUI.Button(new Rect(AlignX, AlignY, halfAlign, height), "Cancel", ButtonStyle)) { show = false; } if (GUI.Button(new Rect(AlignX + halfAlign, AlignY, halfAlign, height), "OK", ButtonStyle)) { show = false; } } }