A very basic question. I just forgot. I did it 8 years ago in Rhino 3 and 4
In between I did not use it at all.
I have created bounding box which looks perfectly fit on plane I have wanted. But when I am transforming it, the bounding box is changing itās shape.
I wanted to create the minimum sized bounding box , which is created at zero, zero xy plane. Then when I transform back to the object orientation plane, the bounding box change shape. I want a bounding box, which is minimum is size and on the position on object orientation plane, not on origin(0,0,0) xy plane.
here object orientation plane is pln_c.
using System;
using System.Collections.Generic;
using Grasshopper.Kernel;
using Rhino.Geometry;
// In order to load the result of this wizard, you will also need to
// add the output bin/ folder of this project to the list of loaded
// folder in Grasshopper.
// You can use the _GrasshopperDeveloperSettings Rhino command for that.
namespace PLANNER_BEAM_BOUNDING_BOX_GH6
{
public class PLANNER_BEAM_BOUNDING_BOX_GH6Component : GH_Component
{
public PLANNER_BEAM_BOUNDING_BOX_GH6Component()
: base("PLANNER_BEAM_BOUNDING_BOX_GH6", "PLANNER_BEAM_BOUNDING_BOX_GH6",
"PLANNER_BEAM_BOUNDING_BOX_GH6",
"Taiyuan_Domes", "SEAM_STUDY")
{
}
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddCurveParameter("Curves_PLANNER_BEAM", "Curves_PLANNER_BEAM", "Curves_PLANNER_BEAM", GH_ParamAccess.list);
pManager.AddBrepParameter("Breps_beams", "Breps_beams", "Breps_beams", GH_ParamAccess.list);
pManager.AddSurfaceParameter("DOME_SURFACE", "DOME_SURFACE", "DOME_SURFACE", GH_ParamAccess.item);
}
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddBrepParameter("Bounding_boxes_for_beams", "Bounding_boxes_for_beams", "Bounding_boxes_for_beams", GH_ParamAccess.list);
}
protected override void SolveInstance(IGH_DataAccess DA)
{
List<Curve> _crv_list_ = new List<Curve>();
List<Brep> _brp_list_ = new List<Brep>();
List<Brep> _brp_list_bbox = new List<Brep>();
if (!DA.GetDataList(0, _crv_list_)) return;
if (_crv_list_.Count < 1)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "count curve must have a value of 1 or higher");
return;
}
//------------------------------------------------------------//
if (!DA.GetDataList(1, _brp_list_)) return;
if (_brp_list_.Count < 1)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "count curve must have a value of 1 or higher");
return;
}
Surface srf = null;
if (!DA.GetData("DOME_SURFACE", ref srf)) return;
//-------------------------------------------------------------//
for (int i= 0;i< _crv_list_.Count;i++ )
{
double t1 = 0.0;
double t2 = 0.0;
//---------------------------------------------------------//
srf.ClosestPoint(_crv_list_[i].PointAtEnd, out t1, out t2);
Vector3d normal_srf = new Vector3d();
normal_srf = srf.NormalAt(t1, t2);
Vector3d crv_dr = new Vector3d((Vector3d)_crv_list_[i].PointAtStart - (Vector3d)_crv_list_[i].PointAtEnd);
Vector3d crv_dr_cross = new Vector3d();
crv_dr_cross = Vector3d.CrossProduct(normal_srf, crv_dr);
Plane pln_c = new Plane(_crv_list_[i].PointAtEnd, crv_dr, crv_dr_cross);
BoundingBox bbox = new BoundingBox();
bbox= _brp_list_[i].GetBoundingBox(pln_c);
bbox.Transform(Transform.PlaneToPlane(Plane.WorldXY, pln_c));
//----------------------------------------------------------//
_brp_list_bbox.Add(bbox.ToBrep());
}
DA.SetDataList(0, _brp_list_bbox);
}
//-------------------------------------------------------------//
protected override System.Drawing.Bitmap Icon
{
get
{
// You can add image files to your project resources and access them like this:
return Properties.Resources.BBOX_ICON_icon;
//return null;
}
}
//-------------------------------------------------------------//
public override Guid ComponentGuid
{
get { return new Guid("261ae48e-5d5a-4e6a-a271-0db3c683b1a6"); }
}
}
}