design1.ActiveViewport.DisplayMode = displayType.Shaded;
design1.Shaded.EdgeColorMethod = edgeColorMethodType.EntityColor;
design1.Shaded.EdgeThickness = 2;
// parameters
double trimTol = 0.001;
double filletTol = 0.001;
double offsetTol = 0.1;
double offsetAmount = -1;
// creates the lists of the components of the hairdryer
List<Entity> whiteEntList = new List<Entity>();
List<Entity> darkEntList = new List<Entity>();
List<Entity> offsetEntList = new List<Entity>();
// body -------------------------
Surface s1 = DrawBody();
whiteEntList.Add(s1);
// body closure
Arc a5 = new Arc(80, 0, 0, 110, Math.PI, 1.11 * Math.PI);
Surface s7 = a5.RevolveAsSurface(Math.PI, Math.PI, Vector3D.AxisX, Point3D.Origin)[0];
whiteEntList.Add(s7);
// fillet
Surface[] f1;
Surface.Fillet(s1, s7, 5, filletTol, true, true, true, true, true, false, out f1);
whiteEntList.AddRange(f1);
// air vents
Arc ff = new Arc(Plane.YZ, new Point3D(0, 0, 0), 5.2, 0, Math.PI);
devDept.Eyeshot.Entities.Region r1 = new devDept.Eyeshot.Entities.Region(ff, Plane.YZ, false);
Surface[] AirVent1 = r1.ExtrudeAsSurface(-31 * Vector3D.AxisX);
Surface.Trim(AirVent1, new Surface[] { s7 }, 0.01, false, false);
CreateAndCutAirVent(-0.5, 5.7, 11.9, 0, Math.PI / 2, s7);
CreateAndCutAirVent(-0.5, 11.9, 18.1, 0, Math.PI / 2, s7);
CreateAndCutAirVent(-0.5, 18.1, 24.3, 0, Math.PI / 4, s7);
CreateAndCutAirVent(-0.5, 18.1, 24.3, Math.PI / 4, Math.PI / 2, s7);
CreateAndCutAirVent(-0.5, 24.3, 30.5, 0, Math.PI / 4, s7);
CreateAndCutAirVent(-0.5, 24.3, 30.5, Math.PI / 4, Math.PI / 2, s7);
double len1 = 150;
double ang1 = -Math.PI / 2.8;
// back
Arc a1 = new Arc(Plane.YZ, new Point2D(22, 0), 50, 4 * Math.PI / 5, Math.PI);
Surface s2 = a1.ExtrudeAsSurface(len1, 0, 0)[0];
s2.Rotate(ang1, Vector3D.AxisZ);
whiteEntList.Add(s2);
// front
Arc a2 = new Arc(Plane.YZ, new Point2D(-30, 0), 30, 0, Math.PI / 5);
Arc a3 = new Arc(Plane.YZ, new Point2D(-15, -40), 60, 9 * Math.PI / 20, 12 * Math.PI / 20);
Arc a4;
Curve.Fillet(a2, a3, 10, false, false, true, true, out a4);
CompositeCurve cc1 = new CompositeCurve(new ICurve[] { a2, a4, a3 });
Surface s3 = cc1.ExtrudeAsSurface(len1, 0, 0)[0];
s3.Rotate(ang1, Vector3D.AxisZ);
whiteEntList.Add(s3);
// bottom
Line ln3 = new Line(0, -125, 100, -125);
s2.Regen(0.1);
Surface s6 = ln3.ExtrudeAsSurface(new Vector3D(0, 0, s2.BoxMax.Z), devDept.Geometry.Utility.DegToRad(2), trimTol)[0];
whiteEntList.Add(s6);
// fillets
Surface[] f2, f3, f4;
// rear fillet
Surface.Fillet(new Surface[] { s2 }, new Surface[] { s6 }, 10, filletTol, true, true, true, true, true, false, out f2);
whiteEntList.AddRange(f2);
f2[0].TrimBy(new Plane(-1 * Vector3D.AxisZ), trimTol);
// along handle fillet
Surface.Fillet(new Surface[] { s3 }, new Surface[] { s2, s6, f2[0] }, 5, filletTol, true, true, true, true, true, false, out f3);
whiteEntList.AddRange(f3);
f3[4].TrimBy(new Plane(-1 * Vector3D.AxisZ), trimTol);
// handle-body fillet
Surface.Fillet(new Surface[] { s1 }, new Surface[] { s3, s2, s6, f2[0], f3[0] }, 10, filletTol, false, false, true, true, true, false, out f4);
foreach (Surface surface in f4)
{
surface.ReverseU();
}
whiteEntList.AddRange(f4);
// nozzle
Surface s8 = DrawNozzle(trimTol);
darkEntList.Add(s8);
// offset
offsetEntList.AddRange(OffsetSurfaces(offsetAmount, offsetTol, whiteEntList));
offsetEntList.AddRange(OffsetSurfaces(offsetAmount, offsetTol, darkEntList));
// mirror
Mirror m = new Mirror(Plane.XY);
MirrorEntities(m, whiteEntList);
MirrorEntities(m, darkEntList);
MirrorEntities(m, offsetEntList);
// adds to 3D scene
design1.Entities.AddRange(whiteEntList, Color.WhiteSmoke);
design1.Entities.AddRange(darkEntList, Color.FromArgb(31, 31, 31));
design1.Entities.AddRange(offsetEntList, Color.DarkGray);
Utility methods used to create the components of the hair dryer
private static Surface DrawNozzle(double trimTol)
{
Arc a1 = new Arc(Plane.YZ, Point2D.Origin, 30, 0, Math.PI);
a1.Translate(81, 0, 0);
Curve a2 = new Arc(Plane.YZ, Point2D.Origin, 27, 0, Math.PI).GetNurbsForm();
a2.Scale(1, 1, 1.15);
a2.Translate(81 + 10, 0, 0);
Curve a3 = new Arc(Plane.YZ, Point2D.Origin, 34, 0, Math.PI).GetNurbsForm();
a3.Scale(1, .5, 1);
a3.Translate(81 + 30, 0, 0);
Curve a4 = new Arc(Plane.YZ, Point2D.Origin, 34, 0, Math.PI).GetNurbsForm();
a4.Scale(1, .5, 1);
a4.Translate(81 + 40, 0, 0);
Surface s1 = Surface.Loft(new ICurve[] { a1, a2, a3, a4 }, 3)[0];
s1.ReverseU();
Arc a5 = new Arc(Plane.ZX, Point2D.Origin, 120, 0, Math.PI);
a5.Translate(0, -20, 0);
Surface s2 = a5.ExtrudeAsSurface(0, 40, 0)[0];
s1.TrimBy(s2, trimTol, false);
return s1;
}
private static Surface DrawBody()
{
// simple
Line ln1 = new Line(-30, 32, 80, 32);
Surface s1 = ln1.RevolveAsSurface(0, Math.PI, Vector3D.AxisX, Point3D.Origin)[0];
// advanced
Arc a1 = new Arc(Plane.YZ, Point2D.Origin, 32, 0, Math.PI);
a1.Translate(-30, 0, 0);
Arc a2 = new Arc(Plane.YZ, Point2D.Origin, 35, 0, Math.PI);
a2.Translate(-20, 0, 0);
Arc a3 = new Arc(Plane.YZ, Point2D.Origin, 36, 0, Math.PI);
a3.Translate(30, 0, 0);
Arc a4 = new Arc(Plane.YZ, Point2D.Origin, 30, 0, Math.PI);
a4.Translate(80, 0, 0);
s1 = Surface.Loft(new ICurve[] { a1, a2, a3, a4 }, 3)[0];
s1.ReverseU();
return s1;
}
Utility functions
private static Entity[] OffsetSurfaces(double amount, double tol, IList<Entity> whiteEntList)
{
List<Entity> offSurf = new List<Entity>();
for (int i = 0; i < whiteEntList.Count; i++)
{
Entity entity = whiteEntList[i];
if (entity is Surface)
{
Surface surf = (Surface)entity;
Surface offset;
if (surf.Offset(amount, tol, out offset))
offSurf.Add(offset);
}
}
return offSurf.ToArray();
}
/// <summary>
/// This function creates an air vent with defined internal and external radius and cuts it from the provided surface. The rotation angle determines the air vent's orientation. If 'rotate' is true, air vents are created on both sides of the surface.
/// </summary>
/// <param name="margin"> Margin of the air vent </param>
/// <param name="r1"> Internal radius </param>
/// <param name="r2"> External radius </param>
/// <param name="alpha"> Initial angle for rotation </param>
/// <param name="beta"> End angle for rotation </param>
/// <param name="s"> Surface to be cut </param>
/// <param name="rotate"> If True, air vents are created on both sides of the surface. Otherwise, only one air vent is created. </param>
private static void CreateAndCutAirVent(double margin, double r1, double r2, double alpha, double beta, Surface s, bool rotate=true)
{
Arc a1 = new Arc(Plane.YZ, new Point3D(0, 0,0), r1, alpha,beta);
Arc a2= new Arc(Plane.YZ, new Point3D(0,0,0), r2, beta,alpha);
Line a3 = new Line(a2.EndPoint, a1.StartPoint);
Line a4= new Line(a1.EndPoint, a2.StartPoint);
CompositeCurve C1 = new CompositeCurve(new ICurve[] { a1, a2, a3, a4 });
ICurve[] Curveoffset = C1.Offset(margin,Vector3D.AxisMinusX, false);
devDept.Eyeshot.Entities.Region reg=new devDept.Eyeshot.Entities.Region(Curveoffset, Plane.YZ, false);
Surface[] AirVent = reg.ExtrudeAsSurface(-31 * Vector3D.AxisX);
Surface.Trim(new Surface[] { s }, AirVent, 0.01, false, false);
if (rotate)
{
Mirror m = new Mirror(Plane.ZX);
CompositeCurve copy = (CompositeCurve)C1.Clone();
copy.TransformBy(m);
ICurve[] Curveoffset_copy = copy.Offset(margin, Vector3D.AxisX, false);
devDept.Eyeshot.Entities.Region reg1 = new devDept.Eyeshot.Entities.Region(Curveoffset_copy, Plane.YZ, false);
Surface[] AirVent2 = reg1.ExtrudeAsSurface(-31 * Vector3D.AxisX);
Surface.Trim(new Surface[] { s }, AirVent2, 0.01, true, false);
}
}
private static void MirrorEntities(Mirror m, IList<Entity> entList)
{
int count = entList.Count;
for (int i = 0; i < count; i++)
{
Entity entity = entList[i];
if (entity is Surface)
{
Surface copy = (Surface)entity.Clone();
copy.TransformBy(m);
copy.ReverseU();
entList.Add(copy);
}
}
}
Comments
Please sign in to leave a comment.