// center and radius of each circle is random public PackCircles(Point3d basePoint, int circleCount, double minRadius, double maxRadius) { m_base = new Point3d(basePoint); m_circles = new PackingCircle[circleCount]; Random rnd = new Random(); for( int i=0; i<circleCount; i++) { Point3d center = new Point3d(m_base.X + rnd.NextDouble() * minRadius, m_base.Y + rnd.NextDouble() * minRadius, m_base.Z); double radius = minRadius + rnd.NextDouble() * (maxRadius - minRadius); m_circles[i] = new PackingCircle(center, radius); } DestroyBoundingBoxCache(); Rhino.Display.DisplayPipeline.CalculateBoundingBox += DisplayPipeline_CalculateBoundingBox; Rhino.Display.DisplayPipeline.PostDrawObjects += DisplayPipeline_PostDrawObjects; }
// center and radius of each circle is random public PackCircles(Point3d basePoint, int circleCount, double minRadius, double maxRadius) { m_base = new Point3d(basePoint); m_circles = new PackingCircle[circleCount]; Random rnd = new Random(); for (int i = 0; i < circleCount; i++) { Point3d center = new Point3d(m_base.X + rnd.NextDouble() * minRadius, m_base.Y + rnd.NextDouble() * minRadius, m_base.Z); double radius = minRadius + rnd.NextDouble() * (maxRadius - minRadius); m_circles[i] = new PackingCircle(center, radius); } DestroyBoundingBoxCache(); Rhino.Display.DisplayPipeline.CalculateBoundingBox += DisplayPipeline_CalculateBoundingBox; Rhino.Display.DisplayPipeline.PostDrawObjects += DisplayPipeline_PostDrawObjects; }
//Compare this circle to another circle and move this circle in case of an overlap public bool FastPack(PackingCircle other, double tolerance) { Point3d a = this.Center; Point3d b = other.Center; double d = (a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y); double r = m_circle.Radius + other.m_circle.Radius; if (d < ((r * r) - 0.01 * tolerance)) { //If the above line evaluates to TRUE, we have an overlap Vector3d v = new Vector3d(a.X - b.X, a.Y - b.Y, 0); v.Unitize(); v *= (r - Math.Sqrt(d)); Translate(v); InMotion = true; return(true); } return(false); }
//Compare this circle to another circle and move this circle in case of an overlap public bool FastPack(PackingCircle other, double tolerance) { Point3d a = this.Center; Point3d b = other.Center; double d = (a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y); double r = m_circle.Radius + other.m_circle.Radius; if (d < ((r * r) - 0.01 * tolerance)) { //If the above line evaluates to TRUE, we have an overlap Vector3d v = new Vector3d(a.X - b.X, a.Y - b.Y, 0); v.Unitize(); v *= (r - Math.Sqrt(d)); Translate(v); InMotion = true; return true; } return false; }