//p1 - start na otse4kata, p2 - end of segment // nout internal - return null public quaternion IsInternalForSegment(quaternion lP1, quaternion lP2) { quaternion rez = (new quaternion(q[0], q[1], q[2], q[3]) - lP1) / (lP2 - lP1); return((rez.absV() < Constants.zero_dist && rez.real() > Constants.zero_dist && rez.real() < (1.0 - Constants.zero_dist)) ? rez : null); }
//p1 - start na otse4kata, p2 - end of segment // nout internal - return null public static quaternion IsInternalForSegment(quaternion p1, quaternion p2, quaternion p) { quaternion rez = (p - p1) / (p2 - p1); return((rez.absV() < Constants.zero_dist && rez.real() > Constants.zero_dist && rez.real() < (1.0 - Constants.zero_dist)) ? rez : null); }
public void KojtoCAD_3D_Check() { Database db = HostApplicationServices.WorkingDatabase; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; Matrix3d old = ed.CurrentUserCoordinateSystem; ed.CurrentUserCoordinateSystem = Matrix3d.Identity; try { TypedValue[] acTypValAr = new TypedValue[1]; acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "LINE"), 0); List <Entity> solids = GlobalFunctions.GetSelection(ref acTypValAr, "Select Lines: "); using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTable acBlkTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; foreach (Entity ent in solids) { Line Line1 = tr.GetObject(ent.ObjectId, OpenMode.ForWrite) as Line; quaternion qStart1 = Line1.StartPoint; quaternion qEnd1 = Line1.EndPoint; quaternion q1 = qEnd1 - qStart1; foreach (Entity ENT in solids) { if (ENT.ObjectId != ent.ObjectId) { Line Line2 = tr.GetObject(ENT.ObjectId, OpenMode.ForWrite) as Line; quaternion qStart2 = Line2.StartPoint; quaternion qEnd2 = Line2.EndPoint; quaternion QQ1 = Common.IsCoincidentWithLine(qStart1, qEnd1, qStart2); quaternion QQ2 = Common.IsCoincidentWithLine(qStart1, qEnd1, qEnd2); if (((object)QQ1 != null || (object)QQ2 != null) && !((object)QQ1 != null && (object)QQ2 != null)) { //internal - Q1 != null quaternion Q1 = Common.IsInternalForSegment(qStart1, qEnd1, qStart2); //internal - Q2 != null quaternion Q2 = Common.IsInternalForSegment(qStart1, qEnd1, qEnd2); #region split or no if ((object)Q1 != null || (object)Q2 != null) { Point3d p = (Point3d)(q1 * (((object)Q1 != null) ? Q1.real() : Q2.real()) + qStart1); Line Line3 = new Line((Point3d)qStart1, p); Line3.Layer = Line1.Layer; Line3.ColorIndex = Line1.ColorIndex; acBlkTblRec.AppendEntity(Line3); tr.AddNewlyCreatedDBObject(Line3, true); Line Line4 = new Line((Point3d)qEnd1, p); Line4.Layer = Line1.Layer; Line4.ColorIndex = Line1.ColorIndex; acBlkTblRec.AppendEntity(Line4); tr.AddNewlyCreatedDBObject(Line4, true); Line1.Erase(); break; } } #endregion } } if (!Line1.IsErased) { Line1.Visible = true; } } tr.Commit(); } } catch { } finally { ed.CurrentUserCoordinateSystem = old; } }