- 积分
- 5811
- 明经币
- 个
- 注册时间
- 2016-10-12
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 wang2006zhi 于 2024-8-30 12:14 编辑
public void Tt21()
{
using var tr = new DBTrans();
if (!Env.Editor.SelEnt(out Polyline plSel, out Point3d ptSel))
return;
var plTemp = plSel.CloneEx();
plTemp.ColorIndex = 1;
using var jig = new JigEx((mpt, _) => {MovePolyline(plTemp, mpt); });
jig.DatabaseEntityDraw(wd => wd.RawGeometry.Draw(plTemp));
var jppo = jig.SetOptions("指定放入点:");
var r1 = jig.Drag();
if (r1.Status != PromptStatus.OK)
return;
void MovePolyline(Polyline pl, Point3d ptTemp)
{
var ptStar = plSel.GetClosestPointTo(ptSel, false);
var parmStar = plSel.GetParameterAtPoint(ptStar);
var parmS = Math.Floor(parmStar);
var parmE = Math.Ceiling(parmStar);
var indexS = Convert.ToInt32(parmS);
var indexE = Convert.ToInt32(parmE);
var part = parmStar - parmS;
var ptS = plSel.GetPointAtParameter(parmS);
var ptE = plSel.GetPointAtParameter(parmE);
var vecN = (ptE - ptS).GetNormal();
var vec = ptTemp - ptStar;
if (vec.Length<50)
return;
if (parmS.Equals(pl.StartParam))
{
pl.SetPointAt(indexS,(ptS + vec.DotProduct(vecN) * vecN).Point2d());
}
else if (parmE.Equals(pl.EndParam))
{
pl.SetPointAt(indexE,(ptE + vec.DotProduct(vecN) * vecN).Point2d());
}
else
{
if (part < 0.3)
{
var vecN1 = (ptE - ptS).GetNormal();
for (var i = 0; i <= parmS; i++)
{
var item = Convert.ToInt32(i);
var ptTem = plSel.GetPointAtParameter(item);
pl.SetPointAt(item, (ptTem + vec.DotProduct(vecN) * vecN1).Point2d());
}
}
else if (part > 0.7)
{
var vecN1 = (ptE - ptS).GetNormal();
for (var i = parmE; i < pl.NumberOfVertices; i++)
{
var item = Convert.ToInt32(i);
var ptTem = plSel.GetPointAtParameter(item);
pl.SetPointAt(item,(ptTem + vec.DotProduct(vecN) * vecN1).Point2d());
}
}
else
{
var pt00 = plSel.GetPointAtParameter(parmS - 1);
var pt11 = plSel.GetPointAtParameter(parmE + 1);
var vecN1 = (pt00 - ptS).GetNormal();
var vecN2 = (pt11 - ptE).GetNormal();
pl.SetPointAt(indexS, (ptS + vec.DotProduct(vecN1) * vecN1).Point2d());
pl.SetPointAt(indexE, (ptE + vec.DotProduct(vecN2) * vecN2).Point2d());
// pl.Move(pl.StartPoint-ptTemp);
}
}
}
}
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|