文檔首頁>>VectorDraw Developer Framework使用教程>>VDF常見問題整理(三十一):如何將PolarTrack捕捉到固定距離步長?
VDF常見問題整理(三十一):如何將PolarTrack捕捉到固定距離步長?
VectorDraw Developer Framework(VDF)是一個用于應用程序可視化的圖形引擎庫。有了VDF提供的功能,您可以輕松地創(chuàng)建、編輯、管理、輸出、輸入和打印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; } }
對于以上問答,如果您有任何的疑惑都可以在評論區(qū)留言,我們會及時回復。此系列的問答教程我們會持續(xù)更新,如果您感興趣,可以多多關注本教程。
熱門文章推薦:
如果您對想要購買正版授權VectorDraw Developer Framework(VDF),可以聯系在線客服>>咨詢相關問題。
關注慧聚IT微信公眾號 ???,了解產品的最新動態(tài)及最新資訊。