/// <summary> /// Transform calculator /// </summary> public bool CalculateTransform(Rhino.Display.RhinoViewport vp, double length, ref Rhino.Geometry.Transform xform) { bool rc = false; if (null == xform) { xform = new Rhino.Geometry.Transform(); } xform = Rhino.Geometry.Transform.Identity; if (length >= Rhino.RhinoMath.ZeroTolerance) { Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(vp.ConstructionPlane()) { Origin = m_origin }; Rhino.Geometry.Transform rotate_xform = Rhino.Geometry.Transform.PlaneToPlane(Rhino.Geometry.Plane.WorldXY, plane); Rhino.Geometry.Transform scale_xform = Rhino.Geometry.Transform.Scale(plane, length, length, length); xform = scale_xform * rotate_xform; rc = xform.IsValid; if (rc) { m_length = length; } } return(rc); }
public static Rhino.Commands.Result Stretch(Rhino.RhinoDoc doc) { ObjectType filter = SpaceMorphObjectFilter(); Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select object to stretch", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) { return(rc); } Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane(); Rhino.Geometry.Line axis; rc = Rhino.Input.RhinoGet.GetLine(out axis); if (rc != Rhino.Commands.Result.Success || axis == null) { return(rc); } Rhino.Geometry.Morphs.StretchSpaceMorph morph = new Rhino.Geometry.Morphs.StretchSpaceMorph(axis.From, axis.To, axis.Length * 1.5); Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate(); if (morph.Morph(geom)) { doc.Objects.Add(geom); doc.Views.Redraw(); } return(Rhino.Commands.Result.Success); }
protected override void DrawOverlay(Rhino.Display.DrawEventArgs e) { base.DrawOverlay(e); Rhino.Display.RhinoView myViewport = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView; Rhino.Display.RhinoViewport viewport = myViewport.ActiveViewport; for (int i = 0; i < Ids.Count; i++) { RhinoObject foundObject = Rhino.RhinoDoc.ActiveDoc.Objects.Find(Ids[i]); Rhino.Geometry.BoundingBox bbox = foundObject.Geometry.GetBoundingBox(true); Rhino.Geometry.Plane myFrustumPlane = new Rhino.Geometry.Plane(); //viewport.GetFrustumFarPlane(out myFrustumPlane); //myFrustumPlane.Origin = bbox.Center; //Rhino.Geometry.Circle myFrustumCircle = new Rhino.Geometry.Circle(); //myFrustumCircle.Plane = myFrustumPlane; //myFrustumCircle.Radius = bbox.Diagonal.Length / 2; //Rhino.Geometry.Curve myFrustumCurve = myFrustumCircle.ToNurbsCurve(); //myFrustumCurve.Domain = new Rhino.Geometry.Interval(0.0,1.0); //e.Display.DrawDot(myFrustumCurve.PointAtNormalizedLength(0.4), i.ToString(), System.Drawing.Color.Red, System.Drawing.Color.White); } Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); }
public static Rhino.Commands.Result AddClippingPlane(Rhino.RhinoDoc doc) { // Define the corners of the clipping plane Rhino.Geometry.Point3d[] corners; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetRectangle(out corners); if (rc != Rhino.Commands.Result.Success) { return(rc); } // Get the active view Rhino.Display.RhinoView view = doc.Views.ActiveView; if (view == null) { return(Rhino.Commands.Result.Failure); } Rhino.Geometry.Point3d p0 = corners[0]; Rhino.Geometry.Point3d p1 = corners[1]; Rhino.Geometry.Point3d p3 = corners[3]; // Create a plane from the corner points Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(p0, p1, p3); // Add a clipping plane object to the document Guid id = doc.Objects.AddClippingPlane(plane, p0.DistanceTo(p1), p0.DistanceTo(p3), view.ActiveViewportID); if (id != Guid.Empty) { doc.Views.Redraw(); return(Rhino.Commands.Result.Success); } return(Rhino.Commands.Result.Failure); }
public List <Plane> getEdgeFrames(HeGraph3d _graph, int _edgeId, double _height) { var e0 = _graph.Edges[_edgeId]; var v0 = e0.End.Position; var v1 = e0.Start.Position; var eVec = (v0 - v1).Unit; var dist = v0.DistanceTo(v1); var zUnit = new SpatialSlur.Vector3d(1, 0, 0); var n = SpatialSlur.Vector3d.Cross(eVec, zUnit).Unit; var bn = SpatialSlur.Vector3d.Cross(eVec, n).Unit; var frames = new List <Rhino.Geometry.Plane>(); double num = e0.GetLength() / _height; for (int i = 0; i < num + 1; i++) { var pt = e0.Start.Position + eVec * (dist / num) * i; var frame = new Rhino.Geometry.Plane((Point3d)pt, (Vector3d)n, (Vector3d)bn); frames.Add(frame); } return(frames); }
protected override void SolveInstance(IGH_DataAccess DA) { Box iBox = new Box(); bool isDynamic = true; Material iMaterial = PhysXManager.Physics.CreateMaterial(0.5f, 0.5f, 0.5f); DA.GetData(0, ref iBox); DA.GetData(1, ref isDynamic); DA.GetData(2, ref iMaterial); Plane plane = iBox.Plane; plane.Translate(iBox.Center - iBox.Plane.Origin); if (isDynamic) { PxGhRigidDynamic rigidDynamic = new PxGhRigidDynamicBox(plane, (float)iBox.X.Length, (float)iBox.Y.Length, (float)iBox.Z.Length, iMaterial, 1); DA.SetData(0, rigidDynamic); } else { PxGhRigidStaticBox rigidStatic = new PxGhRigidStaticBox(plane, (float)iBox.X.Length, (float)iBox.Y.Length, (float)iBox.Z.Length, iMaterial); DA.SetData(0, rigidStatic); } }
/***************************************************/ public static void RenderRhinoWires(RHG.Plane plane, Rhino.Display.DisplayPipeline pipeline, Color bhColour, int thickness) { pipeline.DrawConstructionPlane(new Rhino.DocObjects.ConstructionPlane() { Plane = plane, ThickLineColor = bhColour, ThinLineColor = Color.Black, GridLineCount = 10 }); }
/***************************************************/ /**** Public Methods - IRender ****/ /***************************************************/ public static Text3d ToRhino(this RenderText renderText) { if (renderText == null) { return(null); } RHG.Vector3d xdir = (RHG.Vector3d)renderText.Cartesian.X.IToRhino(); RHG.Vector3d ydir = (RHG.Vector3d)renderText.Cartesian.Y.IToRhino(); RHG.Point3d pos = (RHG.Point3d)renderText.Cartesian.Origin.IToRhino(); RHG.Plane textPlane = new RHG.Plane(pos, xdir, ydir); Text3d text3D = new Text3d(renderText.Text, textPlane, renderText.Height); if (renderText.FontName.Contains("Italic")) { text3D.Italic = true; } if (renderText.FontName.Contains("Bold")) { text3D.Bold = true; } text3D.FontFace = renderText.FontName.Replace("Italic", "").Replace("Bold", "").Trim(); return(text3D); }
/// <summary> /// Convert a LinearElement to a Rhino Brep /// </summary> /// <param name="element"></param> /// <returns></returns> public static RC.Brep ConvertToBrep(LinearElement element) { if (element.Geometry is Line) { return(ConvertToExtrusion(element)?.ToBrep()); } else { Curve perimeter = element?.Family?.Profile?.Perimeter; CurveCollection voids = element?.Family?.Profile?.Voids; if (perimeter != null && element.Geometry != null) { //TODO: Deal with voids! RC.Curve profile = Convert(perimeter); var cSystem = element.Geometry.LocalCoordinateSystem(0, element.Orientation); RC.Plane startPlane = Convert(cSystem.YZPlane()); profile.Transform(RC.Transform.PlaneToPlane(RC.Plane.WorldXY, startPlane)); RC.Brep[] breps = RC.Brep.CreateFromSweep(Convert(element.Geometry), profile, false, 0.001); //TODO: Change tolerance if (breps.Length > 0) { return(breps[0]); } } } return(null); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = @"Image Files|*.bmp;*.gif;*.jpg;*.jpeg;*.pcx;*.png;*.tif;*.tiff"; DialogResult rc = dialog.ShowDialog(); if (rc != DialogResult.OK) { return(Result.Cancel); } string filename = dialog.FileName; Point3d[] corners; Result res = Rhino.Input.RhinoGet.GetRectangle(out corners); if (res != Result.Success) { return(res); } Point3d p0 = corners[0]; Point3d p1 = corners[1]; Point3d p3 = corners[3]; Plane plane = new Rhino.Geometry.Plane(p0, p1, p3); double width = p0.DistanceTo(p1); double height = p0.DistanceTo(p3); doc.Objects.AddPictureFrame(plane, filename, false, width, height, true, false); doc.Views.Redraw(); return(Result.Success); }
public List <Brep> ComputeAnchorGeometry() { Vector3d NormNormalVec = NormalVec / NormalVec.Length; Point3d A = Origin + NormNormalVec * Height1 / 2; Point3d B = Origin - NormNormalVec * Height1 / 2; Point3d C = Origin - NormNormalVec * (Height1 / 2 + Height2); List <Brep> displayGeometry = new List <Brep>(); Rhino.Geometry.Plane planea = new Rhino.Geometry.Plane(A, NormNormalVec); Rhino.Geometry.Plane planeb = new Rhino.Geometry.Plane(B, NormNormalVec); Rhino.Geometry.Plane planec = new Rhino.Geometry.Plane(C, NormNormalVec); Rhino.Geometry.Circle circlea = new Rhino.Geometry.Circle(planea, Radius2); Rhino.Geometry.Circle circleb = new Rhino.Geometry.Circle(planeb, Radius1); Rhino.Geometry.Circle circlec = new Rhino.Geometry.Circle(planec, Radius2); Rhino.Geometry.Cylinder cylindera = new Rhino.Geometry.Cylinder(circlea, Height2); Rhino.Geometry.Brep brepa = cylindera.ToBrep(true, true); displayGeometry.Add(brepa); Rhino.Geometry.Cylinder cylinderb = new Rhino.Geometry.Cylinder(circleb, Height1); Rhino.Geometry.Brep brepb = cylinderb.ToBrep(true, true); displayGeometry.Add(brepb); Rhino.Geometry.Cylinder cylinderc = new Rhino.Geometry.Cylinder(circlec, Height2); Rhino.Geometry.Brep brepc = cylinderc.ToBrep(true, true); displayGeometry.Add(brepc); return(displayGeometry); }
// Start is called before the first frame update void Start() { var plane = new Rhino.Geometry.Plane(Point3d.Origin, Vector3d.ZAxis); var interval = new Interval(-0.5, 0.5); rect = new Rectangle3d(plane, interval, interval); var intervalR = new Interval(-5, 5); region = new Rectangle3d(plane, intervalR, intervalR); pts = RhinoWrapper.RandomPt(rect, numSphere); _relax = gameObject.AddComponent <Relax>(); spheres = new List <GameObject>(); var col = new Color(0.5f, 0, 0, 0.01f); for (int i = 0; i < pts.Count; i++) { var sphere = GameObject.CreatePrimitive(PrimitiveType.Quad); sphere.GetComponent <MeshRenderer>().material.color = Random.ColorHSV(1f, 1f, 1f, 1f, 0, 0); spheres.Add(sphere); } RhinoPreview.PolyLineShow(region.ToPolyline(), col, 0.3f); }
protected override void SolveInstance(IGH_DataAccess DA) { Plane iPlane = new Plane(); double iRadius = 0; bool isDynamic = true; Material iMaterial = PhysXManager.Physics.CreateMaterial(0.5f, 0.5f, 0.5f); DA.GetData(0, ref iPlane); DA.GetData(1, ref iRadius); DA.GetData(2, ref isDynamic); DA.GetData(3, ref iMaterial); PxGhRigidDynamic dynamic = new PxGhRigidDynamicSphere(iPlane, (float)iRadius, iMaterial, 1f); DA.SetData(0, dynamic); if (isDynamic) { PxGhRigidDynamic rigidDynamic = new PxGhRigidDynamicSphere(iPlane, (float)iRadius, iMaterial, 1f); DA.SetData(0, rigidDynamic); } else { PxGhRigidStaticSphere rigidStatic = new PxGhRigidStaticSphere(iPlane, (float)iRadius, iMaterial); DA.SetData(0, rigidStatic); } }
/// <summary> /// Initializes a new instance of the <see cref="Wirecutter"/> class. /// </summary> /// <param name="doc"> RhinoDoc - the file that will be used by the wirecutter class.</param> /// <param name="dt">DataTable - must contain correct column structure for toolpathing inputs.</param> /// <param name="plane"> Rhino.Geometry.Plane - the cutting plane where the geometry has been drawn, will be translated.</param> /// <param name="offset">double - the retract offset specified by the programmer.</param> public Wirecutter(RhinoDoc doc, DataTable dt, Rhino.Geometry.Plane plane, double offset) { this.DefaultSetup(); this.GeometryPlane = plane; this.Doc = doc; this.Parameters = dt; }
/// <summary> RunCommandPickPlane is a helper method for picking an existing surface to draw on </summary> /// <param name="mRhinoDoc"></param> /// <param name="mode"></param> /// <returns></returns> protected Result RunCommandPickPlane(RhinoDoc mRhinoDoc, RunMode mode) { //routine for picking an existing surface to draw on //please select a plane Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Surface; Rhino.DocObjects.ObjRef objref = null; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select surface", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) { return(rc); } Rhino.Geometry.Surface refSrf = objref.Surface(); refSrf.FrameAt(.5, .5, out plane1); Point3d pOrigin = refSrf.PointAt(1, 1); Point3d pY = refSrf.PointAt(0.5, 1); Point3d pX = refSrf.PointAt(1, 0.75); Vector3d vX = Rhino.Geometry.Point3d.Subtract(pX, pOrigin); Vector3d vY = Rhino.Geometry.Point3d.Subtract(pY, pOrigin); plane1 = new Plane(pOrigin, vX, vY); Rhino.DocObjects.RhinoObject rhobj = objref.Object(); rhobj.Select(false); mRhinoDoc.Objects.AddPoint(pOrigin); mRhinoDoc.Objects.AddPoint(pX); mRhinoDoc.Objects.AddPoint(pY); mRhinoDoc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Rhino.Geometry.Point3d[] corners; Result rc = Rhino.Input.RhinoGet.GetRectangle(out corners); if (rc != Result.Success) { return(rc); } Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(corners[0], corners[1], corners[2]); Rhino.Geometry.Interval x_interval = new Rhino.Geometry.Interval(0, corners[0].DistanceTo(corners[1])); Rhino.Geometry.Interval y_interval = new Rhino.Geometry.Interval(0, corners[1].DistanceTo(corners[2])); Rhino.Geometry.Mesh mesh = Rhino.Geometry.Mesh.CreateFromPlane(plane, x_interval, y_interval, 10, 10); //mesh.FaceNormals.ComputeFaceNormals(); //mesh.Normals.ComputeNormals(); SampleCsDrawMeshConduit conduit = new SampleCsDrawMeshConduit(); conduit.Mesh = mesh; conduit.Enabled = true; doc.Views.Redraw(); string out_str = null; rc = Rhino.Input.RhinoGet.GetString("Press <Enter> to continue", true, ref out_str); conduit.Enabled = false; doc.Views.Redraw(); return(Result.Success); }
public static GameObject TileShow(List <Rhino.Geometry.Point3d> grid, int gridSize, Color color, bool convertM = true, string name = "TileGrid") { var gridObj = new GameObject(name); Brep[] breps = new Brep[grid.Count]; // List<Brep> breps = new List<Brep>(); for (int i = 0; i < grid.Count; i++) { var pt = grid[i]; if (convertM) { var mPt = pt * (0.001); var plane = new Rhino.Geometry.Plane(mPt, Vector3d.ZAxis); var interval = new Interval((-gridSize / 2) * (0.001), (gridSize / 2) * (0.001)); var srf = new Rhino.Geometry.PlaneSurface(plane, interval, interval); var brep = srf.ToBrep(); // breps.Add(brep); breps[i] = brep; } else { var plane = new Rhino.Geometry.Plane(pt, Vector3d.ZAxis); var interval = new Interval(-gridSize / 2, gridSize / 2); var srf = new Rhino.Geometry.PlaneSurface(plane, interval, interval); var brep = srf.ToBrep(); //breps.Add(brep); breps[i] = brep; } } var joinedBrep = Rhino.Geometry.Brep.CreateBooleanUnion(breps, 0.1); var meshParam = MeshingParameters.FastRenderMesh; var meshs = Rhino.Geometry.Mesh.CreateFromBrep(joinedBrep[0], meshParam); var joinedMesh = new Rhino.Geometry.Mesh(); foreach (var m in meshs) { joinedMesh.Append(m); } joinedMesh.Weld(180); //attatch Mesh var UnityMesh = joinedMesh.ToHost(); var meshRender = gridObj.AddComponent <MeshRenderer>(); meshRender.material.color = color; meshRender.material.shader = Shader.Find("UI/Default"); var meshFilter = gridObj.AddComponent <MeshFilter>(); meshFilter.mesh = UnityMesh; return(gridObj); }
public static Matrix4x4 ToMatrix(this Plane p) => new Matrix4x4 { M11 = (float)p.XAxis.X, M12 = (float)p.XAxis.Y, M13 = (float)p.XAxis.Z, M14 = 0f, M21 = (float)p.YAxis.X, M22 = (float)p.YAxis.Y, M23 = (float)p.YAxis.Z, M24 = 0f, M31 = (float)p.ZAxis.X, M32 = (float)p.ZAxis.Y, M33 = (float)p.ZAxis.Z, M34 = 0f, M41 = (float)p.OriginX, M42 = (float)p.OriginY, M43 = (float)p.OriginZ, M44 = 1f, };
public static Transform ToTransform(this Plane p) => new Transform { M00 = p.XAxis.X, M01 = p.YAxis.X, M02 = p.ZAxis.X, M03 = p.OriginX, M10 = p.XAxis.Y, M11 = p.YAxis.Y, M12 = p.ZAxis.Y, M13 = p.OriginY, M20 = p.XAxis.Z, M21 = p.YAxis.Z, M22 = p.ZAxis.Z, M23 = p.OriginZ, M30 = 0.0, M31 = 0.0, M32 = 0.0, M33 = 1.0, };
/***************************************************/ public static RHG.Ellipse ToRhino(this BHG.Ellipse ellipse) { if (ellipse == null) { return(default(RHG.Ellipse)); } RHG.Plane plane = new RHG.Plane(ellipse.Centre.ToRhino(), ellipse.Axis1.ToRhino(), ellipse.Axis2.ToRhino()); return(new RHG.Ellipse(plane, ellipse.Radius1, ellipse.Radius2)); }
/***************************************************/ /**** Public Methods - Vectors ****/ /***************************************************/ public static bool IsEqual(this BHG.Plane bhPlane, RHG.Plane rhPlane, double tolerance = BHG.Tolerance.Distance) { if (bhPlane == null & rhPlane == default(RHG.Plane)) { return(true); } return(bhPlane.Origin.IsEqual(rhPlane.Origin, tolerance) && bhPlane.Normal.IsEqual(rhPlane.Normal, tolerance)); }
protected override void SolveInstance(IGH_DataAccess DA) { ///// INPUTS ///// Point3d pt = Point3d.Unset; List <bool> rels = new List <bool>(); Plane pl = Plane.Unset; if (!DA.GetData(0, ref pt)) { return; } if (!DA.GetDataList <bool>(1, rels)) { //Set as unrestrained if no release information is provided for (int i = 0; i < 6; i++) { rels.Add(false); } } if (rels.Count != 6) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Number of bools in input should be 6"); return; } if (!DA.GetData(2, ref pl)) { // If no plane submitted, use global XY plane pl = new Rhino.Geometry.Plane(new Rhino.Geometry.Point3d(0, 0, 0), new Rhino.Geometry.Vector3d(1, 0, 0), new Rhino.Geometry.Vector3d(0, 1, 0)); } ///// SOLVE ///// /* * double factor = Utilities.GetScalingFactorFromRhino(); * * WR_XYZ wrXYZ = new WR_XYZ(pt.X * factor, pt.Y * factor, pt.Z * factor); * WR_Vector wrX = GetUnitizedWR_Vector(pl.XAxis); * WR_Vector wrY = GetUnitizedWR_Vector(pl.YAxis); * WR_Vector wrZ = GetUnitizedWR_Vector(pl.ZAxis); * * WR_Plane wrPl = new WR_Plane(wrX, wrY, wrZ, wrXYZ); * WR_Restraint rest = new WR_Restraint(wrPl, rels[0], rels[1], rels[2], rels[3], rels[4], rels[5]); * * WR_INode node = new WR_Node3d(pt.X * factor, pt.Y * factor, pt.Z * factor, rest); * * * ///// OUTPUTS ///// * DA.SetData(0, node); */ }
public PxGhRigidDynamicBox(Plane plane, float length, float width, float height, Material material, float mass) { actor = PhysXManager.Physics.CreateRigidDynamic(); actor.CreateShape(new BoxGeometry(length * 0.5f, width * 0.5f, height * 0.5f), material); initialGlobalPose = actor.GlobalPose = plane.ToMatrix(); actor.UpdateMassAndInertia(mass); hX = length * 0.5; hY = width * 0.5; hZ = height * 0.5; }
/***************************************************/ public static RHG.Cone ToRhino(this BHG.Cone cone) { if (cone == null) { return(default(RHG.Cone)); } BHG.Vector axis = cone.Axis * -1.0; RHG.Plane plane = new RHG.Plane((cone.Centre + cone.Axis.Normalise() * cone.Height).ToRhino(), axis.ToRhino()); return(new RHG.Cone(plane, cone.Height, cone.Radius)); }
/***************************************************/ public static RHG.Cylinder ToRhino(this BHG.Cylinder cylinder) { if (cylinder == null) { return(default(RHG.Cylinder)); } RHG.Plane plane = new RHG.Plane(cylinder.Centre.ToRhino(), cylinder.Axis.ToRhino()); RHG.Circle circle = new RHG.Circle(plane, cylinder.Radius); return(new RHG.Cylinder(circle, cylinder.Height)); }
/// <summary> btnNewDwgPlane creates new drawing plane perpedicular to camera centered around chosed origin </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnNewDwgPlane_Click(object sender, EventArgs e) { Rhino.Geometry.Point3d pt1 = org; Rhino.Geometry.Transform move1 = Rhino.Geometry.Transform.Translation(view3.MainViewport.CameraX); Rhino.Geometry.Transform move2 = Rhino.Geometry.Transform.Translation(view3.MainViewport.CameraY); var xRev = view3.MainViewport.CameraX; var yRev = view3.MainViewport.CameraY; xRev.Reverse(); yRev.Reverse(); Rhino.Geometry.Transform move3 = Rhino.Geometry.Transform.Translation(xRev); Rhino.Geometry.Transform move4 = Rhino.Geometry.Transform.Translation(yRev); Rhino.Geometry.Point3d pt2 = org; Rhino.Geometry.Point3d pt3 = org; Rhino.Geometry.Point3d pt4 = org; Rhino.Geometry.Point3d pt5 = org; //Rhino.Geometry.Vector3d.l pt2.Transform(move1); pt2.Transform(move2); pt3.Transform(move3); pt3.Transform(move4); pt4.Transform(move1); pt4.Transform(move4); pt5.Transform(move3); pt5.Transform(move2); srf1 = Rhino.Geometry.NurbsSurface.CreateFromCorners(pt2, pt4, pt3, pt5); plane1 = new Plane(org, view3.MainViewport.CameraX, view3.MainViewport.CameraY); Rhino.Geometry.Transform scale1 = Rhino.Geometry.Transform.Scale(org, 400); srf1.Transform(scale1); mRhinoDoc.Objects.AddPoint(pt1); mRhinoDoc.Objects.AddPoint(pt2); mRhinoDoc.Objects.AddPoint(pt3); mRhinoDoc.Objects.AddPoint(pt4); mRhinoDoc.Objects.AddPoint(pt5); mRhinoDoc.Objects.AddSurface(srf1); mRhinoDoc.Views.Redraw(); }
public static Rhino.Commands.Result AddTorus(Rhino.RhinoDoc doc) { const double major_radius = 4.0; const double minor_radius = 2.0; Rhino.Geometry.Plane plane = Rhino.Geometry.Plane.WorldXY; Rhino.Geometry.Torus torus = new Rhino.Geometry.Torus(plane, major_radius, minor_radius); Rhino.Geometry.RevSurface revsrf = torus.ToRevSurface(); if (doc.Objects.AddSurface(revsrf) != Guid.Empty) { doc.Views.Redraw(); return(Rhino.Commands.Result.Success); } return(Rhino.Commands.Result.Failure); }
private Rhino.Geometry.PlaneSurface ToRhinoPlaneSurface(PlanarSurface planarSurface, Face face) { // From Topologic List <double> coefficients = planarSurface.Coefficients; double a = coefficients[0]; double b = coefficients[1]; double c = coefficients[2]; double d = coefficients[3]; Vertex faceCenterOfMass = face.CenterOfMass; Point3d ghFaceCenterOfMass = ToPoint(faceCenterOfMass); Rhino.Geometry.Plane ghPlane = new Rhino.Geometry.Plane(a, b, c, d); double occtXMin = planarSurface.XMin; double occtXMax = planarSurface.XMax; double occtAbsDeltaX = Math.Abs(occtXMax - occtXMin); double occtHalfDeltaX = occtAbsDeltaX / 2.0; double occtYMin = planarSurface.YMin; double occtYMax = planarSurface.YMax; double occtAbsDeltaY = Math.Abs(occtYMax - occtYMin); double occtHalfDeltaY = occtAbsDeltaY / 2.0; double ghXMin = occtXMin; // - occtHalfDeltaX - safetyMarginX; double ghXMax = occtXMax; // - occtHalfDeltaX + safetyMarginX; double ghYMin = occtYMin; // - occtHalfDeltaY - safetyMarginY; double ghYMax = occtYMax; // - occtHalfDeltaY + safetyMarginY; Interval xExtents = new Interval( ghXMin, ghXMax); Interval yExtents = new Interval( ghYMin, ghYMax); PlaneSurface ghPlaneSurface = new PlaneSurface(ghPlane, xExtents, yExtents); Point3d ghCentroid = Rhino.Geometry.AreaMassProperties.Compute(ghPlaneSurface).Centroid; Vector3d ghTranslationVector = ghFaceCenterOfMass - ghCentroid; ghPlaneSurface.Translate(ghTranslationVector); if (!ghPlaneSurface.IsValid) { throw new Exception("A valid surface cannot be created from this Face."); } return(ghPlaneSurface); }
public static Rhino.Commands.Result Maelstrom(Rhino.RhinoDoc doc) { ObjectType filter = SpaceMorphObjectFilter(); Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select object to maelstrom", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) { return(rc); } Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane(); double radius0 = Rhino.RhinoMath.UnsetValue; rc = Rhino.Input.RhinoGet.GetNumber("Starting radius", false, ref radius0); if (rc != Rhino.Commands.Result.Success || !Rhino.RhinoMath.IsValidDouble(radius0)) { return(rc); } double radius1 = Rhino.RhinoMath.UnsetValue; rc = Rhino.Input.RhinoGet.GetNumber("Ending radius", false, ref radius1); if (rc != Rhino.Commands.Result.Success || !Rhino.RhinoMath.IsValidDouble(radius1)) { return(rc); } double angle = Rhino.RhinoMath.UnsetValue; rc = Rhino.Input.RhinoGet.GetNumber("Twist angle in degrees", false, ref angle); if (rc != Rhino.Commands.Result.Success || !Rhino.RhinoMath.IsValidDouble(angle)) { return(rc); } Rhino.Geometry.Morphs.MaelstromSpaceMorph morph = new Rhino.Geometry.Morphs.MaelstromSpaceMorph(plane, radius0, radius1, Rhino.RhinoMath.ToRadians(angle)); Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate(); if (morph.Morph(geom)) { doc.Objects.Add(geom); doc.Views.Redraw(); } return(Rhino.Commands.Result.Success); }
/***************************************************/ public static RHG.Torus ToRhino(this BHG.Torus torus) { if (torus == null) { return(default(RHG.Torus)); } if (torus.RadiusMajor <= torus.RadiusMinor) { Reflection.Compute.RecordError("Major Radius less than or equal to Minor Radius. Conversion to Rhino Torus failed."); return(RHG.Torus.Unset); } RHG.Plane plane = new RHG.Plane(torus.Centre.ToRhino(), torus.Axis.ToRhino()); return(new RHG.Torus(plane, torus.RadiusMajor, torus.RadiusMinor)); }
Rhino.Geometry.Plane GetPlane(int which) { IntPtr pConstThis = ConstPointer(); Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(); if (!UnsafeNativeMethods.ON_Viewport_GetPlane(pConstThis, which, ref plane)) plane = Rhino.Geometry.Plane.Unset; return plane; }
/// <summary> RunCommandPickPlane is a helper method for picking an existing surface to draw on </summary> /// <param name="mRhinoDoc"></param> /// <param name="mode"></param> /// <returns></returns> protected Result RunCommandPickPlane(RhinoDoc mRhinoDoc, RunMode mode) { //routine for picking an existing surface to draw on //please select a plane Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Surface; Rhino.DocObjects.ObjRef objref = null; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select surface", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) return rc; Rhino.Geometry.Surface refSrf = objref.Surface(); refSrf.FrameAt(.5, .5, out plane1); Point3d pOrigin = refSrf.PointAt(1, 1); Point3d pY = refSrf.PointAt(0.5, 1); Point3d pX = refSrf.PointAt(1, 0.75); Vector3d vX = Rhino.Geometry.Point3d.Subtract(pX, pOrigin); Vector3d vY = Rhino.Geometry.Point3d.Subtract(pY, pOrigin); plane1 = new Plane(pOrigin, vX, vY); Rhino.DocObjects.RhinoObject rhobj = objref.Object(); rhobj.Select(false); mRhinoDoc.Objects.AddPoint(pOrigin); mRhinoDoc.Objects.AddPoint(pX); mRhinoDoc.Objects.AddPoint(pY); mRhinoDoc.Views.Redraw(); return Result.Success; }
public void mosek1(List<leaf> _listLeaf, List<branch> _listBranch, Dictionary<string, slice> _listSlice,Dictionary<string,range>_listRange,Dictionary<string,range>_listRangeOpen,Dictionary<string,range> _listRangeLeaf, bool obj, double allow, bool obj2) { // Since the value infinity is never used, we define // 'infinity' symbolic purposes only double infinity = 0; int[] csub = new int[3];// for cones int numvar = 0; int numcon = 0; foreach (var leaf in _listLeaf) { leaf.varOffset = numvar; leaf.conOffset = numcon; numvar += (leaf.nU * leaf.nV) + leaf.r * 4; //z,H11,H22,H12 mean curvature numcon += leaf.r * 4;// H11,H22,H12 if (obj) numvar += leaf.r * 3; //z,target_z, z-_z if (obj) numcon += leaf.r * 2; //z, z-target_z } foreach (var branch in _listBranch) { branch.varOffset = numvar; branch.conOffset = numcon; numvar += branch.N + branch.tuples.Count(); //z,D if (branch.branchType == branch.type.kink) { numcon += 2 * branch.N;//branch->left and right sides } else if (branch.branchType == branch.type.reinforce||branch.branchType==branch.type.open) { numcon += 1 * branch.N; //z=-ax-by-d numcon += 1 * branch.N; //branch->edge(target) } else//free { numcon += 1 * branch.N; //branch->edge(target) } numcon += branch.tuples.Count();// D(kink angle) } foreach (var slice in _listSlice.Values) { slice.varOffset = numvar; slice.conOffset = numcon; numvar += 3; //a,b,d if (slice.sliceType == slice.type.fx) { numcon++; } } if (obj) { numvar++; } //variable settings mosek.boundkey[] bkx = new mosek.boundkey[numvar]; double[] blx = new double[numvar]; double[] bux = new double[numvar]; foreach (var leaf in _listLeaf) { //z for (int i = 0; i < leaf.nU * leaf.nV; i++) { bkx[i + leaf.varOffset] = mosek.boundkey.fr; blx[i + leaf.varOffset] = -infinity; bux[i + leaf.varOffset] = infinity; } //H11,H22,H12 for (int i = 0; i < leaf.r; i++) { int n = i * 3 + (leaf.nU * leaf.nV); bkx[n + leaf.varOffset] = mosek.boundkey.fr; blx[n + leaf.varOffset] = -infinity; bux[n + leaf.varOffset] = infinity; bkx[n + 1 + leaf.varOffset] = mosek.boundkey.fr; blx[n + 1 + leaf.varOffset] = -infinity; bux[n + 1 + leaf.varOffset] = infinity; bkx[n + 2 + leaf.varOffset] = mosek.boundkey.fr; blx[n + 2 + leaf.varOffset] = -infinity; bux[n + 2 + leaf.varOffset] = infinity; } //later mean curvature will be added here // for (int i = 0; i < leaf.r; i++) { int n = i + leaf.r*3+(leaf.nU * leaf.nV); if (leaf.range.rangeType == range.type.lo) { bkx[n + leaf.varOffset] = mosek.boundkey.lo; blx[n + leaf.varOffset] = leaf.range.lb; bux[n + leaf.varOffset] = 0; } else if (leaf.range.rangeType == range.type.up) { bkx[n + leaf.varOffset] = mosek.boundkey.up; blx[n + leaf.varOffset] = 0; bux[n + leaf.varOffset] = leaf.range.ub; } else { bkx[n + leaf.varOffset] = mosek.boundkey.ra; blx[n + leaf.varOffset] = leaf.range.lb; bux[n + leaf.varOffset] = leaf.range.ub; } } //////////////// //target z if (obj) { //z for (int i = 0; i < leaf.r; i++) { bkx[i + (leaf.nU * leaf.nV) + 4 * leaf.r + leaf.varOffset] = mosek.boundkey.fr; blx[i + (leaf.nU * leaf.nV) + 4 * leaf.r + leaf.varOffset] = 0; bux[i + (leaf.nU * leaf.nV) + 4 * leaf.r + leaf.varOffset] = 0; } //target_z for (int i = 0; i < leaf.r; i++) { bkx[i + (leaf.nU * leaf.nV) + 5 * leaf.r + leaf.varOffset] = mosek.boundkey.fx; //reference multiquadric surface blx[i + (leaf.nU * leaf.nV) + 5 * leaf.r + leaf.varOffset] = globalFunc(leaf.tuples[i].x, leaf.tuples[i].y); bux[i + (leaf.nU * leaf.nV) + 5 * leaf.r + leaf.varOffset] = globalFunc(leaf.tuples[i].x, leaf.tuples[i].y); } //z-target_z for (int i = 0; i < leaf.r; i++) { bkx[i + (leaf.nU * leaf.nV) + 6 * leaf.r + leaf.varOffset] = mosek.boundkey.fr; blx[i + (leaf.nU * leaf.nV) + 6 * leaf.r + leaf.varOffset] = 0; bux[i + (leaf.nU * leaf.nV) + 6 * leaf.r + leaf.varOffset] = 0; } } } foreach(var branch in _listBranch) { if (branch.branchType == branch.type.reinforce ) { for (int i = 0; i < branch.N; i++) { bkx[i + branch.varOffset] = mosek.boundkey.fr; blx[i + branch.varOffset] = 0; bux[i + branch.varOffset] = 0; } //kink angle parameter for (int i = 0; i < branch.tuples.Count(); i++) { bkx[branch.N + i + branch.varOffset] = mosek.boundkey.lo; blx[branch.N + i + branch.varOffset] = 0.0; bux[branch.N + i + branch.varOffset] = 0; } } else if (branch.branchType == branch.type.open) { for (int i = 0; i < branch.N; i++) { bkx[i + branch.varOffset] = mosek.boundkey.fr; blx[i + branch.varOffset] = 0; bux[i + branch.varOffset] = 0; } //kink angle parameter for (int i = 0; i < branch.tuples.Count(); i++) { if (branch.range.rangeType == range.type.lo) { bkx[branch.N + i + branch.varOffset] = mosek.boundkey.lo; blx[branch.N + i + branch.varOffset] = branch.range.lb; bux[branch.N + i + branch.varOffset] = 0; } else if (branch.range.rangeType == range.type.up) { bkx[branch.N + i + branch.varOffset] = mosek.boundkey.up; blx[branch.N + i + branch.varOffset] = 0; bux[branch.N + i + branch.varOffset] = branch.range.ub; } else { bkx[branch.N + i + branch.varOffset] = mosek.boundkey.ra; blx[branch.N + i + branch.varOffset] = branch.range.lb; bux[branch.N + i + branch.varOffset] = branch.range.ub; } //bkx[branch.N + i + branch.varOffset] = mosek.boundkey.ra; //blx[branch.N + i + branch.varOffset] = 0; //bux[branch.N + i + branch.varOffset] = 0; } } else if (branch.branchType == branch.type.kink) { for (int i = 0; i < branch.N; i++) { bkx[i + branch.varOffset] = mosek.boundkey.fr; blx[i + branch.varOffset] = -infinity; bux[i + branch.varOffset] = infinity; } //kink angle parameter for (int i = 0; i < branch.tuples.Count(); i++) { if (branch.range.rangeType == range.type.lo) { bkx[branch.N + i + branch.varOffset] = mosek.boundkey.lo; blx[branch.N + i + branch.varOffset] = branch.range.lb; bux[branch.N + i + branch.varOffset] = 0; } else if(branch.range.rangeType == range.type.up) { bkx[branch.N + i + branch.varOffset] = mosek.boundkey.up; blx[branch.N + i + branch.varOffset] = 0; bux[branch.N + i + branch.varOffset] = branch.range.ub; } else { bkx[branch.N + i + branch.varOffset] = mosek.boundkey.ra; blx[branch.N + i + branch.varOffset] = branch.range.lb; bux[branch.N + i + branch.varOffset] = branch.range.ub; } } } else//free { for (int i = 0; i < branch.N; i++) { bkx[i + branch.varOffset] = mosek.boundkey.fr; blx[i + branch.varOffset] = -infinity; bux[i + branch.varOffset] = infinity; } //kink angle parameter for (int i = 0; i < branch.tuples.Count(); i++) { bkx[branch.N + i + branch.varOffset] = mosek.boundkey.fr; blx[branch.N + i + branch.varOffset] = -infinity; bux[branch.N + i + branch.varOffset] = infinity; } } } foreach (var slice in _listSlice.Values) { if (slice.sliceType == slice.type.fx) { //add something! bkx[slice.varOffset] = mosek.boundkey.fx; blx[slice.varOffset] = slice.a; bux[slice.varOffset] = slice.a; bkx[slice.varOffset + 1] = mosek.boundkey.fx; blx[slice.varOffset + 1] = slice.b; bux[slice.varOffset + 1] = slice.b; bkx[slice.varOffset + 2] = mosek.boundkey.fx; blx[slice.varOffset + 2] = slice.d; bux[slice.varOffset + 2] = slice.d; } else { bkx[slice.varOffset] = mosek.boundkey.fr; blx[slice.varOffset] = -infinity; bux[slice.varOffset] = infinity; bkx[slice.varOffset + 1] = mosek.boundkey.fr; blx[slice.varOffset + 1] = -infinity; bux[slice.varOffset + 1] = infinity; bkx[slice.varOffset + 2] = mosek.boundkey.fr; blx[slice.varOffset + 2] = -infinity; bux[slice.varOffset + 2] = infinity; } } if (obj) { bkx[numvar - 1] = mosek.boundkey.fx; blx[numvar - 1] = allow; bux[numvar - 1] = allow; //bkx[numvar - 1] = mosek.boundkey.fr; //blx[numvar - 1] = -infinity; //bux[numvar - 1] = infinity; } // Make mosek environment. using (mosek.Env env = new mosek.Env()) { // Create a task object. using (mosek.Task task = new mosek.Task(env, 0, 0)) { // Directs the log task stream to the user specified // method msgclass.streamCB task.set_Stream(mosek.streamtype.log, new msgclass("")); /* Append 'numcon' empty constraints. The constraints will initially have no bounds. */ task.appendcons(numcon); /* Append 'numvar' variables. The variables will initially be fixed at zero (x=0). */ task.appendvars(numvar); for (int j = 0; j < numvar; ++j) { task.putvarbound(j, bkx[j], blx[j], bux[j]); } double root2 = Math.Sqrt(2); foreach (var leaf in listLeaf) { double[] grad = new double[leaf.tuples[0].nNode]; double[] grad0 = new double[leaf.tuples[0].nNode]; double[] grad1i = new double[leaf.tuples[0].nNode]; double[] grad1j = new double[leaf.tuples[0].nNode]; //define H11,H12,H22 for (int i = 0; i < leaf.r; i++) { int N11 = i * 3; //condition number int N22 = i * 3 + 1; int N12 = i * 3 + 2; int target = i * 3 + (leaf.nU * leaf.nV) + leaf.varOffset; //variable number task.putaij(N11+leaf.conOffset, target, -1); task.putconbound(N11 + leaf.conOffset, mosek.boundkey.fx, 0, 0); task.putaij(N22 + leaf.conOffset, target + 1, -1); task.putconbound(N22 + leaf.conOffset, mosek.boundkey.fx, 0, 0); task.putaij(N12 + leaf.conOffset, target + 2, -1); task.putconbound(N12 + leaf.conOffset, mosek.boundkey.fx, 0, 0); //N11 leaf.tuples[i].d2[0, 0].CopyTo(grad, 0); leaf.tuples[i].d0.CopyTo(grad0, 0); leaf.tuples[i].d1[0].CopyTo(grad1i, 0); leaf.tuples[i].d1[0].CopyTo(grad1j, 0); for (int k = 0; k < leaf.tuples[i].nNode; k++) { for (int j = 0; j < leaf.tuples[i].elemDim; j++) { grad[k] -= leaf.tuples[i].Gammaijk[0, 0, j] * leaf.tuples[i].d1[j][k]; } double val = 0; val += grad[k]; task.putaij(N11 + leaf.conOffset, leaf.tuples[i].internalIndex[k] + leaf.varOffset, -val / root2); } //N22 leaf.tuples[i].d2[1, 1].CopyTo(grad, 0); leaf.tuples[i].d0.CopyTo(grad0, 0); leaf.tuples[i].d1[1].CopyTo(grad1i, 0); leaf.tuples[i].d1[1].CopyTo(grad1j, 0); for (int k = 0; k < leaf.tuples[i].nNode; k++) { for (int j = 0; j < leaf.tuples[i].elemDim; j++) { grad[k] -= leaf.tuples[i].Gammaijk[1, 1, j] * leaf.tuples[i].d1[j][k]; } double val = 0; val += grad[k]; task.putaij(N22 + leaf.conOffset, leaf.tuples[i].internalIndex[k] + leaf.varOffset, -val / root2); } //N12 leaf.tuples[i].d2[0, 1].CopyTo(grad, 0); leaf.tuples[i].d0.CopyTo(grad0, 0); leaf.tuples[i].d1[0].CopyTo(grad1i, 0); leaf.tuples[i].d1[1].CopyTo(grad1j, 0); for (int k = 0; k < leaf.tuples[i].nNode; k++) { for (int j = 0; j < leaf.tuples[i].elemDim; j++) { grad[k] -= leaf.tuples[i].Gammaijk[0, 1, j] * leaf.tuples[i].d1[j][k]; } double val = 0; val += grad[k]; task.putaij(N12 + leaf.conOffset, leaf.tuples[i].internalIndex[k] + leaf.varOffset, -val); } } // mean curvature will be added here // // for (int i = 0; i < leaf.r; i++) { int target = i * 3 + (leaf.nU * leaf.nV) + leaf.varOffset; //variable number int target2 = i + leaf.r*3+(leaf.nU * leaf.nV) + leaf.varOffset; //variable number int NH= leaf.r*3+i; //condition number task.putaij(NH + leaf.conOffset, target, 1); task.putaij(NH + leaf.conOffset, target + 1, 1); task.putaij(NH + leaf.conOffset, target2, -1); task.putconbound(NH+leaf.conOffset, mosek.boundkey.fx, 0, 0); } //if (leaf.leafType == leaf.type.convex) for (int i = 0; i < leaf.r; i++) { int N11 = i * 3 + (leaf.nU * leaf.nV); //variable number int N22 = i * 3 + 1 + (leaf.nU * leaf.nV); int N12 = i * 3 + 2 + (leaf.nU * leaf.nV); csub[0] = N11 + leaf.varOffset; csub[1] = N22 + leaf.varOffset; csub[2] = N12 + leaf.varOffset; task.appendcone(mosek.conetype.rquad, 0.0, // For future use only, can be set to 0.0 csub); /*if (obj2) { task.putcj(N11, leaf.tuples[i].Gij[0, 0]); task.putcj(N22, leaf.tuples[i].Gij[1, 1]); task.putcj(N12, 2*leaf.tuples[i].Gij[0, 1]); }*/ } if (obj) { double[] grad00 = new double[leaf.tuples[0].nNode]; for (int i = 0; i < leaf.r; i++) { leaf.tuples[i].d0.CopyTo(grad00, 0); for (int k = 0; k < leaf.tuples[i].nNode; k++) { task.putaij(leaf.conOffset + leaf.r * 4 + i, leaf.varOffset + leaf.tuples[i].internalIndex[k], grad00[k]); } task.putaij(leaf.conOffset + leaf.r * 4 + i, leaf.varOffset + leaf.nU*leaf.nV+leaf.r*4+i,-1); task.putconbound(leaf.conOffset + leaf.r * 4 + i, mosek.boundkey.fx, 0, 0); } for (int i = 0; i < leaf.tuples.Count(); i++) { task.putaij(leaf.conOffset + leaf.r * 5 + i, leaf.varOffset + leaf.nU * leaf.nV + leaf.r * 4 + i, 1); task.putaij(leaf.conOffset + leaf.r * 5 + i, leaf.varOffset + leaf.nU * leaf.nV + leaf.r * 5 + i, -1); task.putaij(leaf.conOffset + leaf.r * 5 + i, leaf.varOffset + leaf.nU * leaf.nV + leaf.r * 6 + i, -1); task.putconbound(leaf.conOffset + leaf.r * 5 + i, mosek.boundkey.fx, 0, 0); } } } if (obj) { List<int> dsub=new List<int>(); dsub.Add(numvar-1); foreach (var leaf in _listLeaf) { for (int i = 0; i < leaf.r; i++) { dsub.Add(leaf.varOffset + leaf.nU * leaf.nV + leaf.r * 6 + i); } } task.appendcone(mosek.conetype.quad, 0.0, dsub.ToArray()); } foreach (var branch in _listBranch) { if (branch.branchType == branch.type.kink) { tieBranchD1(branch, branch.left, task, 2, 0); tieBranchD1(branch, branch.right, task, 2, 1); defineKinkAngle2(branch,branch.left,branch.right,task, branch.conOffset + branch.N*2, branch.varOffset + branch.N); /*if (branch.obj) { for (int i = 0; i < branch.tuples.Count(); i++) { task.putcj(branch.N + i + branch.varOffset, 1); } }*/ } else if (branch.branchType == branch.type.reinforce || branch.branchType == branch.type.open) { int iA = _listSlice[branch.sliceKey].varOffset; int iB = _listSlice[branch.sliceKey].varOffset + 1; int iD = _listSlice[branch.sliceKey].varOffset + 2; //height parameter for (int i = 0; i < branch.N; i++) { double x = branch.crv.Points[i].Location.X; double y = branch.crv.Points[i].Location.Y; task.putconbound(branch.conOffset + branch.N + branch.tuples.Count() + i, mosek.boundkey.fx, 0, 0); task.putaij(branch.conOffset + branch.N + branch.tuples.Count() + i, branch.varOffset + i, 1);//z task.putaij(branch.conOffset + branch.N + branch.tuples.Count() + i, iA, x);//ax task.putaij(branch.conOffset + branch.N + branch.tuples.Count() + i, iB, y);//by task.putaij(branch.conOffset + branch.N + branch.tuples.Count() + i, iD, 1);//d } tieBranchD1(branch, branch.target, task, 1, 0); defineKinkAngleC(branch, branch.target, task, branch.conOffset + branch.N, branch.varOffset + branch.N); } else { tieBranchD1(branch, branch.target, task, 1, 0); defineKinkAngle(branch,branch.target, task, branch.conOffset + branch.N, branch.varOffset + branch.N); } } //task.putcj(numvar - 1, 1); task.putintparam(mosek.iparam.intpnt_max_iterations, 200000000);//20000000 task.putintparam(mosek.iparam.intpnt_solve_form, mosek.solveform.dual); task.putobjsense(mosek.objsense.minimize); //task.writedata("c:/out/mosek_task_dump.opf"); task.optimize(); // Print a summary containing information // about the solution for debugging purposes task.solutionsummary(mosek.streamtype.msg); mosek.solsta solsta; /* Get status information about the solution */ task.getsolsta(mosek.soltype.itr, out solsta); double[] xx = new double[numvar]; task.getxx(mosek.soltype.itr, // Basic solution. xx); switch (solsta) { case mosek.solsta.optimal: System.Windows.Forms.MessageBox.Show("Optimal primal solution\n"); break; case mosek.solsta.near_optimal: System.Windows.Forms.MessageBox.Show("Near Optimal primal solution\n"); break; case mosek.solsta.dual_infeas_cer: case mosek.solsta.prim_infeas_cer: case mosek.solsta.near_dual_infeas_cer: case mosek.solsta.near_prim_infeas_cer: Console.WriteLine("Primal or dual infeasibility.\n"); break; case mosek.solsta.unknown: System.Windows.Forms.MessageBox.Show("Unknown solution status\n"); break; default: System.Windows.Forms.MessageBox.Show("Other solution status\n"); break; } //store airy potential System.Windows.Forms.MessageBox.Show(string.Format("error={0}", xx[numvar - 1])); foreach (var leaf in listLeaf) { double[] x = new double[leaf.nU * leaf.nV]; for (int j = 0; j < leaf.nV; j++) { for (int i = 0; i < leaf.nU; i++) { x[i + j * leaf.nU] = xx[i + j * leaf.nU + leaf.varOffset]; } } leaf.myMasonry.setupAiryPotentialFromList(x); } foreach (var leaf in listLeaf) { foreach (var tup in leaf.tuples) { leaf.myMasonry.elemList[tup.index].computeStressFunction(tup); } } foreach (var branch in _listBranch) { double[] x = new double[branch.N]; for (int i = 0; i < branch.N; i++) { x[i] = xx[i + branch.varOffset]; } branch.myArch.setupAiryPotentialFromList(x); } foreach (var slice in _listSlice.Values) { slice.a = xx[slice.varOffset]; slice.b = xx[slice.varOffset + 1]; slice.d = xx[slice.varOffset + 2]; double norm = Math.Sqrt(slice.a * slice.a + slice.b * slice.b + 1); var pl = new Rhino.Geometry.Plane(slice.a, slice.b, 1d, slice.d / norm); slice.update(pl); } foreach (var branch in listBranch) { foreach (var tup in branch.tuples) { if (branch.branchType == branch.type.kink) { branch.left.myMasonry.elemList[tup.left.index].computeTangent(tup.left); branch.right.myMasonry.elemList[tup.right.index].computeTangent(tup.right); } else if (branch.branchType == branch.type.fix) { branch.target.myMasonry.elemList[tup.target.index].computeTangent(tup.target); } else { branch.target.myMasonry.elemList[tup.target.index].computeTangent(tup.target); var vars = branch.slice.pl.GetPlaneEquation(); branch.target.myMasonry.elemList[tup.target.index].computeTangent(tup.target, vars[0], vars[1], vars[2], vars[3]); //valDc } } } foreach (var leaf in _listLeaf) { for (int i = 0; i < leaf.r; i++) { int target = i + leaf.r*3+(leaf.nU * leaf.nV) + leaf.varOffset; leaf.tuples[i].NH = xx[target]; } } foreach (var branch in _listBranch) { branch.airyCrv = branch.crv.Duplicate() as NurbsCurve; for (int j = 0; j < branch.N; j++) { var P = branch.crv.Points[j]; branch.airyCrv.Points.SetPoint(j, new Point3d(P.Location.X, P.Location.Y, xx[j + branch.varOffset])); } for (int i = 0; i < branch.tuples.Count(); i++) { //branch.tuples[i].z = branch.airyCrv.PointAt(branch.tuples[i].t).Z; //int D = i + branch.N; if (branch.branchType == branch.type.open) { branch.tuples[i].H[0, 0] = branch.tuples[i].target.valD - branch.tuples[i].target.valDc; } else if (branch.branchType == branch.type.reinforce) { branch.tuples[i].H[0, 0] = branch.tuples[i].target.valD - branch.tuples[i].target.valDc; } else if (branch.branchType == branch.type.fix) { branch.tuples[i].H[0, 0] = 0; } else { //afterwards, check why these two values do not match. //branch.tuples[i].H[0, 0] = branch.tuples[i].left.valD + branch.tuples[i].right.valD; branch.tuples[i].H[0, 0] = xx[branch.N + i + branch.varOffset]; } } } foreach (var range in _listRangeLeaf.Values) { double min = 10000d, max = -10000d; foreach (var leaf in range.lL) { for (int i = 0; i < leaf.tuples.Count(); i++) { if (leaf.tuples[i].NH > max) max = leaf.tuples[i].NH; if (leaf.tuples[i].NH < min) min = leaf.tuples[i].NH; } } range.lastMin = min; range.lastMax = max; range.firstPathDone = true; } foreach (var range in _listRange.Values) { double min=10000d,max=-10000d; foreach (var branch in range.lB) { for(int i=0;i<branch.tuples.Count();i++) { if (branch.tuples[i].H[0, 0] > max) max = branch.tuples[i].H[0, 0]; if (branch.tuples[i].H[0, 0] < min) min = branch.tuples[i].H[0, 0]; } } range.lastMin = min; range.lastMax = max; range.firstPathDone = true; } foreach (var range in _listRangeOpen.Values) { double min = 10000d, max = -10000d; foreach (var branch in range.lB) { for (int i = 0; i < branch.tuples.Count(); i++) { if (branch.tuples[i].H[0, 0] > max) max = branch.tuples[i].H[0, 0]; if (branch.tuples[i].H[0, 0] < min) min = branch.tuples[i].H[0, 0]; } } range.lastMin = min; range.lastMax = max; range.firstPathDone = true; } foreach (var leaf in _listLeaf) { leaf.airySrf = leaf.srf.Duplicate() as NurbsSurface; for (int j = 0; j < leaf.nV; j++) { for (int i = 0; i < leaf.nU; i++) { var P = leaf.srf.Points.GetControlPoint(i, j); leaf.airySrf.Points.SetControlPoint(i, j, new ControlPoint(P.Location.X, P.Location.Y, xx[i + j * leaf.nU + leaf.varOffset])); } } } } } }
protected override void SolveInstance(IGH_DataAccess DA) { ///// INPUTS ///// Point3d pt = Point3d.Unset; List<bool> rels = new List<bool>(); Plane pl = Plane.Unset; if (!DA.GetData(0, ref pt)) { return; } if (!DA.GetDataList<bool>(1, rels)) { //Set as unrestrained if no release information is provided for (int i = 0; i < 6; i++) { rels.Add(false); } } if (rels.Count != 6) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Number of bools in input should be 6"); return; } if (!DA.GetData(2, ref pl)) { // If no plane submitted, use global XY plane pl = new Rhino.Geometry.Plane(new Rhino.Geometry.Point3d(0,0,0), new Rhino.Geometry.Vector3d(1,0,0), new Rhino.Geometry.Vector3d(0,1,0)); } ///// SOLVE ///// double factor = Utilities.GetScalingFactorFromRhino(); WR_XYZ wrXYZ = new WR_XYZ(pt.X * factor, pt.Y * factor, pt.Z * factor); WR_Vector wrX = GetUnitizedWR_Vector(pl.XAxis); WR_Vector wrY = GetUnitizedWR_Vector(pl.YAxis); WR_Vector wrZ = GetUnitizedWR_Vector(pl.ZAxis); WR_Plane wrPl = new WR_Plane(wrX, wrY, wrZ, wrXYZ); WR_Restraint rest = new WR_Restraint(wrPl, rels[0], rels[1], rels[2], rels[3], rels[4], rels[5]); WR_INode node = new WR_Node3d(pt.X * factor, pt.Y * factor, pt.Z * factor, rest); ///// OUTPUTS ///// DA.SetData(0, node); }