/// <summary>
/// 承压环、底环板均分函数
/// </summary>
/// <param name="maxr">外圆半径</param>
/// <param name="platewid">排版板宽</param>
/// <param name="totalang">均分总角度</param>
/// <param name="divnum">最优均分数量</param>
/// <param name="divnum2">均分数量</param>
private static void PlateDiv(double maxr, int platewid, double totalang, out int divnum, out int divnum2)
{
double widang = 2 * Math.Atan2(platewid / 2.0, Math.Sqrt(Math.Pow(maxr, 2) - Math.Pow(platewid / 2.0, 2)));
divnum = (int)(totalang / widang);
int divnum1 = divnum;
double divang = totalang / divnum1;
//计算拼接数量
while (maxr * Math.Sin(divang / 2.0) > (platewid / 2.0))
{
divnum1++;
divang = totalang / divnum1;
}
divnum2 = divnum1;
divang = totalang / divnum2;
while (maxr * Math.Sin(divang / 2.0) < (platewid / 2.0))
{
divnum2--;
divang = totalang / divnum2;
}
//确定拼接数量
divnum = divnum1 > divnum ? divnum1 : divnum2;
}
/// <summary>
/// 创建圆环均分及文字
/// </summary>
/// <param name="maxr">圆环最大直径</param>
/// <param name="minr">圆环最小直径</param>
/// <param name="cen">圆环圆心点</param>
/// <param name="divnum">圆环等分数量</param>
/// <param name="divang">圆环等分后,每分角度(弧度)</param>
/// <param name="atpy">焊缝编号,A10X,B20X</param>
private static void MakeRingDivWeldText(double maxr, double minr, Point3d cen, int divnum, double divang, string atpy)
{
for (int i = 0; i < divnum; i++)
{
double lang = (divang / 2.0) + (i * divang);
db.AddLineToModelSpace(cen.PolarPtOfDegree(lang, minr), cen.PolarPtOfDegree(lang, maxr));
string str = $"{atpy}-{i + 1}";
TextHorizontalMode thm;
if (Math.Abs(lang - (Math.PI * 0.5)) < (0.5 * divang) || Math.Abs(lang - (Math.PI * 1.5)) < (0.5 * divang) || lang == Math.PI * 0.5 || lang == Math.PI * 1.5)
thm = TextHorizontalMode.TextCenter;
else if (lang > (Math.PI * 0.5) && lang < (Math.PI * 1.5)) thm = TextHorizontalMode.TextRight;
else thm = TextHorizontalMode.TextLeft;
Point3d tpt = cen.PolarPtOfDegree(lang, maxr + fonthig);
bool angpart = (lang > 0 && lang <= (Math.PI * 0.5)) || (lang > Math.PI && lang <= (Math.PI * 1.5));
double tang = (divang / 2.0) + (i * divang), bigang, smlang;
if (lang <= Math.PI * 0.5)
{
smlang = 0;
bigang = Math.PI * 0.5;
}
else if (lang <= Math.PI)
{
smlang = Math.PI * 0.5;
bigang = Math.PI;
}
else if (lang <= Math.PI * 1.5)
{
smlang = Math.PI;
bigang = Math.PI * 1.5;
}
else
{
smlang = Math.PI * 1.5;
bigang = Math.PI * 2;
}
Point3d prpt1 = tpt;
int n = angpart ? -1 : 1;
Point3d prpt2 = cen.PolarPtOfDegree((divang / 2.0) + ((i + n) * divang), maxr + fonthig);
while (Math.Abs(prpt1.Y - prpt2.Y) <= (1.1 * fonthig) && ((divang / 2.0) + ((i + n) * divang)) > smlang && ((divang / 2.0) + ((i + n) * divang)) <= bigang)
{
if (lang > 0 && lang < Math.PI)
{
tpt = tpt.PolarPtOfDegree(lang, Math.Abs((prpt2.Y + (1.1 * fonthig) - prpt1.Y) / Math.Sin(tang)));
}
else
{
tpt = tpt.PolarPtOfDegree(lang, Math.Abs((prpt2.Y - prpt1.Y - (1.1 * fonthig)) / Math.Sin(tang)));
}
prpt1 = prpt2;
if (angpart) n--;
else n++;
prpt2 = cen.PolarPtOfDegree((divang / 2.0) + ((i + n) * divang), maxr + fonthig);
}
if (pted2.Y > tpt.Y) pte0 = pted2 = new Point3d(pted2.X, tpt.Y - (0.5 * fonthig), 0);
db.AddTextToModelSpace(tpt, str, fonthig, thm, TextVerticalMode.TextVerticalMid);
}
}