public override hresult PlaceObject(PlaceFlags lInsertType) { InputJig jig = new InputJig(); InputResult res = jig.SelectObject("Select Line"); if (res.Result != InputResult.ResultCode.Normal) { return(hresult.e_Fail); } LineSeg3d line = res.Geometry.LineSeg; _pnt1 = line.StartPoint; _pnt2 = line.EndPoint; McObjectId id = res.ObjectId; DbGeometry selection = id.GetObject(); //if (selection.IsKindOf(DbPolyline.TypeID)) //{ // MessageBox.Show("poly"); //} //else if (selection.IsKindOf(DbLine.TypeID)) //{ // MessageBox.Show("line"); //} //else //{ // MessageBox.Show("Objecttype isn't valid"); // DbEntity.Erase(); // return hresult.e_Fail; //} DbEntity.AddToCurrentDocument(); return(hresult.s_Ok); }
public bool GetCrossTrackErr(Vector3 pos, ref float err) { if (iActiveSpan >= nodes.Count - 2) { return(false); } PathNode a = nodes[iActiveSpan]; PathNode b = nodes[iActiveSpan + 1]; //2d path. pos.y = a.pos.y; LineSeg3d pathSeg = new LineSeg3d(ref a.pos, ref b.pos); pathSeg.Draw(Color.green); LineSeg3d.SegResult segRes = new LineSeg3d.SegResult(); Vector3 closePt = pathSeg.ClosestPointOnSegmentTo(ref pos, ref segRes); Debug.DrawLine(a.pos, closePt, Color.blue); if (segRes == LineSeg3d.SegResult.GreaterThanEnd) { iActiveSpan++; } else if (segRes == LineSeg3d.SegResult.LessThanOrigin) { if (iActiveSpan > 0) { iActiveSpan--; } } Vector3 errVec = pathSeg.ClosestVectorTo(ref pos); Debug.DrawRay(closePt, errVec, Color.white); float sign = 1.0f; Vector3 cp = Vector3.Cross(pathSeg.m_dir.normalized, errVec.normalized); if (cp.y > 0.0f) { sign = -1f; } err = errVec.magnitude * sign; return(true); }
public void SmoothPath(float factor = 0.5f) { LineSeg3d.SegResult segRes = new LineSeg3d.SegResult(); for (int iN = 1; iN < nodes.Count - 2; iN++) { PathNode p = nodes[iN - 1]; PathNode c = nodes[iN]; PathNode n = nodes[iN + 1]; LineSeg3d seg = new LineSeg3d(ref p.pos, ref n.pos); Vector3 closestP = seg.ClosestPointOnSegmentTo(ref c.pos, ref segRes); Vector3 dIntersect = closestP - c.pos; c.pos += dIntersect.normalized * factor; } }
public bool GetCrossTrackErr(Vector3 pos, ref int iActiveSpan, ref float err, int lookAhead = 1) { int nextIActiveSpan = (iActiveSpan + 1) % (nodes.Count); int aheadIActiveSpan = (iActiveSpan + lookAhead) % (nodes.Count); PathNode a = nodes[iActiveSpan]; PathNode b = nodes[nextIActiveSpan]; PathNode c = nodes[aheadIActiveSpan]; //2d path. pos.y = a.pos.y; LineSeg3d pathSeg = new LineSeg3d(ref a.pos, ref c.pos); LineSeg3d.SegResult segRes = new LineSeg3d.SegResult(); Vector3 closePt = pathSeg.ClosestPointOnSegmentTo(ref pos, ref segRes); Vector3 errVec = pathSeg.ClosestVectorTo(ref pos); pathSeg.Draw(Color.green); Debug.DrawLine(a.pos, closePt, Color.blue); Debug.DrawRay(closePt, errVec, Color.white); float sign = 1.0f; Vector3 cp = Vector3.Cross(pathSeg.m_dir.normalized, errVec.normalized); if (cp.y > 0.0f) { sign = -1f; } err = errVec.magnitude * sign; int oldActiveSpan = iActiveSpan; float dista = Vector3.Distance(a.pos, pos); float distb = Vector3.Distance(b.pos, pos); if (dista > distb) { iActiveSpan = (iActiveSpan + 1) % (nodes.Count); } // if (iActiveSpan - oldActiveSpan <= 0) { return true; } // we lapped return(false); // we are on the same lap }
public override hresult PlaceObject(PlaceFlags lInsertType) { InputJig jig = new InputJig(); InputResult res = jig.SelectObject("Select Line"); if (res.Result != InputResult.ResultCode.Normal) { return(hresult.e_Fail); } LineSeg3d line = res.Geometry.LineSeg; poly = new Polyline3d(line); McObjectId id = res.ObjectId; DbGeometry selection = id.GetObject(); DbEntity.AddToCurrentDocument(); return(hresult.s_Ok); }
public override void OnDraw(GeometryBuilder dc) { dc.Clear(); dc.Color = McDbEntity.ByObject;//color will be taken from object properties and object will be redrawn after color change if (V_true == 0) { double pos_thickness = Thickness < 0 ? Thickness * -1 : Thickness; if (pos_thickness < 3) { V = 16; } else if (pos_thickness == 3) { V = 20; } else if (pos_thickness == 4) { V = 35; } else if (pos_thickness > 4) { V = 50; } } else { V = V_true; } Polyline3d polyround = new Polyline3d(poly); _length_sum = 0; //HostMgd.EditorInput.Editor ed = HostMgd.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; for (int i = 2; i < polyround.Vertices.Count; i += 2) { //double angle1 = Math.Atan2(polyround.Vertices[i - 2].Point.X - polyround.Vertices[i - 1].Point.X, polyround.Vertices[i - 2].Point.Y - polyround.Vertices[i - 1].Point.Y); //double angle2 = Math.Atan2(polyround.Vertices[i - 1].Point.X - polyround.Vertices[i].Point.X, polyround.Vertices[i - 1].Point.Y - polyround.Vertices[i].Point.Y); double anglesum = (polyround.Vertices[i - 1].Point.X - polyround.Vertices[i].Point.X) * (polyround.Vertices[i - 2].Point.Y - polyround.Vertices[i].Point.Y) - (polyround.Vertices[i - 1].Point.Y - polyround.Vertices[i].Point.Y) * (polyround.Vertices[i - 2].Point.X - polyround.Vertices[i].Point.X);//Math.Atan((angle2 - angle1) / (1 + angle2 * angle1));//angle1 + angle2 double a = polyround.Vertices[i - 2].Point.DistanceTo(polyround.Vertices[i - 1].Point); double b = polyround.Vertices[i - 1].Point.DistanceTo(polyround.Vertices[i].Point); double c = polyround.Vertices[i - 2].Point.DistanceTo(polyround.Vertices[i].Point); double angle = Math.Acos((Math.Pow(a, 2) + Math.Pow(b, 2) - Math.Pow(c, 2)) / (2 * a * b)); angle = angle * 180 / Math.PI; double r = V * 0.16; double pos_thickness = Thickness < 0 ? Thickness * -1 : Thickness; double BA = Math.PI / 180 * (180 - angle) * (r + k_factor * pos_thickness); _length_sum += BA; double radius; if (anglesum < 0) { radius = V * 0.16; } else { radius = V * 0.16 + Thickness; } if (Thickness < 0) { radius += Thickness * -1; } polyround.Vertices.MakeFilletAtVertex(i - 1, radius); } for (int i = 0; i < polyround.Vertices.Count; i += 2) { LineSeg3d line = polyround.Segments[i] as LineSeg3d; _length_sum += line.Length; } _length_sum = Math.Round(_length_sum, 4); Polyline3d offset = polyround.GetTrimmedOffset(-Thickness)[0]; dc.DrawPolyline(polyround); dc.DrawPolyline(offset); dc.DrawLine(polyround.Points.FirstPoint, offset.Points.FirstPoint); dc.DrawLine(polyround.Points.LastPoint, offset.Points.LastPoint); Polyline3d middlePoly = polyround.GetTrimmedOffset(-Thickness * (Thickness < 0 ? 1 - k_factor : k_factor))[0]; dc.TextHeight = 2.5 * DbEntity.Scale; //Use annotation scale dc.DrawMText(_textPoint, Vector3d.XAxis, Math.Round(_length_sum, 1).ToString(), HorizTextAlign.Center, VertTextAlign.Center); dc.StrLineType = "Center"; dc.Color = Color.Yellow; dc.LinetypeScale = DbEntity.LinetypeScale * 0.3; dc.DrawPolyline(middlePoly); }