public static Line GetFaceSideDirection(Face face, UnitVector xAxis) { switch (face.SurfaceType) { case SurfaceTypeEnum.kConeSurface: Cone cone = face.Geometry as Cone; UnitVector axisVector = cone.AxisVector; double num = (cone.IsExpanding ? -1.0 : 1.0) * cone.Radius / Math.Tan(cone.HalfAngle); Point point1 = Toolkit._Tg.CreatePoint(cone.BasePoint.X + xAxis.X * cone.Radius, cone.BasePoint.Y + xAxis.Y * cone.Radius, cone.BasePoint.Z + xAxis.Z * cone.Radius); Point point2 = Toolkit._Tg.CreatePoint(cone.BasePoint.X + axisVector.X * num, cone.BasePoint.Y + axisVector.Y * num, cone.BasePoint.Z + axisVector.Z * num); return(Toolkit._Tg.CreateLine(point1, point1.VectorTo(point2))); default: return((Line)null); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Use: Returns an UnitVector orthogonal to input vector // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static UnitVector GetOrthoVector(UnitVector vector) { if (Math.Abs(vector.Z) < _Tolerance) { return(InvApplication.TransientGeometry.CreateUnitVector(0, 0, 1)); } else if (Math.Abs(vector.Y) < _Tolerance) { return(InvApplication.TransientGeometry.CreateUnitVector(0, 1, 0)); } else { //Expr: - xx'/y = y' return(InvApplication.TransientGeometry.CreateUnitVector(1, -vector.X / vector.Y, 0)); } }
public void TestSignedAngle() { var u = (new Vector(1, 0.5)).Unit; var a = u.ToAngle(); AssertAreEqual(u, UnitVector.FromAngle(a)); u = (new Vector(1, -0.5)).Unit; a = u.ToAngle(); AssertAreEqual(u, UnitVector.FromAngle(a)); u = (new Vector(-1, 0.5)).Unit; a = u.ToAngle(); AssertAreEqual(u, UnitVector.FromAngle(a)); u = (new Vector(-1, -0.5)).Unit; a = u.ToAngle(); AssertAreEqual(u, UnitVector.FromAngle(a)); }
public static string VectorToString(object pO) { if (pO is Vector) { Vector p = (Vector)pO; return(p.X + "," + p.Y + "," + p.Z); } else if (pO is UnitVector) { UnitVector p = (UnitVector)pO; return(p.X + "," + p.Y + "," + p.Z); } else if (pO is Point) { Point p = (Point)pO; return(p.X + "," + p.Y + "," + p.Z); } return(""); }
public void TestRotate() { var pt1 = new Point(1, 1); var pt2 = new Point(2, 2); var pt1_1 = pt1.Rotate(UnitVector.FromAngle(Math.PI / 4), Point.Zero); var pt2_1 = pt2.Rotate(UnitVector.FromAngle(Math.PI / 4), Point.Zero); var a1 = (pt2_1 - pt1_1).Unit.ToAngle(); var pt1_2 = pt1.Rotate(UnitVector.FromAngle(Math.PI / 8), Point.Zero); var pt2_2 = pt2.Rotate(UnitVector.FromAngle(Math.PI / 8), Point.Zero); pt2_2 = pt2_2.Rotate(UnitVector.FromAngle(Math.PI / 8), pt1_2); var a2 = (pt2_2 - pt1_2).Unit.ToAngle(); Assert.AreEqual(a1, a2, Tol); }
public void TestGetAngle() { Assert.AreEqual(new UnitVector(1, 0), UnitVector.GetAngle(new Vector(10, 1), new Vector(10, 1))); var u = UnitVector.GetAngle(new Vector(10, 1), new Vector(10, 2)); Assert.IsTrue(u.X > 0 && u.Y > 0); u = UnitVector.GetAngle(new Vector(10, 1), new Vector(-10, 2)); Assert.IsTrue(u.X < 0 && u.Y > 0); u = UnitVector.GetAngle(new Vector(10, 1), new Vector(-10, -2)); Assert.IsTrue(u.X < 0 && u.Y < 0); u = UnitVector.GetAngle(new Vector(10, 1), new Vector(10, -2)); Assert.IsTrue(u.X > 0 && u.Y < 0); u = UnitVector.GetAngle(new Vector(-10, 1), new Vector(-10, -1)); Assert.IsTrue(u.X > 0 && u.Y > 0); }
///////////////////////////////////////////////////////////// // Use: Returns thread major radius for tapered thread. // ///////////////////////////////////////////////////////////// private static double GetThreadMajorRadiusTapered( ThreadInfo threadInfo, Face threadedFace) { UnitVector yAxis = threadInfo.ThreadDirection.AsUnitVector(); UnitVector xAxis = Toolkit.GetOrthoVector(yAxis); Point basePoint = threadInfo.ThreadBasePoints[1] as Point; Line l1 = Toolkit.GetFaceSideDirection( threadedFace.Geometry, xAxis); Line l2 = _Tg.CreateLine(basePoint, xAxis.AsVector()); Point p1 = l1.IntersectWithCurve(l2, 0.0001)[1] as Point; return(p1.DistanceTo(basePoint)); }
////////////////////////////////////////////////////////////////////////////////////////////// // Creates a new GraphicsNode that contains our graphic symbol // ////////////////////////////////////////////////////////////////////////////////////////////// GraphicsNode DrawSymbol( UnitVector normal, Point center, double radius) { Circle circle = _Tg.CreateCircle(center, normal, radius); double[] up = new double[] { center.X, center.Y + radius, 0 }; double[] down = new double[] { center.X, center.Y - radius, 0 }; double[] right = new double[] { center.X + radius, center.Y, 0 }; double[] left = new double[] { center.X - radius, center.Y, 0 }; GraphicsNode node = _clientGraphicsMng.CreateNewGraphicsNode(); node.Selectable = true; CurveGraphics curve = _clientGraphicsMng.DrawCurve(circle, node); LineGraphics lineVert = _clientGraphicsMng.DrawLine(up, down, node); LineGraphics lineHorz = _clientGraphicsMng.DrawLine(left, right, node); return(node); }
///////////////////////////////////////////////////////////// // Use: Returns direction of the cone side as Line object. // ///////////////////////////////////////////////////////////// public static Line GetConeSideDirection( Cone cone, UnitVector xAxis) { UnitVector yAxis = cone.AxisVector; double height = (cone.IsExpanding ? -1.0 : 1.0) * cone.Radius / Math.Tan(cone.HalfAngle); Point p1 = _Tg.CreatePoint( cone.BasePoint.X + xAxis.X * cone.Radius, cone.BasePoint.Y + xAxis.Y * cone.Radius, cone.BasePoint.Z + xAxis.Z * cone.Radius); Point p2 = _Tg.CreatePoint( cone.BasePoint.X + yAxis.X * height, cone.BasePoint.Y + yAxis.Y * height, cone.BasePoint.Z + yAxis.Z * height); return(_Tg.CreateLine(p1, p1.VectorTo(p2))); }
////////////////////////////////////////////////////////////////////////////////////////////// // Creates a new GraphicsNode that contains our graphic symbol // ////////////////////////////////////////////////////////////////////////////////////////////// GraphicsNode DrawSymbol( UnitVector normal, Point center, double radius) { Circle circle = _Tg.CreateCircle(center, normal, radius); double[] up = new double[]{center.X, center.Y + radius, 0}; double[] down = new double[]{center.X, center.Y - radius, 0}; double[] right = new double[]{center.X + radius, center.Y, 0}; double[] left = new double[]{center.X - radius, center.Y, 0}; GraphicsNode node = _clientGraphicsMng.CreateNewGraphicsNode(); node.Selectable = true; CurveGraphics curve = _clientGraphicsMng.DrawCurve(circle, node); LineGraphics lineVert = _clientGraphicsMng.DrawLine(up, down, node); LineGraphics lineHorz = _clientGraphicsMng.DrawLine(left, right, node); return node; }
private bool RelationWithSegment1(Segment segment, Coordinate coordinate) { UnitVector vector = new UnitVector() { X = Math.Abs(coordinate.x - segment.SegmentStart.x) < 0.1?0: coordinate.x - segment.SegmentStart.x, Y = Math.Abs(coordinate.y - segment.SegmentStart.y) < 0.00001?0: coordinate.y - segment.SegmentStart.y }; UnitVector vector1 = new UnitVector() { X = Math.Abs(coordinate.x - segment.SegmentEnd.x) < 0.1?0:coordinate.x - segment.SegmentStart.x, Y = Math.Abs(coordinate.y - segment.SegmentEnd.y) < 0.00001 ? 0 : coordinate.y - segment.SegmentEnd.y }; if (vector.X == 0 && vector1.X == 0) { if (vector.Y * vector1.Y < 0)//共线 { return(true); } else { return(false); } } else if (vector.Y == 0 && vector1.Y == 0)//共线 { if (vector.X * vector1.X < 0) { return(true); } else { return(false); } } else { return(false); } }
////////////////////////////////////////////////////////////////////////////////////////////// // OnMouseMove Event is used to transform current GraphicsNode moved by the user // ////////////////////////////////////////////////////////////////////////////////////////////// void MouseEvents_OnMouseMove( MouseButtonEnum Button, ShiftStateEnum ShiftKeys, Inventor.Point ModelPosition, Point2d ViewPosition, Inventor.View View) { if (_symbolNode == null) { // Define symbol inputs: center, normal, radius Point center = _Tg.CreatePoint(0, 0, 0); UnitVector normal = _Tg.CreateUnitVector(0, 0, 1); double radius = _sheet.Width / 30; _symbolNode = DrawSymbol(normal, center, radius); } SetNodePosition(_symbolNode, ModelPosition); _clientGraphicsMng.UpdateView(); }
public void UpdatePreviewGraphics() { m_graphicsCoordinateSet = null; InteractionGraphics interactionGraphics = m_interactionEvents.InteractionGraphics; GraphicsDataSets graphicsDataSets = interactionGraphics.GraphicsDataSets; if (graphicsDataSets.Count != 0) { graphicsDataSets[1].Delete(); } // m_graphicsCoordinateSet = graphicsDataSets.CreateCoordinateSet(1); //m_pointGraphics.CoordinateSet = m_graphicsCoordinateSet; //TransientGeometry transientGeometry = m_inventorApplication.TransientGeometry; PartDocument oPartDoc; oPartDoc = (PartDocument)m_inventorApplication.ActiveDocument; PartComponentDefinition oPartCompDef; oPartCompDef = oPartDoc.ComponentDefinition; WorkAxis workAxis; workAxis = oPartCompDef.WorkAxes.AddByRevolvedFace(m_selectFace, true); if (m_UCS == null) { return; } WorkPoint workPoint; workPoint = oPartCompDef.WorkPoints.AddByCurveAndEntity(workAxis, m_UCS.XYPlane); Point transPoint = workPoint.Point; UnitVector xUnitVector = m_UCS.XAxis.Line.Direction; UnitVector yUnitVector = m_UCS.YAxis.Line.Direction; Double[] xCoords = new Double[3]; xUnitVector.GetUnitVectorData(ref xCoords); Double[] yCoords = new Double[3]; yUnitVector.GetUnitVectorData(ref yCoords); double xOffset = this.GetValueFromExpression(m_moveCmdDlg.xOffsetText.Text); double yOffset = this.GetValueFromExpression(m_moveCmdDlg.yOffsetText.Text); Double[] transCoords = new Double[3]; transCoords[0] = xOffset * xCoords[0] + yOffset * yCoords[0]; transCoords[1] = xOffset * xCoords[1] + yOffset * yCoords[1]; transCoords[2] = xOffset * xCoords[2] + yOffset * yCoords[2]; Vector transVector = m_inventorApplication.TransientGeometry.CreateVector(); transVector.PutVectorData(transCoords); transPoint.TranslateBy(transVector); Double[] oPointCoords = new Double[3]; oPointCoords[0] = transPoint.X; oPointCoords[1] = transPoint.Y; oPointCoords[2] = transPoint.Z; m_graphicsCoordinateSet = graphicsDataSets.CreateCoordinateSet(1); m_graphicsCoordinateSet.PutCoordinates(oPointCoords); m_pointGraphics.CoordinateSet = m_graphicsCoordinateSet; TransientGeometry transientGeometry = m_inventorApplication.TransientGeometry; // m_graphicsCoordinateSet.Add(1, transPoint); m_inventorApplication.ActiveView.Update(); }
public InfinitePlane(Material material, Point point, UnitVector normal) : base(material) { _point = point; _normal = normal; }
public List <Coordinate> deleteOppositeVector(List <Coordinate> coordinates) { List <UnitVector> savedVectors = new List <UnitVector>(); int flag = 0; if (coordinates.Count < 3) { throw new Exception("坐标数量小于三,无法进行判断"); } //先判断第一个向量是不是等于最后一个向量 UnitVector fistVector = calcuUnitVector(coordinates[0], coordinates[1]); //计算最后一条线的向量 UnitVector lastVector = calcuUnitVector(coordinates[coordinates.Count - 2], coordinates[coordinates.Count - 1]); if ((Math.Abs(fistVector.X + lastVector.X) < 0.000001) && (Math.Abs(fistVector.Y + lastVector.Y) < 0.00001))//第一条线的向量等于最后一条线的向量 { coordinates.RemoveAt(coordinates.Count - 1); coordinates.RemoveAt(0); coordinates.Insert(0, coordinates[coordinates.Count - 1]);//删完首尾的点还要在头部再加一个和尾部相同的点 } //判断中间线串的中间有没有出现自相交 for (int i = 0; i < coordinates.Count - 3; i++) { if (JudgeDirection(coordinates[i], coordinates[i + 1], coordinates[i + 2]))//ture,方向相反 { coordinates[i + 1].x = (coordinates[i].x + coordinates[i + 2].x) / 2; coordinates[i + 1].y = (coordinates[i].y + coordinates[i + 2].y) / 2; } } List <Segment> segments = new List <Segment>(); List <Coordinate> deleteCoord = new List <Coordinate>(); int count = 0; if (coordinates.Count > 2) { Segment segmentfirst = new Segment() { SegmentStart = coordinates[0], SegmentEnd = coordinates[1] }; segments.Add(segmentfirst); for (int i = 1; i < coordinates.Count - 1; i++) { foreach (var item in segments) { if (RelationWithSegment(item, coordinates[i]))//判断线段和坐标点的关系 { deleteCoord.Add(coordinates[i]); } } Segment segment = new Segment() { SegmentStart = coordinates[i], SegmentEnd = coordinates[i + 1] }; segments.Add(segment); } } for (int i = coordinates.Count - 1; i > 0; i--) { foreach (var deleteitem in deleteCoord) { if (coordinates[i].x == deleteitem.x && coordinates[i].y == deleteitem.y) { coordinates.Remove(deleteitem); } } } //计算第一条线的向量 return(coordinates); }
public override UnitVector SurfaceNormalAtPoint(Point point) { return(UnitVector.UnsafeCreateUnitVector(Point.Origin.To(point) * _inverseRadius)); }
private ObjectsEnumerator InternalFindUsingVector(Point originPoint, UnitVector direction, SelectionFilterEnum[] objectTypes, bool useCylinder, Object proximityTolerance, bool visibleObjectsOnly, out Object locationPoints) { return(ComponentDefinitionInstance.FindUsingVector(originPoint.ToPoint(), direction, objectTypes, useCylinder, proximityTolerance, visibleObjectsOnly, out locationPoints)); }
static public MirrorFeature addMirror(SheetMetalComponentDefinition smcd, ObjectCollection objs, string name, UnitVector vec) { SheetMetalFeatures smf = (SheetMetalFeatures)smcd.Features; WorkPlane wp = smcd.WorkPlanes.OfType <WorkPlane>().First(e => InvDoc.u.eq(vec, e.Plane.Normal)); MirrorFeature mir = smf.MirrorFeatures.Add(objs, wp, false, PatternComputeTypeEnum.kAdjustToModelCompute); mir.Name = name; return(mir); }
private ObjectsEnumerator InternalFindUsingVector(Point originPoint, UnitVector direction, SelectionFilterEnum[] objectTypes, bool useCylinder, Object proximityTolerance, bool visibleObjectsOnly, out Object locationPoints) { return ComponentDefinitionInstance.FindUsingVector( originPoint.ToPoint(), direction, objectTypes, useCylinder, proximityTolerance, visibleObjectsOnly, out locationPoints); }
/* * public Equation DistanceTo(Vector3D point) * { * return UnitVector.Dot(point) - D; * }*/ public double DistanceTo(Vector3D point) { return(UnitVector.Dot(point) - D); }
private void GetLayer(double[] del, ref int Layer, ref int direction, ref int clockwise) { Box sceneBox = GetSceneBox(); if (null != sceneBox && null != mSelectedFace) { GraphicsNode node = mSelectedFace.Parent.Parent; Box nodeBox = node.RangeBox; double[] midPt = { (nodeBox.MaxPoint.X + nodeBox.MinPoint.X) / 2.0, (nodeBox.MaxPoint.Y + nodeBox.MinPoint.Y) / 2.0, (nodeBox.MaxPoint.Z + nodeBox.MinPoint.Z) / 2.0 }; double[] delta = { nodeBox.MaxPoint.X - nodeBox.MinPoint.X , nodeBox.MaxPoint.Y - nodeBox.MinPoint.Y , nodeBox.MaxPoint.Z - nodeBox.MinPoint.Z }; int i = (int)((midPt[0] - sceneBox.MinPoint.X) / delta[0]); int j = (int)((midPt[1] - sceneBox.MinPoint.Y) / delta[1]); int k = (int)((midPt[2] - sceneBox.MinPoint.Z) / delta[2]); Plane plane = mSelectedFace.Face.Geometry as Plane; if (null == plane) { return; } UnitVector normal = plane.Normal; if (mSelectedFace.Face.IsParamReversed == true) { normal.X = -normal.X; normal.Y = -normal.Y; normal.Z = -normal.Z; } normal.TransformBy(node.Transformation); if (Math.Abs(Math.Abs(normal.X) - 1.0) < 0.0001) { if (Math.Abs(del[1]) > Math.Abs(del[2])) { Layer = k; direction = 2; //clockwise = (del[1] > 0 ? 1 : -1) * (int)normal.X; clockwise = (del[1] * normal.X > 0 ? 1 : -1); } else { Layer = j; direction = 1; //clockwise = (del[2] > 0 ? -1 : 1) * (int)normal.X; clockwise = (del[2] * normal.X > 0 ? -1 : 1); } } else if (Math.Abs(Math.Abs(normal.Y) - 1.0) < 0.0001) { if (Math.Abs(del[2]) > Math.Abs(del[0])) { Layer = i; direction = 0; //clockwise = (del[2] > 0 ? 1 : -1) * (int)normal.Y; clockwise = (del[2] * normal.Y > 0 ? 1 : -1); } else { Layer = k; direction = 2; //clockwise = (del[0] > 0 ? -1 : 1) * (int)normal.Y; clockwise = (del[0] * normal.Y > 0 ? -1 : 1); } } else if (Math.Abs(Math.Abs(normal.Z) - 1.0) < 0.0001) { if (Math.Abs(del[0]) > Math.Abs(del[1])) { Layer = j; direction = 1; //clockwise = (del[0] > 0 ? 1 : -1) * (int)normal.Z; clockwise = (del[0] * normal.Z > 0 ? 1 : -1); } else { Layer = i; direction = 0; //clockwise = (del[1] > 0 ? -1 : 1) * (int)normal.Z; clockwise = (del[1] * normal.Z > 0 ? -1 : 1); } } } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Use: Returns an UnitVector orthogonal to input vector // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static UnitVector GetOrthoVector(UnitVector vector) { if (Math.Abs(vector.Z) < _Tolerance) { return InvApplication.TransientGeometry.CreateUnitVector(0, 0, 1); } else if (Math.Abs(vector.Y) < _Tolerance) { return InvApplication.TransientGeometry.CreateUnitVector(0, 1, 0); } else { //Expr: - xx'/y = y' return InvApplication.TransientGeometry.CreateUnitVector(1, -vector.X / vector.Y, 0); } }
///////////////////////////////////////////////////////////// // Use: Creates new solid bodies affected by the future // CoilFeature for Tapered Thread. ///////////////////////////////////////////////////////////// private static bool CreateCoilBodyTapered(PartDocument doc, ThreadInfo threadInfo, Face threadedFace, double depth, bool isInteriorFace) { try { PartComponentDefinition compDef = doc.ComponentDefinition; Vector direction = threadInfo.ThreadDirection; Point basePoint = threadInfo.ThreadBasePoints[1] as Point; Point endPoint = _Tg.CreatePoint( basePoint.X + direction.X, basePoint.Y + direction.Y, basePoint.Z + direction.Z); UnitVector yAxis = direction.AsUnitVector(); UnitVector xAxis = Toolkit.GetOrthoVector(yAxis); WorkPoint wpt = compDef.WorkPoints.AddFixed(basePoint, _ConstructionWorkFeature); WorkPlane wpl = compDef.WorkPlanes.AddFixed(basePoint, xAxis, yAxis, _ConstructionWorkFeature); WorkAxis xWa = compDef.WorkAxes.AddFixed(basePoint, xAxis, _ConstructionWorkFeature); WorkAxis yWa = compDef.WorkAxes.AddFixed(basePoint, yAxis, _ConstructionWorkFeature); PlanarSketch sketch = compDef.Sketches.AddWithOrientation(wpl, xWa, true, true, wpt, false); Cone cone = threadedFace.Geometry as Cone; double revDepth = depth / Math.Cos(cone.HalfAngle) * (isInteriorFace ? -1.0 : 1.0); Line l1 = Toolkit.GetFaceSideDirection(threadedFace, xAxis); Line l2 = _Tg.CreateLine(basePoint, xAxis.AsVector()); Line l3 = _Tg.CreateLine(endPoint, xAxis.AsVector()); Point p1 = l1.IntersectWithCurve(l2, 0.0001)[1] as Point; Point p2 = l1.IntersectWithCurve(l3, 0.0001)[1] as Point; Point p3 = _Tg.CreatePoint( p2.X - xAxis.X * revDepth, p2.Y - xAxis.Y * revDepth, p2.Z - xAxis.Z * revDepth); Point p4 = _Tg.CreatePoint( p1.X - xAxis.X * revDepth, p1.Y - xAxis.Y * revDepth, p1.Z - xAxis.Z * revDepth); SketchPoint skp1 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p1), false); SketchPoint skp2 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p2), false); SketchPoint skp3 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p3), false); SketchPoint skp4 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p4), false); sketch.SketchLines.AddByTwoPoints(skp1, skp2); sketch.SketchLines.AddByTwoPoints(skp2, skp3); sketch.SketchLines.AddByTwoPoints(skp3, skp4); sketch.SketchLines.AddByTwoPoints(skp4, skp1); Profile profile = sketch.Profiles.AddForSolid(true, null, null); RevolveFeature rev1 = compDef.Features.RevolveFeatures.AddFull( profile, yWa, PartFeatureOperationEnum.kCutOperation); sketch = compDef.Sketches.AddWithOrientation(wpl, xWa, true, true, wpt, false); skp1 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p1), false); skp2 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p2), false); skp3 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p3), false); skp4 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p4), false); sketch.SketchLines.AddByTwoPoints(skp1, skp2); sketch.SketchLines.AddByTwoPoints(skp2, skp3); sketch.SketchLines.AddByTwoPoints(skp3, skp4); sketch.SketchLines.AddByTwoPoints(skp4, skp1); profile = sketch.Profiles.AddForSolid(true, null, null); RevolveFeature rev2 = compDef.Features.RevolveFeatures.AddFull( profile, yWa, PartFeatureOperationEnum.kNewBodyOperation); return(true); } catch { return(false); } }
public ObjectsEnumerator FindUsingVector(Point originPoint, UnitVector direction, SelectionFilterEnum[] objectTypes, bool useCylinder, Object proximityTolerance, bool visibleObjectsOnly, out Object locationPoints) { return(InternalFindUsingVector(originPoint, direction, objectTypes, useCylinder, proximityTolerance, visibleObjectsOnly, out locationPoints)); }
private int funds; //Bank (income is handled in TeamManager) public Team(Commander co) { units = new UnitVector(); this.co = co; coBar = 0; }
public ObjectsEnumerator FindUsingVector(Point originPoint, UnitVector direction, SelectionFilterEnum[] objectTypes, bool useCylinder, Object proximityTolerance, bool visibleObjectsOnly, out Object locationPoints) { return InternalFindUsingVector( originPoint, direction, objectTypes, useCylinder, proximityTolerance, visibleObjectsOnly, out locationPoints); }
internal static bool AreSame(UnitVector u1, UnitVector u2) { var sin = u1 ^ u2; return(Math.Abs(sin) < angleTolSin && u1 * u2 > 0); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private static RectangularPatternFeature[] CopyRectangularPatternFeature(PartComponentDefinition partCompDef, RectangularPatternFeature AsmFeature, Matrix invTransfo, int elementIdx, ComponentOccurrence occurrence, out ReportData[] reports) { List <RectangularPatternFeature> newFeatures = new List <RectangularPatternFeature>(); ObjectCollection ParentFeatures = FeatureUtilities.CopyParentFeatures(partCompDef, AsmFeature.Parent.Document as Document, AsmFeature.ParentFeatures, invTransfo, occurrence, out reports); if (ParentFeatures.Count == 0) { return(null); } Sketch3D sketch3D = partCompDef.Sketches3D.Add(); List <RectangularPatternFeatureData> FeaturesDataList = new List <RectangularPatternFeatureData>(); //Only along X Axis if (AsmFeature.XDirectionEntity != null && AsmFeature.YDirectionEntity == null) { UnitVector xDirection = FeatureUtilities.GetDirection(AsmFeature.XDirectionEntity); xDirection.TransformBy(invTransfo); Point xDirStartPoint = null; WorkAxis xDirAxis = null; SketchPoint3D xDirStartPoint3D = null; try { xDirStartPoint = FeatureUtilities.GetPoint(AsmFeature.XDirectionStartPoint); xDirStartPoint.TransformBy(invTransfo); xDirAxis = partCompDef.WorkAxes.AddFixed(xDirStartPoint, xDirection, FeatureUtilities.ConstructionWorkAxis); xDirStartPoint3D = sketch3D.SketchPoints3D.Add(xDirStartPoint, false); } catch { xDirAxis = partCompDef.WorkAxes.AddFixed(partCompDef.WorkPoints[1].Point, xDirection, FeatureUtilities.ConstructionWorkAxis); } double count1 = (double)(AsmFeature.XCount.Value) - elementIdx + 1; //Check it's not the last pattern element if (count1 != 0 && elementIdx != (double)(AsmFeature.XCount.Value)) { RectangularPatternFeatureData featureData = newRectangularPatternFeatureData(); featureData.xCount = count1; featureData.xSpacing = AsmFeature.XSpacing.Value; featureData.naturalXDirection = AsmFeature.NaturalXDirection; featureData.xDirectionSpacingType = AsmFeature.XDirectionSpacingType; featureData.xDirAxis = xDirAxis; featureData.xDirStartPoint3D = xDirStartPoint3D; FeaturesDataList.Add(featureData); } double count2 = elementIdx; //Check it's not the first pattern element if (count2 != 0 && elementIdx != 1) { RectangularPatternFeatureData featureData = newRectangularPatternFeatureData(); featureData.xCount = count2; featureData.xSpacing = AsmFeature.XSpacing.Value; featureData.naturalXDirection = !AsmFeature.NaturalXDirection; featureData.xDirectionSpacingType = AsmFeature.XDirectionSpacingType; featureData.xDirAxis = xDirAxis; featureData.xDirStartPoint3D = xDirStartPoint3D; FeaturesDataList.Add(featureData); } } //Only along Y Axis if (AsmFeature.YDirectionEntity != null && AsmFeature.XDirectionEntity == null) { } //Only along both Axes if (AsmFeature.XDirectionEntity != null && AsmFeature.YDirectionEntity != null) { } foreach (RectangularPatternFeatureData featureData in FeaturesDataList) { RectangularPatternFeature newFeature = partCompDef.Features.RectangularPatternFeatures.Add(ParentFeatures, featureData.xDirAxis, featureData.naturalXDirection, featureData.xCount, featureData.xSpacing, featureData.xDirectionSpacingType, featureData.xDirStartPoint3D, featureData.yDirAxis, featureData.naturalYDirection, featureData.yCount, featureData.ySpacing, featureData.yDirectionSpacingType, featureData.yDirStartPoint3D, AsmFeature.ComputeType, AsmFeature.OrientationMethod); foreach (FeaturePatternElement element in newFeature.PatternElements) { if (newFeature.HealthStatus == HealthStatusEnum.kUpToDateHealth) { break; } if (element.Faces.Count == 0 && element.Index != 1) { element.Suppressed = true; } } if (newFeature != null) { newFeatures.Add(newFeature); } } return(newFeatures.ToArray()); }
public static void addProjectCut(PartDocument oDoc, WorkPlane oWpReference, bool manual = false) { SheetMetalComponentDefinition oCompDef = (SheetMetalComponentDefinition)oDoc.ComponentDefinition; WorkPlane oWpWork = oCompDef.WorkPlanes.AddByPlaneAndOffset(oWpReference, 0); oWpWork.Name = "wpWork"; oWpWork.Visible = false; PlanarSketch oSketch = oCompDef.Sketches.Add(oWpWork); ProjectedCut oProjectCut = oSketch.ProjectedCuts.Add(); if (!manual) { int tmpSegmThk = countThicknessSegment(oProjectCut.SketchEntities); int loop = 0; double offset = 1; while (tmpSegmThk != 2) { // Devo spostare il piano se ci sono cose nel mezzo oWpWork.SetByPlaneAndOffset(oWpReference, offset); tmpSegmThk = countThicknessSegment(oProjectCut.SketchEntities); loop++; offset += offset; if (loop == 20) { throw new Exception("Numero massimo offset piano."); } } oProjectCut.Delete(); oProjectCut = oSketch.ProjectedCuts.Add(); } List <ObjectCollection> dataLine = splittoLinea(oProjectCut.SketchEntities); ObjectCollection linea = lengthPerimetro(); TransientGeometry oTransGeom = iApp.TransientGeometry; UnitVector oNormalVector = oSketch.PlanarEntityGeometry.Normal; UnitVector2d oLineDir = linea[1].Geometry.Direction; UnitVector oLineVector = (UnitVector)oTransGeom.CreateUnitVector(oLineDir.X, oLineDir.Y, 0); UnitVector oOffsetVector = (UnitVector)oLineVector.CrossProduct(oNormalVector); UnitVector oDesiredVector = (UnitVector)oTransGeom.CreateUnitVector(0, 1, 0); bool bNaturalOffsetDir; if (oOffsetVector.IsEqualTo(oDesiredVector)) { bNaturalOffsetDir = true; } else { bNaturalOffsetDir = false; } SketchEntitiesEnumerator oSSketchEntitiesEnum = oSketch.OffsetSketchEntitiesUsingDistance(linea, 0.5, bNaturalOffsetDir, false); oProjectCut.Delete(); styleSketch(oSketch.SketchEntities); int countThicknessSegment(SketchEntitiesEnumerator oSketchEntities) { int result = 0; foreach (SketchEntity e in oSketchEntities) { if (e.Type == ObjectTypeEnum.kSketchLineObject) { SketchLine oSketchLine = (SketchLine)e; double length = Math.Round(oSketchLine.Length * 100) / 100; if (length == Math.Round(oCompDef.Thickness.Value * 100) / 100) { result++; } } } return(result); } List <ObjectCollection> splittoLinea(SketchEntitiesEnumerator oSketchEntities) { List <ObjectCollection> tmp = new List <ObjectCollection>(); tmp.Add(iApp.TransientObjects.CreateObjectCollection()); tmp.Add(iApp.TransientObjects.CreateObjectCollection()); tmp.Add(iApp.TransientObjects.CreateObjectCollection()); int indice = 0; foreach (SketchEntity oSketchEntity in oSketchEntities) { if (oSketchEntity.Type != ObjectTypeEnum.kSketchPointObject) { if (oSketchEntity.Type == ObjectTypeEnum.kSketchLineObject) { SketchLine oSketchLine = (SketchLine)oSketchEntity; if (Math.Round(oSketchLine.Length * 100) / 100 == Math.Round(oCompDef.Thickness.Value * 100) / 100) { if (indice == 0) { indice = 1; } else { indice = 2; } } else { tmp[indice].Add(oSketchEntity); } } if (oSketchEntity.Type == ObjectTypeEnum.kSketchArcObject) { tmp[indice].Add(oSketchEntity); } } } foreach (SketchEntity oSketchEntity in tmp[0]) { tmp[2].Add(oSketchEntity); } List <ObjectCollection> result = new List <ObjectCollection>(); result.Add(tmp[1]); result.Add(tmp[2]); return(result); } void styleSketch(SketchEntitiesEnumerator oSketchEntities) { foreach (SketchEntity oSe in oSketchEntities) { if (oSe.Type == ObjectTypeEnum.kSketchLineObject) { SketchLine se = (SketchLine)oSe; se.OverrideColor = iApp.TransientObjects.CreateColor(0, 0, 255); se.LineType = LineTypeEnum.kDashDottedLineType; } else if (oSe.Type == ObjectTypeEnum.kSketchArcObject) { SketchArc sa = (SketchArc)oSe; sa.OverrideColor = iApp.TransientObjects.CreateColor(0, 0, 255); sa.LineType = LineTypeEnum.kDashDottedLineType; } } } ObjectCollection lengthPerimetro() { double l0 = 0; double l1 = 0; foreach (SketchEntity oSE in dataLine[0]) { if (oSE.Type == ObjectTypeEnum.kSketchLineObject) { SketchLine se = (SketchLine)oSE; l0 = l0 + se.Length; } else if (oSE.Type == ObjectTypeEnum.kSketchArcObject) { SketchArc se = (SketchArc)oSE; l0 = l0 + se.Length; } } foreach (SketchEntity oSE in dataLine[1]) { if (oSE.Type == ObjectTypeEnum.kSketchLineObject) { SketchLine se = (SketchLine)oSE; l1 = l1 + se.Length; } else if (oSE.Type == ObjectTypeEnum.kSketchArcObject) { SketchArc se = (SketchArc)oSE; l1 = l1 + se.Length; } } if (l0 > l1) { return(dataLine[0]); } else { return(dataLine[1]); } } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Use: Returns two orthogonal vectors depending on the input normal // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static void GetOrthoBase(UnitVector normal, out UnitVector xAxis, out UnitVector yAxis) { xAxis = GetOrthoVector(normal); yAxis = normal.CrossProduct(xAxis); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public bool UpdateFeatureFromAsm(PartFeature AsmFeature, PartFeature PartFeature, Matrix invTransfo) { ExtrudeFeature asmFeature = AsmFeature as ExtrudeFeature; ExtrudeFeature partFeature = PartFeature as ExtrudeFeature; try { PartComponentDefinition partCompDef = partFeature.Parent as PartComponentDefinition; PlanarSketch partSketch = partFeature.Profile.Parent as PlanarSketch; UnitVector xAxis = null; UnitVector yAxis = null; FeatureUtilities.UpdateSketch(asmFeature.Profile.Parent as PlanarSketch, partSketch, invTransfo, out xAxis, out yAxis); Document asmDocument = asmFeature.Parent.Document as Document; bool suppressed = partFeature.Suppressed; //Feature needs to be suppressed if we change the Profile partFeature.Suppressed = true; Profile newPartProfile = FeatureUtilities.UpdateProfile(asmDocument, partCompDef.Document as Document, asmFeature.Profile, partFeature.Profile, true); if (newPartProfile != null) { partFeature.Profile = newPartProfile; } partFeature.Suppressed = suppressed; partFeature.TaperAngle.Value = asmFeature.TaperAngle.Value; if (FeatureUtilities.UpdateFeatureExtent(asmFeature.Extent, partFeature.Extent, invTransfo)) { return(true); } switch (asmFeature.ExtentType) { case PartFeatureExtentEnum.kThroughAllExtent: { ThroughAllExtent asmThroughAllExtent = asmFeature.Extent as ThroughAllExtent; partFeature.SetThroughAllExtent(asmThroughAllExtent.Direction); break; } case PartFeatureExtentEnum.kDistanceExtent: { DistanceExtent asmDistanceExtent = asmFeature.Extent as DistanceExtent; partFeature.SetDistanceExtent(asmDistanceExtent.Distance.Value, asmDistanceExtent.Direction); break; } case PartFeatureExtentEnum.kToExtent: { ToExtent asmToExtent = asmFeature.Extent as ToExtent; object ToEntity = FeatureUtilities.CopyFromToEntity(asmToExtent.ToEntity, partCompDef, invTransfo); partFeature.SetToExtent(ToEntity, false); break; } case PartFeatureExtentEnum.kFromToExtent: { FromToExtent asmFromToExtent = asmFeature.Extent as FromToExtent; object FromEntity = FeatureUtilities.CopyFromToEntity(asmFromToExtent.FromFace, partCompDef, invTransfo); object ToEntity = FeatureUtilities.CopyFromToEntity(asmFromToExtent.ToFace, partCompDef, invTransfo); partFeature.SetFromToExtent(FromEntity, false, ToEntity, false); break; } default: return(false); } return(true); } catch { //Something went wrong return(false); } }
/// <summary> /// Returns two orthogonal vectors depending on the input normal /// </summary> /// <returns>Void</returns> public static void GetOrthoBase(UnitVector normal, out UnitVector xAxis, out UnitVector yAxis) { xAxis = GetOrthoVector(normal); yAxis = normal.CrossProduct(xAxis); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public PartFeature CopyFeature(PartComponentDefinition partCompDef, PartFeature AsmFeature, Matrix invTransfo) { try { ExtrudeFeature extrudeFeature = AsmFeature as ExtrudeFeature; ExtrudeFeature newFeature = null; UnitVector xAxis = null; UnitVector yAxis = null; PlanarSketch asmSketch = extrudeFeature.Profile.Parent as PlanarSketch; PlanarSketch partSketch = FeatureUtilities.CopySketch(partCompDef, asmSketch, invTransfo, out xAxis, out yAxis); ObjectCollection pathSegments = FeatureUtilities.GetPathSegments(extrudeFeature.Profile, partSketch); Profile partProfile = partSketch.Profiles.AddForSolid(true, pathSegments, null); FeatureUtilities.CopyProfile(extrudeFeature.Profile, partProfile); switch (extrudeFeature.ExtentType) { case PartFeatureExtentEnum.kThroughAllExtent: { ThroughAllExtent ThroughAllExtent = extrudeFeature.Extent as ThroughAllExtent; newFeature = partCompDef.Features.ExtrudeFeatures.AddByThroughAllExtent(partProfile, ThroughAllExtent.Direction, extrudeFeature.Operation, extrudeFeature.TaperAngle.Value); break; } case PartFeatureExtentEnum.kDistanceExtent: { DistanceExtent DistanceExtent = extrudeFeature.Extent as DistanceExtent; newFeature = partCompDef.Features.ExtrudeFeatures.AddByDistanceExtent(partProfile, DistanceExtent.Distance.Value, DistanceExtent.Direction, extrudeFeature.Operation, extrudeFeature.TaperAngle.Value); break; } case PartFeatureExtentEnum.kToExtent: { ToExtent ToExtent = extrudeFeature.Extent as ToExtent; object ToEntity = FeatureUtilities.CopyFromToEntity(ToExtent.ToEntity, partCompDef, invTransfo); newFeature = partCompDef.Features.ExtrudeFeatures.AddByToExtent(partProfile, ToEntity, extrudeFeature.Operation, false, extrudeFeature.TaperAngle.Value); break; } case PartFeatureExtentEnum.kFromToExtent: { FromToExtent FromToExtent = extrudeFeature.Extent as FromToExtent; object FromEntity = FeatureUtilities.CopyFromToEntity(FromToExtent.FromFace, partCompDef, invTransfo); object ToEntity = FeatureUtilities.CopyFromToEntity(FromToExtent.ToFace, partCompDef, invTransfo); newFeature = partCompDef.Features.ExtrudeFeatures.AddByFromToExtent(partProfile, FromEntity, false, ToEntity, false, extrudeFeature.Operation, extrudeFeature.TaperAngle.Value); break; } default: break; } return(newFeature as PartFeature); } catch { return(null); } }
private void HandleCollision() { Vector2 distance = LocalPosition - PreviousLocation; int stateCount = (int)distance.Length() + 1; Vector2 currentPosition = LocalPosition; int count; for (count = 0; count < stateCount; count++) { LocalPosition = PreviousLocation + count * UnitVelocity; var normals = new List <Vector2>(); if (HitBottomWall()) { Drop(); break; } if (HitRightWall()) { normals.Add(UnitVector.Angle180); } if (HitLeftWall()) { normals.Add(UnitVector.Angle0); } if (HitTopWall()) { normals.Add(UnitVector.Angle270); } RefreshTouchedBrick(); normals.AddRange(ListBrick.Instance.GetNormalVectorsWhenTouchBall(this)); if (normals.Any()) { Vector2 combineNormal = normals[0]; foreach (var normal in normals) { combineNormal = UnitVector.Combine(combineNormal, normal); } LocalPosition = PreviousLocation + (count - 1) * UnitVelocity; if (Reflect(combineNormal)) { break; } else { RevertTouchedBricks(); } } ListItemAddBall.Instance.CheckCollisionWithBall(this); ListItemClearRow.Instance.CheckCollisionWithBall(this); ListItemClearColumn.Instance.CheckCollisionWithBall(this); ListItemAddCoin.Instance.CheckCollisionWithBall(this); if (ListItemSpreadBall.Instance.CheckCollisionWithBall(this)) { break; } } if (count == stateCount) { LocalPosition = currentPosition; } }
////////////////////////////////////////////////////////////////////////////////////////////// // Draws dimension graphics // ////////////////////////////////////////////////////////////////////////////////////////////// DimData DrawDimension(Point point1, Point point2, Point dimText, Vector normal) { // Compute extension points Vector xAxis = point1.VectorTo(point2); Vector upVector = normal.CrossProduct(xAxis); upVector.Normalize(); Plane plane = _Tg.CreatePlane(point1, normal); Point dimTextProj = AdnInventorUtilities.ProjectOnPlane(dimText, plane); double dotP1 = point1.VectorTo(dimTextProj).DotProduct(upVector); double dotP2 = point2.VectorTo(dimTextProj).DotProduct(upVector); Point extP1 = _Tg.CreatePoint( point1.X + upVector.X * dotP1, point1.Y + upVector.Y * dotP1, point1.Z + upVector.Z * dotP1); Point extP2 = _Tg.CreatePoint( point2.X + upVector.X * dotP2, point2.Y + upVector.Y * dotP2, point2.Z + upVector.Z * dotP2); double dimValue = extP1.DistanceTo(extP2); GraphicsNode node = _clientGraphicsMng.CreateNewGraphicsNode(); LineGraphics extLine1 = _clientGraphicsMng.DrawLine( AdnInventorUtilities.ToArray(point1), AdnInventorUtilities.ToArray(extP1), node); LineGraphics extLine2 = _clientGraphicsMng.DrawLine( AdnInventorUtilities.ToArray(point2), AdnInventorUtilities.ToArray(extP2), node); LineGraphics dimLine = _clientGraphicsMng.DrawLine( AdnInventorUtilities.ToArray(extP1), AdnInventorUtilities.ToArray(extP2), node); extLine1.LineType = LineTypeEnum.kDashedLineType; extLine2.LineType = LineTypeEnum.kDashedLineType; UnitVector v = extP1.VectorTo(extP2).AsUnitVector(); double length = 20.0; double radius = 7.0; Point bottom1 = _Tg.CreatePoint( extP1.X + length * v.X, extP1.Y + length * v.Y, extP1.Z + length * v.Z); Point bottom2 = _Tg.CreatePoint( extP2.X - length * v.X, extP2.Y - length * v.Y, extP2.Z - length * v.Z); SurfaceBody cone1 = _TBrep.CreateSolidCylinderCone( bottom1, extP1, radius, radius, 0.0, null); SurfaceBody cone2 = _TBrep.CreateSolidCylinderCone( bottom2, extP2, radius, radius, 0.0, null); GraphicsNode dimNode = _clientGraphicsMng.CreateNewGraphicsNode(); SurfaceGraphics arrow1 = _clientGraphicsMng.DrawSurface(cone1, dimNode); SurfaceGraphics arrow2 = _clientGraphicsMng.DrawSurface(cone2, dimNode); arrow1.SetTransformBehavior(extP1, DisplayTransformBehaviorEnum.kPixelScaling, 1.0); arrow2.SetTransformBehavior(extP2, DisplayTransformBehaviorEnum.kPixelScaling, 1.0); TextGraphics text = _clientGraphicsMng.DrawText( AdnInventorUtilities.GetStringFromAPILength(dimValue), false, dimNode); text.Font = "Arial"; text.Bold = false; text.Italic = false; text.FontSize = 20; text.PutTextColor(221, 0, 0); text.VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextMiddle; text.HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextLeft; Point txtPos = _Tg.CreatePoint( (extP1.X + extP2.X) * 0.5, (extP1.Y + extP2.Y) * 0.5, (extP1.Z + extP2.Z) * 0.5); text.Anchor = txtPos; text.SetTransformBehavior(txtPos, DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling, 1.0); node.Selectable = true; dimNode.Selectable = true; return(new DimData(point1, point2, extLine1, extLine2, dimLine, dimNode)); }