文档彩票走势图>>VectorDraw Developer Framework使用教程>>VDF常见问题整理(三十一):如何将PolarTrack捕捉到固定距离步长?
VDF常见问题整理(三十一):如何将PolarTrack捕捉到固定距离步长?
VectorDraw Developer Framework(VDF)是一个用于应用程序可视化的图形引擎库。有了VDF提供的功能,您可以轻松地创建、编辑、管理、输出、输入和打印2D和3D图形文件。
VectorDraw Developer Framework试用版下载
问:
如何将PolarTrack捕捉到固定距离步长并显示捕捉点的视觉指示?即当用户将距离设置为5时,将以5、10、15等距离启用捕捉。
答:
通过使用vdDocument对象类型的OnPolarTrackAngleValidate事件,可以完全操纵或更改PolarTrack的功能。在本文中,我们将设置一个距离间隔,该间隔将用于以特定角度和距参考点的特定距离捕捉,在捕捉点上还将显示一个视觉指示(红色圆圈)。
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; } }
对于以上问答,如果您有任何的疑惑都可以在评论区留言,我们会及时回复。此系列的问答教程我们会持续更新,如果您感兴趣,可以多多关注本教程。
热门文章推荐:
如果您对想要购买正版授权VectorDraw Developer Framework(VDF),可以联系咨询相关问题。
关注慧聚IT微信公众号 ???,了解产品的最新动态及最新资讯。