2D CAD Exercises 57

CAD_Exercises_57_2021-03-03_11-47-16.png

const string Dim = "Dimension";
const string DashDot = "DashDot";

model1.LineTypes.Add(DashDot, new float[] { 20, -2, 2, -2 });

model1.Layers.Add(new Layer(Dim, Color.CornflowerBlue));
model1.Layers[0].LineWeight = 2.5f;

// Y axis
Line axisY = new Line(0, -45, 0, 45)
{ 
	LineTypeMethod = colorMethodType.byEntity,
	LineTypeName = DashDot
};
model1.Entities.Add(axisY, Dim);

Mirror m = new Mirror(Plane.ZY);

// Building geometry - External Outline
Line lT1 = new Line(34.8, 30.2, 34.8, 44.6);
Line lT2 = new Line(28.8, 30.2, 28.8, 44.6);
Line lT3 = new Line(25.6, 32.6, 0.0, 32.6);
Circle c = new Circle(Plane.XY, new Point3D(31.8, 28, 0), 13.2);
Circle c_mir = (Circle)c.Clone();
c_mir.TransformBy(m);
Point3D int1 = Curve.Intersection(c, lT1)[0];
Point3D int2 = Curve.Intersection(c, lT2)[0];
Point3D int3 = Curve.Intersection(c, lT3)[0];

// External outline
Line eo1 = new Line(0.0, -36, 17.8, -36);
Line eo2 = new Line(17.8, -36, 17.8, -42);
Line eo3 = new Line(17.8, -42, 51, -42);
Line eo4 = new Line(51, -42, 51, -12.6);
Line eo5 = new Line(51, -12.6, 43.8, -12.6);
Line eo7 = new Line(43.8, 0.6, 51, 0.6);
Arc eo6 = new Arc(Plane.XY, new Point3D(43.8, -6.0, 0.0), 6.6, eo5.EndPoint, eo7.StartPoint, true);
Line eo8 = new Line(51, 0.6, 51, 22.6);
Line eo9 = new Line(51, 22.6, 45, 22.6);
Line eo10 = new Line(45, 22.6, 45, 28);
Arc eo11 = new Arc(Plane.XY, new Point3D(31.8, 28, 0), 13.2, eo10.EndPoint, int1, false);
Line eo12 = new Line(int1.X, int1.Y, 34.8, 44.6);
Line eo13 = new Line(34.8, 44.6, 28.8, 44.6);
Line eo14 = new Line(28.8, 44.6, int2.X, int2.Y);
Arc eo15 = new Arc(Plane.XY, new Point3D(31.8, 28, 0), 13.2, int2, int3, false);
Line eo16 = new Line(int3.X, int3.Y, 0, int3.Y);

Entity[] borders = new Entity[]{ eo1, eo2, eo3, eo4, eo5, eo6, eo7, eo8, eo9, eo10, eo11, eo12, eo13, eo14, eo15, eo16 };
Entity[] mirroredBorders = new Entity[borders.Length];

for (int i = 0; i < borders.Length; i++)
{
	mirroredBorders[i] = (Entity)borders[i].Clone();
	mirroredBorders[i].TransformBy(m);
}

model1.Entities.AddRange(borders);
model1.Entities.AddRange(mirroredBorders);

// Holes
Circle c1 = new Circle(Plane.XY, new Point3D(31.8, 28, 0), 6);
Circle c2 = (Circle)c1.Clone();
c2.TransformBy(m);
CompositeCurve h1 = CompositeCurve.CreateHexagon(31.8, 28, 6);
h1.Rotate(Math.PI / 6, Vector3D.AxisZ, new Point3D(31.8, 28, 0));
h1.TransformBy(m);

// Building Geometry - Internal Holes
Circle bC1 = new Circle(Plane.XY, new Point3D(22.8, -6.0, 0.0), 6);
Circle bC2 = new Circle(Plane.XY, new Point3D(25.2, -6.0, 0.0), 6);
Circle bC3 = new Circle(Plane.XY, new Point3D(22.9, -15.57, 0.0), 3.7);
Point3D bPt = new Point3D(16.8, -14.5, 0.0);

Line[] tgts;
UtilityEx.GetLinesTangentToCircleFromPoint(bC1, bPt, out tgts);
Line lh1 = tgts[1];
Line lh2 = UtilityEx.GetLinesTangentToTwoCircles(bC1, bC2)[0];
Line lh3 = UtilityEx.GetLinesTangentToTwoCircles(bC2, bC3)[0];
UtilityEx.GetLinesTangentToCircleFromPoint(bC3, bPt, out tgts);
Line lh4 = tgts[0];

