VDF常见问题整理(三十一):如何将PolarTrack捕捉到固定距离步长?

VectorDraw Developer Framework试用版下载


问:

    如何将PolarTrack捕捉到固定距离步长并显示捕捉点的视觉指示当用户将距离设置为5时,将以5、10、15等距离启用捕捉。

答:

private void Form1_Load(object sender, EventArgs e){    //Adding the event handlers that will override the default functionality.    vdFramedControl1.BaseControl.ActiveDocument.OnPolarTrackAngleValidate += ActiveDocument_OnPolarTrackAngleValidate;    vdFramedControl1.BaseControl.ActionDraw += new VectorDraw.Professional.Control.ActionDrawEventHandler(BaseControl_ActionDraw);    //PolarTrack should also be enabled.    vdFramedControl1.BaseControl.ActiveDocument.PolarTrack = true;}void BaseControl_ActionDraw(object sender, object action, bool isHideMode, ref bool cancel){    //If IsHideMode is true, nothing should be drawn on the render.    if (isHideMode) return;    VectorDraw.Actions.BaseAction act = action as VectorDraw.Actions.BaseAction;    if (act == null) return;    //If PolarTrack is off or there is not a ReferencePoint the draw will be cancelled.    if (!act.IsPolarTrackOn || act.ReferencePoint == null) return;    //Draw a small red circle at the OrthoPoint.    act.Render.PushPenstyle(new VectorDraw.Render.vdGdiPenStyle(Color.Red, 255));    act.Render.DrawArc(sender, act.OrthoPoint, 0, Globals.VD_TWOPI, act.Render.PixelSize * 5);    act.Render.PopPenstyle();}//You can use set angle values to snap on.double[] AdditionalAngles = {15, 25, 35};private void ActiveDocument_OnPolarTrackAngleValidate(object sender, VectorDraw.Geometry.gPoint referencePoint, VectorDraw.Geometry.gPoint currentPoint, double DefaultEquality, ref double NewTrackingAngle, ref bool isValid, ref bool cancel){    cancel = true;    double plrAngle = vdFramedControl1.BaseControl.ActiveDocument.PolarTrackAngle;    //The following for statement checks the current angle with all our additional angles.    bool addAng = false;    for (int i = 0; i < AdditionalAngles.Length; i++)    {        double angRad = Globals.DegreesToRadians(AdditionalAngles[i]);        if (Globals.AreEqualAngle(angRad, NewTrackingAngle, DefaultEquality))        {            addAng = true;            NewTrackingAngle = angRad;        }    }    //Checking if our angle is close to any multiple of the PolarTrackAngle.    //First if statement checks angles greater than the PolarTrackAngle.    if (NewTrackingAngle % plrAngle < DefaultEquality) NewTrackingAngle = NewTrackingAngle - (NewTrackingAngle % plrAngle);    //Second if statement checks angles smaller than the PolarTrackAngle.    else if ((plrAngle - NewTrackingAngle % plrAngle) < DefaultEquality) NewTrackingAngle = NewTrackingAngle + (plrAngle - NewTrackingAngle % plrAngle);    else if (!addAng) return;                //polarStep is the interval distance that snapping will be performed.    double polarStep = 2;    double sensitivity = 0.5;    double dist = referencePoint.Distance2D(currentPoint);    double distR = Math.Round(dist);    if ((distR % polarStep == 0) && Math.Abs(dist - distR) < sensitivity)    {        gPoint p = referencePoint.Polar(NewTrackingAngle, distR);        currentPoint.x = p.x;        currentPoint.y = p.y;        cancel = false;        isValid = true;    }}

    对于以上问答,如果您有任何的疑惑都可以在评论区留言,我们会及时回复。此系列的问答教程我们会持续更新,如果您感兴趣,可以多多关注本教程。

热门文章推荐:

  • 如何排除GroundSurface对象的三角形区域/strong>

  • 复杂自定义对象的入门指南


    如果您对想要购买正版授权VectorDraw Developer Framework(VDF),可以联系在线客服>>咨询相关问题。

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年9月27日
下一篇 2019年9月27日

相关推荐

发表回复

登录后才能评论