public static Plane GetPlaneCenteredOnFace(DesignFace face) { PointUV centerUV = face.Shape.BoxUV.Center; SurfaceEvaluation evaluation = face.Shape.Geometry.Evaluate(centerUV); Point point = evaluation.Point; Direction dirU = (face.Shape.Geometry.Evaluate(PointUV.Create(centerUV.U + 0.001, centerUV.V)).Point.Vector - face.Shape.Geometry.Evaluate(PointUV.Create(centerUV.U - 0.001, centerUV.V)).Point.Vector).Direction; Direction dirVTemp = Direction.Cross(evaluation.Normal, dirU); if (face.Shape.Geometry as Plane != null) { if (!Accuracy.Equals(Vector.Dot(dirU.UnitVector, Direction.DirZ.UnitVector), 0.0)) // if our U direction has a Z component, the text might be slanted { if (Accuracy.Equals(Vector.Dot(dirVTemp.UnitVector, Direction.DirZ.UnitVector), 0.0)) // if our V direction has no Z component, use it { dirU = dirVTemp; } } } if (face.Shape.Geometry as Cylinder != null) { dirU = dirVTemp; } dirVTemp = Direction.Cross(evaluation.Normal, dirU); if (Vector.Dot(dirVTemp.UnitVector, Direction.DirZ.UnitVector) < 0.0) // Prevent upside-down notes { dirU = -dirU; } return(Plane.Create(Frame.Create(point, dirU, Direction.Cross(evaluation.Normal, dirU)))); }
public void Reset() { for (int i = 0; i < iSteps * 2; i++) { double u = 2 * Math.PI * (double)i / iSteps; vParameters.Add(new CircularList <double>(jSteps)); tabAngles.Add(new CircularList <double>(jSteps)); points.Add(new CircularList <Point>(jSteps)); for (int j = 0; j < jSteps; j++) { vParameters[i].Add(2 * Math.PI * ((double)j - 0.5) / jSteps); // tabAngles[i].Add((double) 5 / 6 * Math.PI); tabAngles[i].Add((double)Math.PI); points[i].Add(Evaluate(PointUV.Create(vParameters[i][j], u), p, q, circleAngle, inverseOffset, true) * scale); } } //for (int i = 0; i < iSteps * 2; i++) { // double u = 2 * Math.PI * (double) i / iSteps; // tabAngles.Add(new CircularList<double>(jSteps)); // for (int j = 0; j < jSteps; j++) { // int iOther = (j % 2 != 0) ? i - 1 : i + 1; // double l = (points[i][j + 1] - points[i][j]).Magnitude; // double d = (new[] { points[i][j + 1], points[i][j] }.Average() - // new[] { points[iOther][j + 1], points[iOther][j] }.Average()).Magnitude; // double angle = Math.PI - 2 * Math.Asin(l * d / (Math.Pow(l / 2, 2) + Math.Pow(d, 2))); // tabAngles[i][j] = angle; // } //} }
public static Direction GetNormal(PointUV uv, double p, double q, double circleAngle, Vector inverseOffset, bool isInverted) { double delta = 0.001; var deltaU = VectorUV.Create(delta, 0); var deltaV = VectorUV.Create(0, delta); PointUV uv00 = uv - deltaU; PointUV uv01 = uv + deltaU; PointUV uv10 = uv - deltaV; PointUV uv11 = uv + deltaV; Point pCenter = Lawson.Evaluate(uv, p, q, circleAngle, inverseOffset, isInverted); var pxxs = new Point[] { Lawson.Evaluate(uv00, p, q, circleAngle, inverseOffset, isInverted), Lawson.Evaluate(uv01, p, q, circleAngle, inverseOffset, isInverted), Lawson.Evaluate(uv10, p, q, circleAngle, inverseOffset, isInverted), Lawson.Evaluate(uv11, p, q, circleAngle, inverseOffset, isInverted) }; var sum = Vector.Zero; foreach (Point pxx in pxxs) { sum += pxx - pCenter; } if (sum != Vector.Zero) { return(sum.Direction); } return(Vector.Cross(pxxs[1] - pxxs[0], pxxs[1] - pxxs[2]).Direction); }
private static Point[] GetChainAtVWhere(double v, Func <PointUV, bool> condition, FaceToolPath toolPath) { List <Point> points = new List <Point>(); double u = toolPath.StartU; while (u <= toolPath.EndU) { PointUV pointUV; if (!toolPath.Surface.TryOffsetParam(PointUV.Create(u, v), DirectionUV.DirU, toolPath.CuttingParameters.Increment, out pointUV)) { break; } u = pointUV.U; if (!condition(pointUV)) { continue; } ToolEvaluation eval = Evaluate(pointUV, toolPath); points.Add(eval.CenterPoint); } return(points.ToArray()); }
private static PointUV GetCenterOfMass(UnmanagedImage image, Rectangle rectangle) { #if false centerX = rectangle.X + rectangle.Width / 2; centerY = rectangle.Y + rectangle.Height / 2; #else double xTotal = 0; double yTotal = 0; double massTotal = 0; Bitmap bitmap = image.ToManagedImage(); for (int x = 0; x < rectangle.Width; x++) { for (int y = 0; y < rectangle.Height; y++) { double value = bitmap.GetPixel(rectangle.X + x, rectangle.Y + y).R; massTotal += value; xTotal += x * value; yTotal += y * value; } } return(PointUV.Create( xTotal / massTotal + rectangle.X, yTotal / massTotal + rectangle.Y )); #endif }
private static ToolEvaluation Evaluate(PointUV pointUV, FaceToolPath toolPath) { SurfaceEvaluation eval = toolPath.Surface.Evaluate(pointUV); Point surfacePoint = eval.Point; Direction surfaceNormal = toolPath.IsNormalFlipped ? -eval.Normal : eval.Normal; return(new ToolEvaluation(surfacePoint + toolPath.CuttingTool.Radius * surfaceNormal, surfacePoint, surfaceNormal)); }
public static Graphic GetGraphic(double p, double q, double circleAngle, Vector inverseOffset) { var graphics = new List <Graphic>(); int bandCount = 2; int iSteps = bandCount * 32; //32 int jSteps = 34; //34 double uStep = 2 * Math.PI / iSteps; double vStep = 2 * Math.PI / jSteps; bool uSwap = false, vSwap = false; for (int j = 0; j < jSteps; j++) { double v = 2 * Math.PI * j / jSteps; for (int i = 0; i < iSteps; i++) { double u = 2 * Math.PI * i / iSteps; Direction n00, n10, n11, n01; Point p00 = Lawson.Evaluate(PointUV.Create(u, v), p, q, circleAngle, inverseOffset, true, out n00); Point p10 = Lawson.Evaluate(PointUV.Create(u + uStep, v), p, q, circleAngle, inverseOffset, true, out n10); Point p11 = Lawson.Evaluate(PointUV.Create(u + uStep, v + vStep), p, q, circleAngle, inverseOffset, true, out n11); Point p01 = Lawson.Evaluate(PointUV.Create(u, v + vStep), p, q, circleAngle, inverseOffset, true, out n01); var facetVertices = new List <FacetVertex>(); facetVertices.Add(new FacetVertex(p00, n00)); facetVertices.Add(new FacetVertex(p10, n10)); facetVertices.Add(new FacetVertex(p11, n11)); facetVertices.Add(new FacetVertex(p01, n01)); var facets = new List <Facet>(); facets.Add(new Facet(0, 1, 2)); facets.Add(new Facet(0, 2, 3)); HSBColor hsbFill = new HSBColor(Window.ActiveWindow.ActiveLayer.GetColor(null)); hsbFill.H = (float)(u / 2 / Math.PI * 360); hsbFill.A = vSwap ? 127 : 255; HSBColor hsbLine = new HSBColor(System.Drawing.Color.MidnightBlue); hsbLine.H = (float)(u / 2 / Math.PI * 360); var style = new GraphicStyle { EnableDepthBuffer = true, LineColor = hsbLine.Color, LineWidth = 1, FillColor = hsbFill.Color }; graphics.Add(Graphic.Create(style, MeshPrimitive.Create(facetVertices, facets))); uSwap = !uSwap; } vSwap = !vSwap; } return(Graphic.Create(null, null, graphics)); }
// creates a new custom object and a wrapper for it protected OscillatorPart(HandleTypeEnum handleType, IDesignFace iDesignFace, PointUV pointUV, double span, double position) : base(iDesignFace.GetAncestor <Part>()) { this.handleTypeInt = (int)handleType; this.iDesignFace = iDesignFace; this.pointUV = pointUV; this.span = span; this.position = position; }
static Point Figure8(PointUV uv) { double u = uv.U; double v = uv.V; const double t = 1.5; return(Point.Create( Math.Sin(v) * (4 + 2 * Math.Cos(u) * Math.Cos(t * v) - Math.Sin(2 * u) * Math.Sin(t * v)), Math.Cos(v) * (4 + 2 * Math.Cos(u) * Math.Cos(t * v) - Math.Sin(2 * u) * Math.Sin(t * v)), 2 * Math.Cos(u) * Math.Sin(t * v) + Math.Sin(2 * u) * Math.Cos(t * v) )); }
public static Point Evaluate(PointUV uv, double p, double q, double circleAngle, Vector inverseOffset, bool isInverted) { double u = uv.U; double v = uv.V; Circle circle = Circle.Create(Frame.World, 1); // spiraly things circle = circle.CreateTransformedCopy(Matrix.CreateRotation(Line.Create(Point.Origin, Direction.DirY), Math.PI / 4)); circle = circle.CreateTransformedCopy(Matrix.CreateRotation(Line.Create(Point.Origin, Direction.DirY), circleAngle)); return(LawsonTransform(circle.Evaluate(u).Point, v, p, q, inverseOffset, isInverted)); }
public static void Print(this Cone cone, Part part = null) { double startV = -Math.Cos(cone.HalfAngle) * cone.Radius; double endV = 0; ShapeHelper.CreateRevolvedCurve(cone.Axis, CurveSegment.Create( cone.Evaluate(PointUV.Create(0, startV)).Point, cone.Evaluate(PointUV.Create(0, endV)).Point )).Print(part); // Circle.Create(cone.Frame, cone.Radius).Print(part); // CurveSegment.Create(cone.Evaluate(PointUV.Create(0, 0)).Point, cone.Evaluate(PointUV.Create(Math.PI / 2, 0)).Point).Print(part); }
public static double Bilinear(BoxUV bounds, double[,] values, PointUV t) { double divisor = (double) 1 / bounds.RangeU.Span / bounds.RangeV.Span; double dx1 = t.U - bounds.RangeU.Start; double dx2 = bounds.RangeU.End - t.U; double dy1 = t.V - bounds.RangeV.Start; double dy2 = bounds.RangeV.End - t.V; return ( values[0, 0] * dx2 * dy2 + values[1, 0] * dx1 * dy2 + values[0, 1] * dx2 * dy1 + values[1, 1] * dx1 * dy1 ) * divisor; }
static Point ToPoincare(PointUV uv) { double u = uv.U; double v = uv.V; double sumSquares = 1 - u * u - v * v; if (sumSquares == 0) return Point.Origin; return Point.Create( 2 * u / sumSquares, 2 * v / sumSquares, 0 ); }
public static double Bilinear(BoxUV bounds, double[,] values, PointUV t) { double divisor = (double)1 / bounds.RangeU.Span / bounds.RangeV.Span; double dx1 = t.U - bounds.RangeU.Start; double dx2 = bounds.RangeU.End - t.U; double dy1 = t.V - bounds.RangeV.Start; double dy2 = bounds.RangeV.End - t.V; return(( values[0, 0] * dx2 * dy2 + values[1, 0] * dx1 * dy2 + values[0, 1] * dx2 * dy1 + values[1, 1] * dx1 * dy1 ) * divisor); }
public static void AnnotateFace(Part targetPart, DesignFace face, string comment, double textHeight, Direction?direction) { string annotationPlanePartName = "Annotation Planes"; Part part = null; foreach (Part testPart in targetPart.Document.Parts) { if (testPart.Name == annotationPlanePartName) { part = testPart; } } if (part == null) { part = Part.Create(targetPart.Document, annotationPlanePartName); Component component = Component.Create(targetPart, part); } Plane plane = GetPlaneCenteredOnFace(face); if (direction != null) { Direction dirX = Direction.DirX; if (direction.Value != Direction.DirZ) { dirX = direction.Value.ArbitraryPerpendicular; } plane = Plane.Create(Frame.Create(plane.Frame.Origin, dirX, Direction.Cross(direction.Value, dirX))); } Layer planeLayer = CreateOrGetLayer(targetPart.Document, Resources.AnnotationPlaneLayerNameText, System.Drawing.Color.Black); planeLayer.SetVisible(null, false); Layer noteLayer = CreateOrGetLayer(targetPart.Document, Resources.AnnotationLayerNameText, System.Drawing.Color.DarkRed); DatumPlane datum = DatumPlane.Create(part, Resources.AnnotationPlaneNameText, plane); datum.Layer = planeLayer; PointUV location = PointUV.Origin; Note note = Note.Create(datum, location, TextPoint.Center, textHeight, comment); note.SetFontName(DraftingFont.Asme); note.Layer = noteLayer; note.SetColor(null, null); }
protected override bool OnDragStart(ScreenPoint cursorPos, Line cursorRay) { //SelectionTypes = new Type[0]; // disable preselection while dragging OscillatorPart oscillatorPart = OscillatorPart.GetWrapper(InteractionContext.Preselection as CustomObject); if (oscillatorPart == null) { return(false); } Point?pointOnCustom = InteractionContext.PreselectionPoint; if (pointOnCustom == null) { oscillatorPart = null; return(false); } switch (oscillatorPart.HandleType) { case HandleTypeEnum.Base: var iDesignFace = InteractionContext.Preselection as IDesignFace; if (iDesignFace == null) { return(false); } SurfaceEvaluation eval = iDesignFace.Shape.GetSingleRayIntersection(cursorRay); if (eval == null) { return(false); } oscillatorIDesignFace = iDesignFace; oscillatorPointUV = eval.Param; StatusText = "Drag to move the oscillator."; break; case HandleTypeEnum.Start: case HandleTypeEnum.End: break; } return(false); }
private void ProcessPart(Document doc, Part part, DrawingSheet sheetTemplate) { var sheet = DrawingSheet.Create(doc, sheetTemplate); var sheetMajorDim = Math.Max(sheet.Width, sheet.Height); var frontOrigin = PointUV.Create(0.1 * sheetMajorDim, 0.1 * sheetMajorDim); var viewFront = DrawingView.CreateGeneralView(sheet, part, ViewProjection.Front, frontOrigin); var frontBox = viewFront.Extent; var viewTop = DrawingView.CreateProjectedView(viewFront, PointUV.Create(frontBox.Center.U, frontBox.Center.V + frontBox.RangeV.Span)); var viewRight = DrawingView.CreateProjectedView(viewFront, PointUV.Create(frontBox.Center.U + frontBox.RangeU.Span, frontBox.Center.V)); var isoOrigin = PointUV.Create(0.75 * sheetMajorDim, 0.75 * sheetMajorDim); var viewIso = DrawingView.CreateGeneralView(sheet, part, ViewProjection.Isometric, isoOrigin); var drawingStyle = SupportedViewStyles[DrawingStyle.SelectedIndex].Value; viewFront.Style = viewTop.Style = viewRight.Style = viewIso.Style = drawingStyle; }
protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect) { //isDetectingCollisions = Booleans[Resources.DetectCollisionsText].Value; //isCreatingDashes = Booleans[Resources.CreateDashesText].Value; Part part = Window.ActiveWindow.Scene as Part; if (part == null) { return; } Layer curveLayer = NoteHelper.CreateOrGetLayer(Window.ActiveWindow.Document, Resources.FlatMediumEngravingLayerName, System.Drawing.Color.Green); Layer planeLayer = NoteHelper.CreateOrGetLayer(part.Document, Resources.AnnotationPlanesLayerName, Color.Gray); planeLayer.SetVisible(null, false); foreach (Component component in part.Components) { Body body = component.Content.Bodies.First().Master.Shape.Copy(); body.Transform(component.Content.TransformToMaster.Inverse); Face startFace = body.Faces.First(); string name = component.Content.Master.Name; FlatPattern flatPattern = new FlatPattern(body, startFace, isDetectingCollisions, false, 0, 0, name); flatPattern.Render(); DatumPlane datumPlane = DatumPlane.Create(flatPattern.FlatPart, Resources.AnnotationPlaneName, flatPattern.PaperPlane); datumPlane.Layer = planeLayer; PointUV center = flatPattern.PaperPlane.ProjectPoint(flatPattern.GetBoundingBox(Matrix.Identity).Center).Param; Note note = Note.Create(datumPlane, center, TextPoint.Center, 0.01, name); note.Layer = NoteHelper.CreateOrGetLayer(part.Document, Resources.AnnotationLayerName, System.Drawing.Color.DarkViolet); foreach (FlatBody flatBody in flatPattern.FlatBodies) { foreach (FlatFace flatFace in flatBody.FlatFaces) { foreach (ITrimmedCurve iTrimmedCurve in part.Curves.Select(c => c.Shape).Where(c => c.AreEndPointsOnFace(flatFace.SourceFace))) { var designCurve = DesignCurve.Create(flatBody.FlatPart, iTrimmedCurve); designCurve.Transform(flatFace.Transform); designCurve.Layer = curveLayer; } } } } }
protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect) { Window activeWindow = Window.ActiveWindow; Part part = activeWindow.Scene as Part; int steps = 16; double step = (double)1 / steps; for (int i = -steps; i <= steps; i++) { double u = (double)i * step; List <List <Body> > bands = new List <List <Body> >(); for (int j = -steps; j <= steps; j++) { double v = (double)j * step; PointUV uv00 = PointUV.Create(u, v); PointUV uv01 = PointUV.Create(u, v + step); PointUV uv11 = PointUV.Create(u + step, v + step); PointUV uv10 = PointUV.Create(u + step, v); if ( uv00.MagnitudeSquared() > 1 || uv01.MagnitudeSquared() > 1 || uv11.MagnitudeSquared() > 1 || uv10.MagnitudeSquared() > 1 ) { continue; } Point p00 = ToPoincare(uv00); Point p01 = ToPoincare(uv01); Point p11 = ToPoincare(uv11); Point p10 = ToPoincare(uv10); DesignCurve.Create(part, CurveSegment.Create(p00, p01)); DesignCurve.Create(part, CurveSegment.Create(p00, p10)); } } activeWindow.ZoomExtents(); }
static Frame?GetFrameFromPoint(IDesignFace designFace, Point startPoint) { SurfaceEvaluation evaluation = designFace.Shape.Geometry.ProjectPoint(startPoint); Point point = evaluation.Point; PointUV pointUV = evaluation.Param; Direction dirU = (designFace.Shape.Geometry.Evaluate(PointUV.Create(pointUV.U + 0.0001, pointUV.V)).Point.Vector - designFace.Shape.Geometry.Evaluate(PointUV.Create(pointUV.U - 0.0001, pointUV.V)).Point.Vector).Direction; Direction dirV = Direction.Cross(evaluation.Normal, dirU); Frame frame = Frame.Create(point, dirU, dirV); if (designFace.Shape.IsReversed) { return(Frame.Create(frame.Origin, -frame.DirX, frame.DirY)); } return(frame); }
static Point ToPoincare(PointUV uv) { double u = uv.U; double v = uv.V; double sumSquares = 1 - u * u - v * v; if (sumSquares == 0) { return(Point.Origin); } return(Point.Create( 2 * u / sumSquares, 2 * v / sumSquares, 0 )); }
protected override void OnDragMove(ScreenPoint cursorPos, Line cursorRay) { if (oscillatorParts == null || oscillatorParts.Count == 0) { return; } var iDesignFace = InteractionContext.Preselection as IDesignFace; if (iDesignFace == null) { return; } oscillatorIDesignFace = iDesignFace; oscillatorPointUV = oscillatorIDesignFace.Shape.GetSingleRayIntersection(cursorRay).Param; Apply("Modify Oscillator"); }
public static Point[] GetInitialPositions(Body body, int count, bool useSeed) { Point[] positions = new Point[count]; Box box = body.GetBoundingBox(Matrix.Identity); Point start = box.MinCorner; Vector span = box.MaxCorner - start; start = start - span / 2; span *= 2; Random random = useSeed ? new Random(body.GetHashCode()) : new Random(); int i = 0; var faceAreas = new Dictionary <double, Face>(); double totalArea = body.SurfaceArea; double runningArea = 0; foreach (Face face in body.Faces) { runningArea += face.Area; faceAreas[runningArea / totalArea] = face; } while (i < positions.Length) { // positions[i++] = body.ProjectPointToShell(start + Vector.Create(span.X * random.NextDouble(), span.Y * random.NextDouble(), span.Z * random.NextDouble()), out face).Point; Face face = GetRandomFaceByArea(faceAreas, body, random); PointUV param = PointUV.Create(face.BoxUV.RangeU.Start + random.NextDouble() * face.BoxUV.RangeU.Span, face.BoxUV.RangeV.Start + random.NextDouble() * face.BoxUV.RangeV.Span); if (!face.ContainsParam(param)) { continue; } positions[i] = face.Geometry.Evaluate(param).Point; i++; } return(positions); }
protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect) { const int count = 24; double p = 0.5; double q = 1; double circleAngle = Math.PI / 2; Vector inverseOffset = Vector.Create(0.5, 0, 0); Part mainPart = Window.ActiveWindow.Scene as Part; Point[] baseCirclePoints = new Point[count]; for (int i = 0; i < count; i++) { double u = (double)i / count * 2 * Math.PI; Point[] vPoints = new Point[3]; for (int j = 0; j < 3; j++) { vPoints[j] = Lawson.Evaluate(PointUV.Create((double)j / 3 * 2 * Math.PI, u), p, q, circleAngle, inverseOffset, true); if (j == 0) { baseCirclePoints[i] = vPoints[j]; } } Circle circle = Circle.CreateThroughPoints( Plane.Create(Frame.Create(vPoints[0], Vector.Cross(vPoints[1] - vPoints[0], vPoints[2] - vPoints[0]).Direction)), vPoints[0], vPoints[1], vPoints[2] ); DesignCurve.Create(mainPart, CurveSegment.Create(circle)); //ShapeHelper.CreateTorus(circle.Frame.Origin, circle.Frame.DirZ, circle.Radius * 2, } Circle baseCircle = Circle.CreateThroughPoints( Plane.Create(Frame.Create(baseCirclePoints[0], Vector.Cross(baseCirclePoints[1] - baseCirclePoints[0], baseCirclePoints[2] - baseCirclePoints[0]).Direction)), baseCirclePoints[0], baseCirclePoints[1], baseCirclePoints[2] ); DesignCurve.Create(mainPart, CurveSegment.Create(baseCircle)); }
public static Point Bilinear(BoxUV bounds, Point[,] values, PointUV t) { var xs = new double[2, 2]; var ys = new double[2, 2]; var zs = new double[2, 2]; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { xs[i, j] = values[i, j].X; ys[i, j] = values[i, j].Y; zs[i, j] = values[i, j].Z; } } return Point.Create( Bilinear(bounds, xs, t), Bilinear(bounds, ys, t), Bilinear(bounds, zs, t) ); }
public void Reset() { Vector v0 = p01 - p00; Vector v1 = p10 - p00; for (int i = 0; i <= steps; i++) { double u = parameterBounds.RangeU.Span * i / steps; // parameters.Add(new List<PointUV>()); // tabAngles.Add(new List<double>()); // points.Add(new List<Point>()); for (int j = 0; j <= steps; j++) { parameters[i, j] = PointUV.Create(u, parameterBounds.RangeV.Span * j / steps); points[i, j] = Interpolation.Bilinear(parameterBounds, boundaryValues, parameters[i, j]); // tabAngles[i].Add((double) Math.PI); } } }
public static PointUV GetNoteLocation(INote note, HorizontalType horizontalType, VerticalType verticalType) { double U = 0, V = 0; if (horizontalType == HorizontalType.Left) { U = note.GetLocation(TextPoint.LeftSide).U; } else if (horizontalType == HorizontalType.Right) { Debug.Fail("Note width not implemented"); } else if (horizontalType == HorizontalType.Center) { Debug.Fail("Note width not implemented"); } else { Debug.Fail("Case not handled"); } if (verticalType == VerticalType.Bottom) { V = note.GetLocation(TextPoint.BottomSide).V; } else if (verticalType == VerticalType.Top) { Debug.Fail("Note height not implemented"); } else if (verticalType == VerticalType.Middle) { Debug.Fail("Note height not implemented"); } else { Debug.Fail("Case not handled"); } return(PointUV.Create(U, V)); }
public static Point Bilinear(BoxUV bounds, Point[,] values, PointUV t) { var xs = new double[2, 2]; var ys = new double[2, 2]; var zs = new double[2, 2]; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { xs[i, j] = values[i, j].X; ys[i, j] = values[i, j].Y; zs[i, j] = values[i, j].Z; } } return(Point.Create( Bilinear(bounds, xs, t), Bilinear(bounds, ys, t), Bilinear(bounds, zs, t) )); }
protected override sealed bool IsSmallFace(DesignFace desFace) { // faces below a threshold curvature var face = desFace.Shape; var surfShape = (ISurfaceShape)face; var surf = surfShape.Geometry; var surfParams = surf.Parameterization; var uParam = surfParams.U; var vParam = surfParams.V; double midU; double midV; if (!uParam.Bounds.Start.HasValue || !uParam.Bounds.End.HasValue) { midU = 0d; } else { midU = (uParam.Bounds.Start.Value + uParam.Bounds.End.Value) / 2d; } if (!vParam.Bounds.Start.HasValue || !vParam.Bounds.End.HasValue) { midV = 0; } else { midV = (vParam.Bounds.Start.Value + vParam.Bounds.End.Value) / 2d; } var midParam = PointUV.Create(midU, midV); var eval = surf.Evaluate(midParam); var maxCurve = eval.MaxCurvature; var doc = desFace.Document; var lengthFactor = doc.Units.Length.ConversionFactor; return(1d / maxCurve * lengthFactor < (double)AreaThreshold.Value); }
protected override void OnExecute(Command command, System.Drawing.Rectangle buttonRect) { base.OnExecute(command, buttonRect); foreach (Point point in controlForm.CalibrationPoints) { DesignBody desBody = ShapeHelper.CreateSphere(point, 0.1, part); desBody.Layer = referenceLayer; } foreach (VideoForm videoForm in controlForm.VideoForms) { Point point = videoForm.TrackingCamera.GetLine(PointUV.Origin).Evaluate(0.2).Point; DesignBody desBody = ShapeHelper.CreateSphere(point, 0.1, part); desBody.Layer = referenceLayer; foreach (PointUV pointUV in videoForm.TrackingCamera.CalibrationPoints) { point = videoForm.TrackingCamera.GetLine(pointUV).Evaluate(0.2).Point; //desBody = ShapeHelper.CreateSphere(point, 0.1, part); //desBody.Layer = referenceLayer; var desCurve = DesignCurve.Create(part, CurveSegment.Create(PointCurve.Create(point))); desCurve.Layer = referenceLayer; } for (int i = 0; i < videoForm.Size.Width; i += videoForm.Size.Width / 12) { for (int j = 0; j < videoForm.Size.Height; j += videoForm.Size.Height / 12) { Line line = videoForm.TrackingCamera.GetLine(PointUV.Create(i, j)); var curveSegment = CurveSegment.Create(line, Interval.Create(-3, 6)); var desCurve = DesignCurve.Create(part, curveSegment); desCurve.Layer = referenceLayer; } } } }
public static Direction GetNormal(PointUV uv, double p, double q, double circleAngle, Vector inverseOffset, bool isInverted) { double delta = 0.001; var deltaU = VectorUV.Create(delta, 0); var deltaV = VectorUV.Create(0, delta); PointUV uv00 = uv - deltaU; PointUV uv01 = uv + deltaU; PointUV uv10 = uv - deltaV; PointUV uv11 = uv + deltaV; Vector du = Lawson.Evaluate(uv00, p, q, circleAngle, inverseOffset, isInverted) - Lawson.Evaluate(uv01, p, q, circleAngle, inverseOffset, isInverted) ; Vector dv = Lawson.Evaluate(uv10, p, q, circleAngle, inverseOffset, isInverted) - Lawson.Evaluate(uv11, p, q, circleAngle, inverseOffset, isInverted) ; return(Vector.Cross(du, dv).Direction); }
public Line GetLine(PointUV pointUV) { var unitMatrix = new NMatrix(new double[, ] { { pointUV.U }, { pointUV.V }, { 1 } }); NMatrix solution; if (!NMatrix.TryGaussJordanElimination(Homography, unitMatrix, out solution)) { throw new ArgumentException(); } //a = Vector.Create(solution[0, 3], solution[1, 3], solution[2, 3]); //b = Vector.Create(solution[0, 4], solution[1, 4], solution[2, 4]); ////var vector = Vector.Create(pointUV.U * a.X, pointUV.V * a.Y, a.Z); //return Line.Create(Point.Origin + a, b.Direction); return(Line.Create(Point.Origin, Direction.Create( solution[0, 4] / (solution[0, 3] + 1), solution[1, 4] / (solution[1, 3] + 1), solution[2, 4] / (solution[2, 3] + 1) ))); }
public Line GetLine(PointUV pointUV) { var unitMatrix = new NMatrix(new double[,] { { pointUV.U }, { pointUV.V }, { 1 } }); NMatrix solution; if (!NMatrix.TryGaussJordanElimination(Homography, unitMatrix, out solution)) throw new ArgumentException(); //a = Vector.Create(solution[0, 3], solution[1, 3], solution[2, 3]); //b = Vector.Create(solution[0, 4], solution[1, 4], solution[2, 4]); ////var vector = Vector.Create(pointUV.U * a.X, pointUV.V * a.Y, a.Z); //return Line.Create(Point.Origin + a, b.Direction); return Line.Create(Point.Origin, Direction.Create( solution[0, 4] / (solution[0, 3] + 1), solution[1, 4] / (solution[1, 3] + 1), solution[2, 4] / (solution[2, 3] + 1) )); }
public static double MagnitudeSquared(this PointUV pointUV) { return(pointUV.U * pointUV.U + pointUV.V * pointUV.V); }
static Point Figure8(PointUV uv) { double u = uv.U; double v = uv.V; const double t = 1.5; return Point.Create( Math.Sin(v) * (4 + 2 * Math.Cos(u) * Math.Cos(t * v) - Math.Sin(2 * u) * Math.Sin(t * v)), Math.Cos(v) * (4 + 2 * Math.Cos(u) * Math.Cos(t * v) - Math.Sin(2 * u) * Math.Sin(t * v)), 2 * Math.Cos(u) * Math.Sin(t * v) + Math.Sin(2 * u) * Math.Cos(t * v) ); }
public static Point Evaluate(PointUV uv, double p, double q, double circleAngle, Vector inverseOffset, bool isInverted) { double u = uv.U; double v = uv.V; Circle circle = Circle.Create(Frame.World, 1); // spiraly things circle = circle.CreateTransformedCopy(Matrix.CreateRotation(Line.Create(Point.Origin, Direction.DirY), Math.PI / 4)); circle = circle.CreateTransformedCopy(Matrix.CreateRotation(Line.Create(Point.Origin, Direction.DirY), circleAngle)); return LawsonTransform(circle.Evaluate(u).Point, v, p, q, inverseOffset, isInverted); }
public static Direction GetNormal(PointUV uv, double p, double q, double circleAngle, Vector inverseOffset, bool isInverted) { double delta = 0.001; var deltaU = VectorUV.Create(delta, 0); var deltaV = VectorUV.Create(0, delta); PointUV uv00 = uv - deltaU; PointUV uv01 = uv + deltaU; PointUV uv10 = uv - deltaV; PointUV uv11 = uv + deltaV; Vector du = Lawson.Evaluate(uv00, p, q, circleAngle, inverseOffset, isInverted) - Lawson.Evaluate(uv01, p, q, circleAngle, inverseOffset, isInverted) ; Vector dv = Lawson.Evaluate(uv10, p, q, circleAngle, inverseOffset, isInverted) - Lawson.Evaluate(uv11, p, q, circleAngle, inverseOffset, isInverted) ; return Vector.Cross(du, dv).Direction; }
public static Point Evaluate(PointUV uv, double p, double q, double circleAngle, Vector inverseOffset, bool isInverted, out Direction normal) { normal = GetNormal(uv, p, q, circleAngle, inverseOffset, isInverted); return Evaluate(uv, p, q, circleAngle, inverseOffset, isInverted); }
public static Direction GetNormal(PointUV uv, double p, double q, double circleAngle, Vector inverseOffset, bool isInverted) { double delta = 0.001; var deltaU = VectorUV.Create(delta, 0); var deltaV = VectorUV.Create(0, delta); PointUV uv00 = uv - deltaU; PointUV uv01 = uv + deltaU; PointUV uv10 = uv - deltaV; PointUV uv11 = uv + deltaV; Point pCenter = Lawson.Evaluate(uv, p, q, circleAngle, inverseOffset, isInverted); var pxxs = new Point[] { Lawson.Evaluate(uv00, p, q, circleAngle, inverseOffset, isInverted), Lawson.Evaluate(uv01, p, q, circleAngle, inverseOffset, isInverted), Lawson.Evaluate(uv10, p, q, circleAngle, inverseOffset, isInverted), Lawson.Evaluate(uv11, p, q, circleAngle, inverseOffset, isInverted) }; var sum = Vector.Zero; foreach (Point pxx in pxxs) sum += pxx - pCenter; if (sum != Vector.Zero) return sum.Direction; return Vector.Cross(pxxs[1] - pxxs[0], pxxs[1] - pxxs[2]).Direction; }