Arc lha1 = new Arc(Plane.XY, bC1.Center, bC1.Radius, lh2.StartPoint, lh1.EndPoint, false);
Arc lha2 = new Arc(Plane.XY, bC2.Center, bC1.Radius, lh2.EndPoint, lh3.StartPoint, true);
Arc lha3 = new Arc(Plane.XY, bC3.Center, bC3.Radius, lh3.EndPoint, lh4.EndPoint, true);

Entity[] holes = { c1, c2, h1, lh1, lh2, lh3, lh4, lha1, lha2, lha3 };
model1.Entities.AddRange(holes);

// Measures
float txtH = 2.0f;
Plane left = new Plane(Point3D.Origin, Vector3D.AxisY, -1 * Vector3D.AxisX); // plane.XY, vertical writing;

Dimension[] ld = new Dimension[]
{
	// Radial
	new RadialDim(eo6, new Point3D(58.0, 0.0, 0.0), txtH)
	{
		ArrowsLocation = elementPositionType.Inside,
		CenterMarkSize = 9.0f,
		LineTypeName = DashDot,
		LineTypeMethod = colorMethodType.byEntity,
	},
	new RadialDim(new Circle(((Arc)mirroredBorders[5]).Center, ((Arc)mirroredBorders[5]).Radius), new Point3D(-30.0, 5.0, 0.0), txtH)
	{
		ArrowsLocation = elementPositionType.Outside,
		CenterMarkSize = 9.0f,
		LineTypeName = DashDot,
		LineTypeMethod = colorMethodType.byEntity,

	},
	new RadialDim(new Circle(c_mir.Center, c_mir.Radius), new Point3D(-65.0, 40.0, 0.0), txtH)
	{
		ArrowsLocation = elementPositionType.Outside,
		CenterMarkSize = 9.0f,
		LineTypeName = DashDot,
		LineTypeMethod = colorMethodType.byEntity,
		TextPrefix = "2-R"

	},
	new RadialDim(bC1, new Point3D(15.0, 2.0, 0.0), txtH)
	{
		ArrowsLocation = elementPositionType.Outside
	},
	new RadialDim(bC2, new Point3D(30.0, 1.0, 0.0), txtH)
	{
		ArrowsLocation = elementPositionType.Outside
	},
	new RadialDim(bC3, new Point3D(30.0, -32.0, 0.0), txtH)
	{
		ArrowsLocation = elementPositionType.Outside
	},

	// Diametric
	new DiametricDim(c1, new Point3D(20.0, 20.0, 0.0), txtH)
	{
		ArrowsLocation = elementPositionType.Outside,
		TextPrefix = "2-Ø"
	},

	// Linear
	new LinearDim(Plane.XY, new Point2D(-51.0, -42.0), new Point2D(51.0, -42.0), new Point2D(0.0, -70.0), txtH),
	new LinearDim(Plane.XY, new Point2D(-17.8, -42.0), new Point2D(17.8, -42.0), new Point2D(0.0, -60.0), txtH),
	new LinearDim(Plane.XY, new Point2D(-17.8, -42.0), new Point2D(-17.8, -42.0), new Point2D(0.0, -60.0), txtH),
	new LinearDim(Plane.XY, new Point2D(-51.0, -42.0), new Point2D(-17.8, -42.0), new Point2D(-34.4, -60.0), txtH),
	new LinearDim(left, new Point2D(-42.0, 51.0), new Point2D(44.6, 34.8), new Point2D(0.0, 80), txtH),
	new LinearDim(left, new Point2D(-42.0, 51.0), new Point2D(-12.6, 51.0), new Point2D(-27.3, 60), txtH),
	new LinearDim(left, new Point2D(-12.6, 51.0), new Point2D(0.6, 51.0), new Point2D(-6.0, 60), txtH),
	new LinearDim(left, new Point2D(0.6, 51.0), new Point2D(22.8, 51.0), new Point2D(11.7, 60), txtH),
	new LinearDim(Plane.XY, new Point2D(-51.0, 22.8), new Point3D(-31.8, 28, 0), new Point2D(-41.4, 70), txtH),
	new LinearDim(Plane.XY, new Point3D(-31.8, 28, 0), new Point2D(31.8, 22.8), new Point2D(0.0, 70), txtH),
	new LinearDim(left, new Point2D(-42, -51.0), new Point2D(-6, -51.0), new Point2D(-21, -70), txtH),
	new LinearDim(left, new Point2D(-6, -51.0), new Point2D(28.2, -31.8), new Point2D(11.1, -70), txtH),
	new LinearDim(Plane.XY, new Point2D(28.8, 44.6), new Point2D(34.8, 44.6), new Point2D(38.0, 49.6), txtH)
	{
		ArrowsLocation = elementPositionType.Outside
	},
	new LinearDim(Plane.XY, new Point2D(-28.8, 44.6), new Point2D(-34.8, 44.6), new Point2D(-38.0, 49.6), txtH)
	{
		ArrowsLocation = elementPositionType.Outside
	},
	new LinearDim(Plane.XY, new Point2D(-51.0, 22.8), new Point3D(-45.0, 30.0, 0), new Point2D(-48.0, 58.0), txtH),
	new LinearDim(left, new Point2D(-42.0, 20.0), new Point2D(-36.0, 17.8), new Point2D(-39.0, 20.0), txtH),
	new LinearDim(left, new Point2D(-36.0, 17.8), new Point2D(32.6, 19.0), new Point2D(-1.9, 20.0), txtH),
	new LinearDim(left, new Point2D(-36.0, 12.0), new Point2D(0.0, 0.0), new Point2D(-18.0, 12.0), txtH),
	new LinearDim(left, new Point2D(-36.0, 7.0), new Point2D(-14.5, -16.0), new Point2D(-25.25, 7.0), txtH)
	{
		ArrowsLocation = elementPositionType.Inside
	},
	new LinearDim(left, new Point2D(-36.0, -4.0), new Point2D(-15.57, -22.9), new Point2D(-25.79, -4.0), txtH)
	{
		ArrowsLocation = elementPositionType.Inside
	},
	new LinearDim(Plane.XY, new Point2D(43.8, -6.0), new Point2D(51.0, -20.0), new Point2D(54.0, -20.0), txtH)
	{
		ArrowsLocation = elementPositionType.Outside
	},
	new LinearDim(Plane.XY, new Point2D(-43.8, -6.0), new Point2D(-51.0, -20.0), new Point2D(-54.0, -20.0), txtH)
	{
		ArrowsLocation = elementPositionType.Outside
	},
	new LinearDim(Plane.XY, new Point2D(22.8, -6.0), new Point2D(25.2, -6.0), new Point2D(27.0, 10.0), txtH),
	new LinearDim(Plane.XY, new Point2D(22.9, -15.57), new Point2D(16.8, -14.5), new Point2D(18.0, -30.0), txtH)
	{
		ArrowsLocation = elementPositionType.Outside
	},
	new LinearDim(Plane.XY, new Point2D(0.0, -9.5), new Point2D(16.8, -9.5), new Point2D(8.4, -9.5), txtH)
};

