/// <summary> /// /// </summary> /// <param name="cad2d"></param> /// <param name="baseLoopId"></param> /// <param name="x0"></param> /// <param name="y0"></param> /// <param name="rodRadius"></param> /// <param name="rodCircleDiv"></param> /// <param name="rodRadiusDiv"></param> /// <param name="id_v0"></param> /// <param name="id_v1"></param> /// <param name="id_v2"></param> /// <param name="startAngle"></param> /// <param name="isReverseAddVertex"></param> /// <returns></returns> public static uint AddExactlyQuarterRod(CCadObj2D cad2d, uint baseLoopId, double x0, double y0, double rodRadius, int rodCircleDiv, int rodRadiusDiv, uint id_v0, uint id_v1, uint id_v2, double startAngle, bool isReverseAddVertex) { CVector2D pt_center = cad2d.GetVertexCoord(id_v1); System.Diagnostics.Debug.Assert(Math.Abs(x0 - pt_center.x) < MyUtilLib.Matrix.Constants.PrecisionLowerLimit); System.Diagnostics.Debug.Assert(Math.Abs(y0 - pt_center.y) < MyUtilLib.Matrix.Constants.PrecisionLowerLimit); List <CVector2D> pts = new List <CVector2D>(); System.Diagnostics.Debug.Assert((startAngle == 0.0) || (startAngle == 90.0) || (startAngle == 180.0) || (startAngle == 270.0)); // ロッドの分割数調整 for (int k = 1; k < rodRadiusDiv; k++) { for (int itheta = 1; itheta < (rodCircleDiv / 4); itheta++) { double theta = 0; if (isReverseAddVertex) { theta = startAngle * pi / 180.0 - itheta * 2.0 * pi / rodCircleDiv; } else { theta = startAngle * pi / 180.0 + itheta * 2.0 * pi / rodCircleDiv; } double x = x0 + (k * rodRadius / rodRadiusDiv) * Math.Cos(theta); double y = y0 + (k * rodRadius / rodRadiusDiv) * Math.Sin(theta); uint id_v_add = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, baseLoopId, new CVector2D(x, y)).id_v_add; System.Diagnostics.Debug.Assert(id_v_add != 0); } } uint retLoopId = 0; uint prev_id_v = id_v0; // ロッド1/4円 for (int itheta = 1; itheta < (rodCircleDiv / 4); itheta++) { double theta = 0; if (isReverseAddVertex) { theta = startAngle * pi / 180.0 - itheta * 2.0 * pi / rodCircleDiv; } else { theta = startAngle * pi / 180.0 + itheta * 2.0 * pi / rodCircleDiv; } double x = x0 + rodRadius * Math.Cos(theta); double y = y0 + rodRadius * Math.Sin(theta); uint id_v_add = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, baseLoopId, new CVector2D(x, y)).id_v_add; System.Diagnostics.Debug.Assert(id_v_add != 0); CBRepSurface.CResConnectVertex resConnectVertex = cad2d.ConnectVertex_Line(prev_id_v, id_v_add); uint id_e_add = resConnectVertex.id_e_add; System.Diagnostics.Debug.Assert(id_e_add != 0); prev_id_v = id_v_add; } uint last_id_v = id_v2; { CBRepSurface.CResConnectVertex resConnectVertex = cad2d.ConnectVertex_Line(prev_id_v, last_id_v); uint id_e_add = resConnectVertex.id_e_add; uint lId = resConnectVertex.id_l_add; System.Diagnostics.Debug.Assert(id_e_add != 0); System.Diagnostics.Debug.Assert(lId != 0); retLoopId = lId; } return(retLoopId); }
/// <summary> /// ロッド(半分)を追加する /// </summary> /// <param name="cad2d"></param> /// <param name="baseLoopId"></param> /// <param name="x0"></param> /// <param name="y0"></param> /// <param name="rodRadius"></param> /// <param name="rodCircleDiv"></param> /// <param name="rodRadiusDiv"></param> /// <returns></returns> public static uint AddHalfRod(CCadObj2D cad2d, uint baseLoopId, double x0, double y0, double rodRadius, int rodCircleDiv, int rodRadiusDiv, double startAngle, double additionalAngle = 0.0, bool isReverseAddVertex = false, uint id_v_st = uint.MaxValue, uint id_v_ed = uint.MaxValue) { System.Diagnostics.Debug.Assert(additionalAngle < 360.0 / rodCircleDiv); List <CVector2D> pts = new List <CVector2D>(); System.Diagnostics.Debug.Assert((startAngle == 0.0) || (startAngle == 90.0) || (startAngle == 180.0) || (startAngle == 270.0)); if (Math.Abs(additionalAngle) >= MyUtilLib.Matrix.Constants.PrecisionLowerLimit) { // メッシュ形状を整えるためにロッドの中心に頂点を追加 uint id_v_center = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, baseLoopId, new CVector2D(x0, y0)).id_v_add; System.Diagnostics.Debug.Assert(id_v_center != 0); } // ロッドの分割数調整 for (int k = 1; k < rodRadiusDiv; k++) { for (int itheta = 0; itheta <= (rodCircleDiv / 2); itheta++) { if (Math.Abs(additionalAngle) < MyUtilLib.Matrix.Constants.PrecisionLowerLimit && (itheta == 0 || itheta == (rodCircleDiv / 2))) { continue; } double theta = 0; if (isReverseAddVertex) { theta = startAngle * pi / 180.0 - itheta * 2.0 * pi / rodCircleDiv; } else { theta = startAngle * pi / 180.0 + itheta * 2.0 * pi / rodCircleDiv; } double x = x0 + (k * rodRadius / rodRadiusDiv) * Math.Cos(theta); double y = y0 + (k * rodRadius / rodRadiusDiv) * Math.Sin(theta); uint id_v_add = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, baseLoopId, new CVector2D(x, y)).id_v_add; System.Diagnostics.Debug.Assert(id_v_add != 0); } } // ロッドの分割数調整: ロッド1/4円から超えた部分 if (Math.Abs(additionalAngle) >= MyUtilLib.Matrix.Constants.PrecisionLowerLimit) { double theta = 0; if (isReverseAddVertex) { theta = (startAngle + additionalAngle) * pi / 180.0; } else { theta = (startAngle - additionalAngle) * pi / 180.0; } for (int k = 1; k < rodRadiusDiv; k++) { double x = x0 + (k * rodRadius / rodRadiusDiv) * Math.Cos(theta); double y = y0 + (k * rodRadius / rodRadiusDiv) * Math.Sin(theta); uint id_v_add = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, baseLoopId, new CVector2D(x, y)).id_v_add; System.Diagnostics.Debug.Assert(id_v_add != 0); } } // ロッドの分割数調整: ロッド1/4円から超えた部分 if (Math.Abs(additionalAngle) >= MyUtilLib.Matrix.Constants.PrecisionLowerLimit) { double theta = 0; if (isReverseAddVertex) { theta = (startAngle - 180.0 - additionalAngle) * pi / 180.0; } else { theta = (startAngle + 180.0 + additionalAngle) * pi / 180.0; } for (int k = 1; k < rodRadiusDiv; k++) { double x = x0 + (k * rodRadius / rodRadiusDiv) * Math.Cos(theta); double y = y0 + (k * rodRadius / rodRadiusDiv) * Math.Sin(theta); uint id_v_add = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, baseLoopId, new CVector2D(x, y)).id_v_add; System.Diagnostics.Debug.Assert(id_v_add != 0); } } uint retLoopId = 0; if (id_v_st != uint.MaxValue && id_v_ed != uint.MaxValue) { uint prev_id_v = id_v_st; // ロッド半円から超えた部分 if (Math.Abs(additionalAngle) >= MyUtilLib.Matrix.Constants.PrecisionLowerLimit) { double theta = 0; if (isReverseAddVertex) { theta = (startAngle + additionalAngle) * pi / 180.0; } else { theta = (startAngle - additionalAngle) * pi / 180.0; } double x = x0 + rodRadius * Math.Cos(theta); double y = y0 + rodRadius * Math.Sin(theta); uint id_v_add = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, baseLoopId, new CVector2D(x, y)).id_v_add; System.Diagnostics.Debug.Assert(id_v_add != 0); CBRepSurface.CResConnectVertex resConnectVertex = cad2d.ConnectVertex_Line(prev_id_v, id_v_add); uint id_e_add = resConnectVertex.id_e_add; System.Diagnostics.Debug.Assert(id_e_add != 0); prev_id_v = id_v_add; } // ロッド半円 for (int itheta = 0; itheta <= (rodCircleDiv / 2); itheta++) { double theta = 0; if (isReverseAddVertex) { theta = startAngle * pi / 180.0 - itheta * 2.0 * pi / rodCircleDiv; } else { theta = startAngle * pi / 180.0 + itheta * 2.0 * pi / rodCircleDiv; } double x = x0 + rodRadius * Math.Cos(theta); double y = y0 + rodRadius * Math.Sin(theta); uint id_v_add = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, baseLoopId, new CVector2D(x, y)).id_v_add; System.Diagnostics.Debug.Assert(id_v_add != 0); CBRepSurface.CResConnectVertex resConnectVertex = cad2d.ConnectVertex_Line(prev_id_v, id_v_add); uint id_e_add = resConnectVertex.id_e_add; System.Diagnostics.Debug.Assert(id_e_add != 0); prev_id_v = id_v_add; } // ロッド半円から超えた部分 if (Math.Abs(additionalAngle) >= MyUtilLib.Matrix.Constants.PrecisionLowerLimit) { double theta = 0; if (isReverseAddVertex) { theta = (startAngle - 180.0 - additionalAngle) * pi / 180.0; } else { theta = (startAngle + 180.0 + additionalAngle) * pi / 180.0; } double x = x0 + rodRadius * Math.Cos(theta); double y = y0 + rodRadius * Math.Sin(theta); uint id_v_add = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, baseLoopId, new CVector2D(x, y)).id_v_add; System.Diagnostics.Debug.Assert(id_v_add != 0); CBRepSurface.CResConnectVertex resConnectVertex = cad2d.ConnectVertex_Line(prev_id_v, id_v_add); uint id_e_add = resConnectVertex.id_e_add; System.Diagnostics.Debug.Assert(id_e_add != 0); prev_id_v = id_v_add; //!!!!!!!!!!!!!!! } uint last_id_v = id_v_ed; { CBRepSurface.CResConnectVertex resConnectVertex = cad2d.ConnectVertex_Line(prev_id_v, last_id_v); uint id_e_add = resConnectVertex.id_e_add; uint lId = resConnectVertex.id_l_add; System.Diagnostics.Debug.Assert(id_e_add != 0); System.Diagnostics.Debug.Assert(lId != 0); retLoopId = lId; } } else { System.Diagnostics.Debug.Assert(isReverseAddVertex == false); // 逆順未対応 // ロッド半円から超えた部分 if (Math.Abs(additionalAngle) >= MyUtilLib.Matrix.Constants.PrecisionLowerLimit) { double theta = (startAngle - additionalAngle) * pi / 180.0; double x = x0 + rodRadius * Math.Cos(theta); double y = y0 + rodRadius * Math.Sin(theta); pts.Add(new CVector2D(x, y)); } // ロッド半円 for (int itheta = 0; itheta <= (rodCircleDiv / 2); itheta++) { double theta = startAngle * pi / 180.0 + itheta * 2.0 * pi / rodCircleDiv; double x = x0 + rodRadius * Math.Cos(theta); double y = y0 + rodRadius * Math.Sin(theta); pts.Add(new CVector2D(x, y)); } // ロッド半円から超えた部分 if (Math.Abs(additionalAngle) >= MyUtilLib.Matrix.Constants.PrecisionLowerLimit) { double theta = (startAngle + 180.0 + additionalAngle) * pi / 180.0; double x = x0 + rodRadius * Math.Cos(theta); double y = y0 + rodRadius * Math.Sin(theta); pts.Add(new CVector2D(x, y)); } uint lId = cad2d.AddPolygon(pts, baseLoopId).id_l_add; retLoopId = lId; } return(retLoopId); }