public void SetupCorpusSize() { int i; Box[] boxes = { planeLocator.LBox, prismLocator1.LBox, prismLocator2.LBox }; Box boundingBox = new Box(); i = 0; boundingBox.Xmin = new double[] { boxes[0].CoordinatesCorners[i], boxes[1].CoordinatesCorners[i], boxes[2].CoordinatesCorners[i] }.Min(); i = 1; boundingBox.Ymin = new double[] { boxes[0].CoordinatesCorners[i], boxes[1].CoordinatesCorners[i], boxes[2].CoordinatesCorners[i] }.Min(); i = 2; boundingBox.Zmin = new double[] { boxes[0].CoordinatesCorners[i], boxes[1].CoordinatesCorners[i], boxes[2].CoordinatesCorners[i] }.Min(); i = 3; boundingBox.Xmax = new double[] { boxes[0].CoordinatesCorners[i], boxes[1].CoordinatesCorners[i], boxes[2].CoordinatesCorners[i] }.Max(); i = 4; boundingBox.Ymax = new double[] { boxes[0].CoordinatesCorners[i], boxes[1].CoordinatesCorners[i], boxes[2].CoordinatesCorners[i] }.Max(); i = 5; boundingBox.Zmax = new double[] { boxes[0].CoordinatesCorners[i], boxes[1].CoordinatesCorners[i], boxes[2].CoordinatesCorners[i] }.Max(); int width = Convert.ToInt32(1000.0 * (boundingBox.Zmax - boundingBox.Zmin)); int length = Convert.ToInt32(1000.0 * (boundingBox.Xmax - boundingBox.Xmin)); int size = Math.Max(width, length); Vector newLocation = new Vector() { X = (boundingBox.Xmin + boundingBox.Xmax) / 2, Y = (boundingBox.Ymin + boundingBox.Ymax) / 2, Z = (boundingBox.Zmin + boundingBox.Zmax) / 2 }; corpus.Translate(newLocation); corpus.SetParameter(configuration[Property.PARAMETER_CORPUS_WIDTH], size.ToString()); corpus.SetParameter(configuration[Property.PARAMETER_CORPUS_LENGTH], size.ToString()); Rebuild(); }
private void SetupCorpus() { IFace2 face1 = prismLocator1.BottomFace; IFace2 face2 = prismLocator2.BottomFace; (face1 as Entity).Select4(true, null); (face2 as Entity).Select4(true, null); IFace2 lowestFace = null; Locator danglingLocator = null; if (helper.CenterBox(face1.GetBox()).Y < helper.CenterBox(face2.GetBox()).Y) { lowestFace = face1; danglingLocator = prismLocator2; } else { lowestFace = face2; danglingLocator = prismLocator1; } Debug.WriteLine("dangling locator search ... done!"); IFace2 topFaceOfCorpus = corpus.TopFace; mounter.AddMate(topFaceOfCorpus, lowestFace, (int)swMateType_e.swMateCOINCIDENT, (int)swMateAlign_e.swAlignAGAINST); mounter.AddMate(topFaceOfCorpus, planeLocator.BottomFace, (int)swMateType_e.swMateCOINCIDENT, (int)swMateAlign_e.swAlignAGAINST); Debug.WriteLine("mate with corpus of not dangling locator ... done!"); Rebuild(); double delta = 0; double value = 0; Box boxLowestFaceDanglingLocator = new Box(helper.ApplyTransform(danglingLocator.Transform, danglingLocator.BottomFace.GetBox())); Box boxTopFaceCorpus = new Box(helper.ApplyTransform(corpus.Transform, topFaceOfCorpus.GetBox())); delta = Math.Abs(1000.0 * (boxLowestFaceDanglingLocator.Ymin - boxTopFaceCorpus.Ymin)); value = delta + Convert.ToDouble(danglingLocator.GetParameter(configuration[Property.PARAMETER_CYLINDER_LOCATOR_HEIGHT])); danglingLocator.SetParameter(configuration[Property.PARAMETER_CYLINDER_LOCATOR_HEIGHT], Convert.ToInt32(value).ToString()); Debug.WriteLine("extension of the dangling locator, delta: {0}mm, value: {1} ... done!", delta, Convert.ToInt32(value)); Rebuild(); delta = Math.Abs(1000.0 * (planeBase.FaceGBox.Ymax - planeLocator.LBox.Ymax)); value = Convert.ToDouble(planeLocator.GetParameter(configuration[Property.PARAMETER_PLANE_LOCATOR_HEIGHT])) + delta; planeLocator.SetParameter(configuration[Property.PARAMETER_PLANE_LOCATOR_HEIGHT], Convert.ToInt32(value).ToString()); Debug.WriteLine("extension of the plane locator, delta {0}mm, value: {1}mm ... done!", delta, Convert.ToInt32(value)); Rebuild(); Debug.WriteLine("setup corpus ... done!"); }
private IFace2 FindVecticalExtremeFaceWithNormal(int direction) { IFace2 extremeFace = null; Vector extreme = new Vector(0.0, direction * double.MinValue, 0.0); IMathVector targetNormalVector = MathUtility.CreateVector(new double[] { 0.0, direction, 0.0 }); for (int i = 0; i < Faces.Length; ++i) { IFace2 face = Faces[i]; if (face.IGetSurface().IsPlane()) { double[] normal = Helper.Instance.ApplyTransform(Transform, face.Normal); IMathVector normalVector = MathUtility.CreateVector(normal); if (IsHorizontal(normalVector) || IsHorizontal(Helper.Negative(normalVector))) { Vector center = new Box(Helper.ApplyTransform(Transform, face.GetBox())).Center; if (direction == 1 ? center.Y > extreme.Y : center.Y < extreme.Y) { extreme.Y = center.Y; extremeFace = face; } } } } return extremeFace; }