model1.Entities.AddRange(ld, Dim);

DrawFrame();

// Top View
model1.SetView(viewType.Top, false, false);
model1.ZoomFit();

Print();
void DrawFrame()
{
	const string FrameLayer = "FrameLayer";

	model1.Layers.Add(new Layer(FrameLayer, Color.Black));
	model1.Layers[FrameLayer].LineWeight = 3.0f;

	// offset from the ln1 and half height
	const double offset = 150, halfheight = 105, width = 297;

	// drawing the ln1
	Line ln1 = new Line(0 - offset, halfheight, width - offset, halfheight);
	model1.Entities.Add(ln1, FrameLayer);
	ln1 = new Line(0 - offset, halfheight, 0 - offset, -halfheight);
	model1.Entities.Add(ln1, FrameLayer);
	ln1 = new Line(0 - offset, -halfheight, width - offset, -halfheight);
	model1.Entities.Add(ln1, FrameLayer);
	ln1 = new Line(width - offset, -halfheight, width - offset, halfheight);
	model1.Entities.Add(ln1, FrameLayer);
}
private void Print()
{
	model1.PageSetup(true, false, 0, new System.Drawing.Printing.PaperSize("A4", 826, 1169), true);

	// saves current view Camera
	model1.SaveView(out Camera cameraSaved);

	// creates printing setting object and customize it
	HiddenLinesViewSettings hdlS = new HiddenLinesViewSettings(model1);
	hdlS.KeepEntityLineWeight = true;

	// creates paper preview
	HiddenLinesViewOnPaperPreview hdl = new HiddenLinesViewOnPaperPreview(hdlS, new Size(800, 600), 2);
	model1.StartWork(hdl);

	// restores saved view
	model1.RestoreView(cameraSaved);
}

2D CAD Exercises 57

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.