public static string ToSVG(this Rg.Ellipse input) { Rg.Vector3d axisX = input.Plane.XAxis; axisX.Unitize(); axisX = axisX * input.Radius1; Rg.Vector3d axisY = input.Plane.YAxis; axisY.Unitize(); axisY = axisY * input.Radius2; Rg.Point3d A = input.Plane.Origin + axisX; Rg.Point3d B = input.Plane.Origin + axisY; axisX.Reverse(); axisY.Reverse(); Rg.Point3d C = input.Plane.Origin + axisX; Rg.Point3d D = input.Plane.Origin + axisY; double radians = Rg.Vector3d.VectorAngle(input.Plane.YAxis, Rg.Vector3d.YAxis, Rg.Plane.WorldXY); double degrees = 180.0 - (radians / Math.PI) * 180.0; int flip = Convert.ToInt32(!(Rg.Vector3d.VectorAngle(input.Plane.ZAxis, Rg.Vector3d.ZAxis) > 1)); return("M " + A.ToSVG() + " A " + input.Radius1 + ", " + input.Radius2 + " " + degrees + " 0," + flip + " " + B.ToSVG() + " A " + input.Radius1 + ", " + input.Radius2 + " " + degrees + " 0," + flip + " " + C.ToSVG() + " A " + input.Radius1 + ", " + input.Radius2 + " " + degrees + " 0," + flip + " " + D.ToSVG() + " A " + input.Radius1 + ", " + input.Radius2 + " " + degrees + " 0," + flip + " " + A.ToSVG()); }
public void SpreadObjects(double step, Boolean refresh) { if (myDisplayBool == null) { } else { Rhino.Display.RhinoView myViewport = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView; Rhino.Display.RhinoViewport viewport = myViewport.ActiveViewport; //viewport.DisplayMode = Rhino.Display.DisplayModeDescription.FindByName("Wireframe"); Rhino.Geometry.BoundingBox myGlobalBbox = new Rhino.Geometry.BoundingBox(); myGlobalBbox = Rhino.Geometry.BoundingBox.Empty; List <Rhino.Geometry.Point3d> myCentroids = new List <Rhino.Geometry.Point3d>(); //myCentroids.Clear(); //Rhino.Geometry.Point3d explosionCenter; // First iteration: find initial object and initial bounding box center if (originalCentroids.Count == 0 || refresh == true) { myCentroids.Clear(); foreach (Guid guid in allGuids) { RhinoObject foundObject = Rhino.RhinoDoc.ActiveDoc.Objects.Find(guid); Rhino.Geometry.BoundingBox foundBbox = foundObject.Geometry.GetBoundingBox(true); myGlobalBbox.Union(foundBbox); myCentroids.Add(foundBbox.Center); explosionCenter = myGlobalBbox.Center; } originalCentroids = myCentroids; } else { for (int i = 0; i < allGuids.Count; i++) { RhinoObject foundObject = Rhino.RhinoDoc.ActiveDoc.Objects.Find(allGuids[i]); Rhino.Geometry.Vector3d trans = explosionCenter - originalCentroids[i]; // Brings back to original position. Rhino.Geometry.Vector3d backTrans = originalCentroids[i] - foundObject.Geometry.GetBoundingBox(true).Center; trans.Unitize(); Rhino.RhinoDoc.ActiveDoc.Objects.Transform(foundObject, Rhino.Geometry.Transform.Translation(backTrans - Rhino.Geometry.Vector3d.Multiply(step, trans)), true); Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); } } } }
public void set_direction(Rhino.Geometry.Point3d rec, Rhino.Geometry.Vector3d V) { this.Enabled = true; V.Unitize(); Dir = new Rhino.Geometry.Line(rec, rec + V); }
/// <summary> /// /// </summary> /// <param name="vPos"></param> /// <param name="connectedVerts"></param> /// <param name="thickness_"></param> /// <returns></returns> public static Polyline OffsetNode(Point3d vPos, List <Point3d> connectedVerts, double thickness_) { List <Curve[]> offsets = new List <Curve[]>(); List <Curve> crvs = new List <Curve>(); Polyline out_c = new Polyline(); //set curves per graph connectivity int connectedCount = connectedVerts.Count; if (connectedCount < 2) { return(out_c); } for (int i = 0; i < connectedCount; i++) { List <Point3d> vp = new List <Point3d>(); Rhino.Geometry.Vector3d dir = new Rhino.Geometry.Vector3d(); dir = connectedVerts[i] - vPos; dir.Unitize(); dir *= thickness_; dir += (Rhino.Geometry.Vector3d)vPos; vp.Add((Point3d)dir); vp.Add(vPos); dir = connectedVerts[(i + 1) % connectedCount] - vPos; dir.Unitize(); dir *= thickness_; dir += (Rhino.Geometry.Vector3d)vPos; vp.Add((Point3d)dir); Polyline crv = new Polyline(vp); crvs.Add(crv.ToPolylineCurve()); } //create offsets based on curves if (connectedCount > 2) { foreach (var c in crvs) { Point3d s = c.PointAtStart; Point3d e = c.PointAtEnd; Point3d dir = (s + e) / 2; offsets.Add(c.Offset(dir, Rhino.Geometry.Vector3d.ZAxis, thickness_ * 0.5, 0.001, CurveOffsetCornerStyle.Sharp)); } } else { foreach (var c in crvs) { c.Reverse(); offsets.Add(c.Offset(Plane.WorldXY, thickness_ * 0.5, 0.001, CurveOffsetCornerStyle.Sharp)); } } //create end connections for close polyline crvs = new List <Curve>(); foreach (var o in offsets) { foreach (var c in o) { crvs.Add(c); } } List <Curve> joinCurves = new List <Curve>(); for (int i = 0; i < crvs.Count; i++) { List <Point3d> vp = new List <Point3d>(); vp.Add(crvs[i].PointAtEnd); vp.Add(crvs[(i + 1) % crvs.Count].PointAtStart); PolylineCurve c = new PolylineCurve(vp); joinCurves.Add(offsets[i][0]); joinCurves.Add(c); } //Join curves Curve.JoinCurves(joinCurves)[0].TryGetPolyline(out out_c); return(out_c); }
private void createModel() { /* * Rhino.Geometry.Point3d origin = Util.openTkToRhinoPoint(Util.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(0, 0, 0))); * Rhino.Geometry.Point3d normalP1 = Util.openTkToRhinoPoint(Util.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(0, 0, -0.05f))); * Rhino.Geometry.Point3d normalP2 = Util.openTkToRhinoPoint(Util.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(0, 0, -1))); * Rhino.Geometry.Vector3d normal = new Rhino.Geometry.Vector3d(normalP2.X - normalP1.X, normalP2.Y - normalP1.Y, normalP2.Z - normalP1.Z); * Plane plane = new Plane(origin, normal); * float radius = 20; * Rhino.Geometry.Circle circle = new Rhino.Geometry.Circle(plane, origin, radius); * NurbsCurve circleCurve = circle.ToNurbsCurve(); * * //compute transform to follow controllers * OpenTK.Matrix4 tansform = mScene.robotToPlatform * mScene.vrToRobot * Util.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx); * Transform t = Util.OpenTKToRhinoTransform(tansform); * circleCurve.Transform(t); * Brep[] shapes = Brep.CreatePlanarBreps(circleCurve); * Brep circle_s = shapes[0]; * Brep circleBrep = circle_s; * * Guid renderObjId = Util.addSceneNode(ref mScene, circleBrep, ref mesh_m, "circle"); */ //offset the point a little bit to make the plane better OpenTK.Vector4 controller_p = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, -0.05f, 1); OpenTK.Vector4 controller_pZ = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, -1, 1); Point3d controller_pRhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_p.X, controller_p.Y, controller_p.Z))); Point3d controller_pZRhin = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_pZ.X, controller_pZ.Y, controller_pZ.Z))); //fix the x and y axis of the model Plane OpenTK.Vector4 controller_x1 = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(1, 0, 0, 1); OpenTK.Vector4 controller_y1 = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 1, 0, 1); Point3d controller_x1Rhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_x1.X, controller_x1.Y, controller_x1.Z))); Point3d controller_y1Rhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_y1.X, controller_y1.Y, controller_y1.Z))); OpenTK.Vector4 controller_o = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, 0, 1); Point3d controller_oRhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_o.X, controller_o.Y, controller_o.Z))); Rhino.Geometry.Vector3d normal = new Rhino.Geometry.Vector3d(controller_pZRhin.X - controller_oRhino.X, controller_pZRhin.Y - controller_oRhino.Y, controller_pZRhin.Z - controller_oRhino.Z); normal.Unitize(); modelPlane = new Plane(controller_oRhino, normal); if (shapeType == ShapeType.Circle) { Rhino.Geometry.Circle circle = new Rhino.Geometry.Circle(modelPlane, controller_oRhino, radius); modelcurve = circle.ToNurbsCurve(); } else if (shapeType == ShapeType.Rect) { Rhino.Geometry.Vector3d xAxis = new Rhino.Geometry.Vector3d(controller_x1Rhino.X - controller_oRhino.X, controller_x1Rhino.Y - controller_oRhino.Y, controller_x1Rhino.Z - controller_oRhino.Z); xAxis.Unitize(); Rhino.Geometry.Vector3d yAxis = new Rhino.Geometry.Vector3d(controller_y1Rhino.X - controller_oRhino.X, controller_y1Rhino.Y - controller_oRhino.Y, controller_y1Rhino.Z - controller_oRhino.Z); yAxis.Unitize(); modelPlane.XAxis = xAxis; modelPlane.YAxis = yAxis; //Rectangle3d rect = new Rectangle3d(modelPlane, width, height); Rectangle3d rect = new Rectangle3d(modelPlane, new Interval(-width / 2, width / 2), new Interval(-height / 2, height / 2)); modelcurve = rect.ToNurbsCurve(); } if (modelcurve != null) { Brep[] shapes = Brep.CreatePlanarBreps(modelcurve); modelBrep = shapes[0]; UtilOld.updateSceneNode(ref mScene, modelBrep, ref mesh_m, "3D-" + shapeType.ToString(), ref previewObjSN); } }
public void generateModel() { //TODO-simplify the curve and pass to model function simplifyCurve(ref ((Geometry.GeometryStroke)(stroke_g)).mPoints); //result curve is simplifiedCurve if (dynamicRender == "none" || simplifiedCurve == null) { return; } else if (dynamicRender == "Revolve") { if (mScene.iCurveList.Count == 0) { if (drawnType != DrawnType.In3D && curveOnObjRef != null) { simplifiedCurve.SetUserString(CurveData.CurveOnObj.ToString(), curveOnObjRef.ObjectId.ToString()); simplifiedCurve.SetUserString(CurveData.PlaneOrigin.ToString(), curvePlane.Origin.ToString()); simplifiedCurve.SetUserString(CurveData.PlaneNormal.ToString(), curvePlane.Normal.ToString()); } mScene.iCurveList.Add(simplifiedCurve); } else { //get the curve info for later update use oldCurveOnObjID = mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.CurveOnObj.ToString()); oldPlaneOrigin = mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.PlaneOrigin.ToString()); oldPlaneNormal = mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.PlaneNormal.ToString()); simplifiedCurve.SetUserString(CurveData.CurveOnObj.ToString(), oldCurveOnObjID); simplifiedCurve.SetUserString(CurveData.PlaneOrigin.ToString(), oldPlaneOrigin); simplifiedCurve.SetUserString(CurveData.PlaneNormal.ToString(), oldPlaneNormal); mScene.iCurveList[0] = simplifiedCurve; } dynamicBrep = UtilOld.RevolveFunc(ref mScene, ref mScene.iCurveList); } //TODO- fix the bug that when release, it accidently assign the old plane id to the curve. else if (dynamicRender == "Loft") { if (mScene.iCurveList.Count == 1) { if (drawnType != DrawnType.In3D && curveOnObjRef != null) { simplifiedCurve.SetUserString(CurveData.CurveOnObj.ToString(), curveOnObjRef.ObjectId.ToString()); simplifiedCurve.SetUserString(CurveData.PlaneOrigin.ToString(), curvePlane.Origin.ToString()); simplifiedCurve.SetUserString(CurveData.PlaneNormal.ToString(), curvePlane.Normal.ToString()); } mScene.iCurveList.Add(simplifiedCurve); } else { oldCurveOnObjID = mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.CurveOnObj.ToString()); oldPlaneOrigin = mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.PlaneOrigin.ToString()); oldPlaneNormal = mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.PlaneNormal.ToString()); simplifiedCurve.SetUserString(CurveData.CurveOnObj.ToString(), oldCurveOnObjID); simplifiedCurve.SetUserString(CurveData.PlaneOrigin.ToString(), oldPlaneOrigin); simplifiedCurve.SetUserString(CurveData.PlaneNormal.ToString(), oldPlaneNormal); mScene.iCurveList[1] = simplifiedCurve; } dynamicBrep = UtilOld.LoftFunc(ref mScene, ref mScene.iCurveList); } else if (dynamicRender == "Extrude") { //Rhino.Geometry.Vector3d heightVector = simplifiedCurve.PointAtEnd - simplifiedCurve.PointAtStart; Rhino.Geometry.Vector3d heightVector = simplifiedCurve.PointAtEnd - snapPointsList[0]; Rhino.Geometry.Vector3d planeNormal = UtilOld.getVectorfromString(localListCurve[0].GetUserString(CurveData.PlaneNormal.ToString())); planeNormal.Unitize(); double height = Rhino.Geometry.Vector3d.Multiply(heightVector, planeNormal) / planeNormal.Length; List <Point3d> extrudeCurveP = new List <Point3d>(); Point3d startP = snapPointsList[0]; extrudeCurveP.Add(startP); Point3d endP = new Point3d(startP.X + height * planeNormal.X, startP.Y + height * planeNormal.Y, startP.Z + height * planeNormal.Z); extrudeCurveP.Add(endP); //update the edit curve editCurve = Rhino.Geometry.NurbsCurve.Create(false, 1, extrudeCurveP.ToArray()); if (localListCurve.Count == 1) { if (drawnType != DrawnType.In3D && curveOnObjRef != null) { editCurve.SetUserString(CurveData.CurveOnObj.ToString(), curveOnObjRef.ObjectId.ToString()); editCurve.SetUserString(CurveData.PlaneOrigin.ToString(), curvePlane.Origin.ToString()); editCurve.SetUserString(CurveData.PlaneNormal.ToString(), curvePlane.Normal.ToString()); } localListCurve.Add(editCurve); } else { oldCurveOnObjID = mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.CurveOnObj.ToString()); oldPlaneOrigin = mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.PlaneOrigin.ToString()); oldPlaneNormal = mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.PlaneNormal.ToString()); editCurve.SetUserString(CurveData.CurveOnObj.ToString(), oldCurveOnObjID); editCurve.SetUserString(CurveData.PlaneOrigin.ToString(), oldPlaneOrigin); editCurve.SetUserString(CurveData.PlaneNormal.ToString(), oldPlaneNormal); localListCurve[1] = editCurve; } dynamicBrep = UtilOld.ExtrudeFunc(ref mScene, ref localListCurve); } else if (dynamicRender == "Sweep") { if (localListCurve.Count == 1) { if (drawnType != DrawnType.In3D && curveOnObjRef != null) { simplifiedCurve.SetUserString(CurveData.CurveOnObj.ToString(), curveOnObjRef.ObjectId.ToString()); simplifiedCurve.SetUserString(CurveData.PlaneOrigin.ToString(), curvePlane.Origin.ToString()); simplifiedCurve.SetUserString(CurveData.PlaneNormal.ToString(), curvePlane.Normal.ToString()); } localListCurve.Add(simplifiedCurve); } else { oldCurveOnObjID = mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.CurveOnObj.ToString()); oldPlaneOrigin = mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.PlaneOrigin.ToString()); oldPlaneNormal = mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.PlaneNormal.ToString()); simplifiedCurve.SetUserString(CurveData.CurveOnObj.ToString(), oldCurveOnObjID); simplifiedCurve.SetUserString(CurveData.PlaneOrigin.ToString(), oldPlaneOrigin); simplifiedCurve.SetUserString(CurveData.PlaneNormal.ToString(), oldPlaneNormal); localListCurve[1] = simplifiedCurve; } dynamicBrep = UtilOld.SweepFun(ref mScene, ref localListCurve); } /* * mScene.iCurveList.Clear(); * //mScene.iCurveList = localListCurve; * foreach (Curve c in localListCurve) * { * mScene.iCurveList.Add(c); * } */ }
private WR_Vector GetUnitizedWR_Vector(Rhino.Geometry.Vector3d rhVec) { rhVec.Unitize(); return(new WR_Vector(rhVec.X, rhVec.Y, rhVec.Z)); }