bool FindIntersectionAt(double th, PointCyl p0, PointCyl p1, out PointCyl intersection) { try { intersection = new PointCyl(); double th0 = p0.ThetaRad; double th1 = p1.ThetaRad; if (th < 0) { th += (Math.PI * 2.0); } if (th0 < 0) { th0 += (Math.PI * 2.0); } if (th1 < 0) { th1 += (Math.PI * 2.0); } if (th > th0 && th <= th1) { double dth = th1 - th0; double dr = p1.R - p0.R; double r = (th - th0) * (dr / dth) + p0.R; intersection = new PointCyl(r, th, 0); return(true); } return(false); } catch (Exception) { throw; } }
public CylData FitToCircleKnownR(Vector3 pt1, Vector3 pt2, double fitRadius) { try { var centers = GeometryLib.GeomUtilities.FindCirclesofKnownR(pt1, pt2, fitRadius); var center = new Vector3(); if (centers[0].Y > centers[1].Y) { center = centers[0]; } else { center = centers[1]; } var translation = new Vector3(-1.0 * center.X, -1.0 * center.Y, 0); CylData cylData = new CylData(this.FileName); foreach (var pt in this) { var pttrans = pt.Translate(translation); PointCyl pointCyl = new PointCyl(pttrans); cylData.Add(pointCyl); } return(cylData); } catch (Exception) { throw; } }
void CalcAllGrooveDepths(CylData data) { try { double depth = -1; double nomR = _nominalLandDiam / 2.0; PointCyl intersection = new PointCyl(); foreach (var groove in this) { foreach (var depthMeasurement in groove) { for (int i = 0; i < data.Count - 1; i++) { if (FindIntersectionAt(depthMeasurement.Theta, data[i], data[i + 1], out intersection)) { depthMeasurement.Datum = intersection; depth = intersection.R - nomR; depthMeasurement.Depth = depth; break; } } } } } catch (Exception) { throw; } }
/// <summary> /// find min radius and reset radii to nominal /// </summary> /// <param name="singleRing"></param> /// <param name="_nominalRadius"></param> /// <returns></returns> static CylData CorrectRadius(CylData singleRing, double rCorrection, ProbeDirection probeDir) { try { var result = new CylData(singleRing.FileName); foreach (var pt in singleRing) { PointCyl newPt; double r = 0; if (probeDir == ProbeDirection.ID) { r = pt.R + rCorrection; } else { r = rCorrection - pt.R; } newPt = new PointCyl(r, pt.ThetaRad, pt.Z, pt.ID); result.Add(newPt); } result.MinRadius = singleRing.MinRadius; return(result); } catch (Exception) { throw; } }
public double RadiusAt(double z, double thetaRaD) { double r = -1; double thetaRotation = Twist.ThetaRadAt(z); PointCyl ptCyl = new PointCyl(10, thetaRotation + thetaRaD, z); Vector3 pt1 = new Vector3(ptCyl); Vector3 pt2 = new Vector3(0, 0, z); Line ray = new Line(pt1, pt2); Vector3 result = new Vector3(); foreach (DwgEntity entity in Entities) { IntersectionRecord intersectionRecord; if (entity is Arc arc) { intersectionRecord = GeomUtilities.RayArcXYIntersect(arc, ray); if (intersectionRecord.Intersects) { r = Math.Sqrt(intersectionRecord.X * intersectionRecord.X * +intersectionRecord.Y * intersectionRecord.Y); } } else if (entity is Line line) { intersectionRecord = GeomUtilities.RayLineXYIntersect(ray, line); if (intersectionRecord.Intersects) { r = Math.Sqrt(intersectionRecord.X * intersectionRecord.X * +intersectionRecord.Y * intersectionRecord.Y); } } } return(r); }
public DepthMeasurement(PointCyl inputDatum, double thetaRad, int rasterOrder, double depth) { _datum = inputDatum; _thetaLocRad = thetaRad; _rasterOrder = rasterOrder; _depth = depth; }
static PointCyl GetRadiusPoint(int i, double rRaw, double zLocation, CylInspScript script) { var z = zLocation; var theta = i * script.AngleIncrement + GeomUtilities.ToRadians(script.StartLocation.Adeg); double r = script.ProbeSetup[0].DirectionSign * rRaw + script.CalDataSet.ProbeSpacingInch / 2.0; var pt = new PointCyl(r, theta, z, i); return(pt); }
static PointCyl GetDiamPoint(int i, double rRaw, AxialInspScript script) { var z = i * script.AxialIncrement + script.StartLocation.X; var theta = GeomUtilities.ToRadians(script.StartLocation.Adeg); var r = rRaw + script.CalDataSet.ProbeSpacingInch; var pt = new PointCyl(r, theta, z, i); return(pt); }
public void PointCyl_translate_returnPt() { PointCyl pt = new PointCyl(1, Math.PI, 1); PointCyl ptOut = pt.Translate(new Vector3(1, 1, 1)); Assert.AreEqual(2d, ptOut.Z, .001); Assert.AreEqual(pt.R, ptOut.R, .001); Assert.AreEqual(Math.PI / 2, ptOut.ThetaRad, .001); }
public void vector3_constFromCylpt_returnVal() { IPointCyl ptc = new PointCyl(2, Math.PI / 2, 3); IVector3 v = new Vector3(ptc); Assert.AreEqual(0, Math.Round(v.X, 5)); Assert.AreEqual(2, Math.Round(v.Y, 5)); Assert.AreEqual(3, Math.Round(v.Z, 5)); }
public void PointCyl_constFromVect3_returnsVal() { Vector3 v = new Vector3(2, 2, 1); PointCyl pt = new PointCyl(v); Assert.AreEqual(1d, pt.Z, .001); Assert.AreEqual(Math.Sqrt(8), pt.R, .001); Assert.AreEqual(Math.PI / 4, pt.ThetaRad, .001); Assert.AreEqual(45.0, pt.ThetaDeg(), .001); }
public CylData CorrectToMidpoint(CylData points, PointCyl midPoint) { try { CorrectionAngleRads = midPoint.ThetaRad; return(CorrectForError(points)); } catch (Exception) { throw; } }
public IList <IPointCylTol> TrimToWindow(System.Drawing.RectangleF rectangleF, ViewPlane viewPlane) { try { var winData = new List <IPointCylTol>(); var dd = AsDisplayData(viewPlane); IPointCylTol trimPt; foreach (var pt in dd) { if (rectangleF.Contains(pt)) //if (pt.X >= minX && pt.X <= maxX && pt.Y >= minY && pt.Y < maxY) { switch (viewPlane) { case ViewPlane.THETAR: trimPt = new PointCylTol() { R = pt.Y, ThetaRad = PointCyl.ToRadians(pt.X), Z = 0 }; winData.Add(trimPt); break; case ViewPlane.ZR: trimPt = new PointCylTol() { R = pt.Y, ThetaRad = 0, Z = pt.X }; winData.Add(trimPt); break; case ViewPlane.XY: break; case ViewPlane.XZ: break; case ViewPlane.YZ: break; } } } return(winData); } catch (Exception) { throw; } }
static InspDataSet BuildRasterPoints(RasterInspScript script, double[] data) { try { var points = new CylData(script.InputDataFileName); double theta = script.StartLocation.Adeg; double z = script.StartLocation.X; double r = 0; double nextZ = script.StartLocation.X + script.AxialIncrement; double direction = 1; var dataSet = new CylDataSet(script.InputDataFileName); for (int i = 0; i < data.Length; i++) { theta = i * script.AngleIncrement + script.StartLocation.Adeg;; if (theta >= script.EndLocation.Adeg && z < nextZ) { direction = -1; z = i * script.AxialIncrement + script.StartLocation.X; } if (theta <= script.EndLocation.Adeg && z < nextZ) { direction = 1; z = i * script.AxialIncrement + script.StartLocation.X; } if (theta < script.EndLocation.Adeg && theta > script.StartLocation.Adeg) { if (direction > 0) { theta = direction * i * script.AngleIncrement + script.StartLocation.Adeg; } if (direction < 0) { theta = direction * i * script.AngleIncrement + script.EndLocation.Adeg; } if (z >= nextZ) { nextZ += script.AxialIncrement; } } r = data[i]; var pt = new PointCyl(r, GeomUtilities.ToRadians(theta), z, i); dataSet.CylData.Add(pt); } return(dataSet); } catch (Exception) { throw; } }
static public Vector3 UnrollCylPt(PointCyl pt, double thetaOffsetRad, double scaling, double unrollingRadius) { try { var result = new Vector3((pt.ThetaRad + thetaOffsetRad) * unrollingRadius, pt.R * scaling, pt.Z, pt.Col); return(result); } catch (Exception) { throw; } }
protected void BuildFromDXF(string dxfFilename) { Entities = DxfFileParser.Parse(dxfFilename); cartDisplayData = DxfFileParser.AsDisplayData(Entities, MeshSize, ViewPlane.XY); cartDisplayData.FileName = dxfFilename; cylDisplayData = new DisplayData(dxfFilename); foreach (var pt in cartDisplayData) { PointCyl ptc = new PointCyl(new Vector3(pt.X, pt.Y, 0)); PointF ptf = new PointF((float)ptc.ThetaDegPosOnly, (float)ptc.R); cylDisplayData.Add(ptf); } cylDisplayData.FileName = dxfFilename; }
public CylData AsCylData() { var stripd = new CylData(this[0].FileName); foreach (var strip in this) { foreach (var pt in strip) { var ptnew = new PointCyl(pt.R, pt.ThetaRad, pt.Z, pt.Col, pt.ID); stripd.Add(ptnew); } } return(stripd); }
void CalcAveAngleError(CylData points, List <int> intersectionsList) { try { var nomMidPointThetas = GetNomMidpointThetas(); intersectionsList.Sort(); var midpointThetas = new List <double>(); var pt0 = new PointCyl(); var pt1 = new PointCyl(); var ptMid = new PointCyl(); double rAve = 0; double thetaMid = 0; for (int i = 0; i < intersectionsList.Count - 1; i++) { pt0 = points[intersectionsList[i]]; pt1 = points[intersectionsList[i + 1]]; rAve = (pt0.R + pt1.R) / 2.0; thetaMid = (pt0.ThetaRad + pt1.ThetaRad) / 2.0; ptMid = GetIntersectionAt(thetaMid, points); int midIndex = GetIndexofIntersectionAt(thetaMid, points); if (ptMid.R > rAve) { midpointThetas.Add(thetaMid); } } pt0 = points[intersectionsList[intersectionsList.Count - 1]]; pt1 = points[intersectionsList[0]]; rAve = (pt0.R + pt1.R) / 2.0; thetaMid = (pt0.ThetaRad + pt1.ThetaRad) / 2.0; ptMid = GetIntersectionAt(thetaMid, points); if (ptMid.R > rAve) { midpointThetas.Add(thetaMid); } if (midpointThetas.Count >= 1) { CalcAveGrooveAngleError(nomMidPointThetas, midpointThetas.ToArray()); } else { throw new Exception("Unable to find groove intersections for angle correction. Correct Manually"); } } catch (Exception) { throw; } }
public static CylData AsCylData(CartData cartData) { try { var strip = new CylData(cartData.FileName); var thetaStart = new PointCyl(cartData[0]).ThetaRad; foreach (var pt in cartData) { var ptCyl = new PointCyl(pt); strip.Add(ptCyl); } return(strip); } catch (Exception) { throw; } }
public CylData AsCylData() { try { var cylData = new CylData(FileName); var pts = new List <PointCyl>(); foreach (var pt in this) { var newPt = new PointCyl(pt); pts.Add(newPt); } cylData.AddRange(pts); return(cylData); } catch (Exception) { throw; } }
public DXFLine(PointCyl pt1, PointCyl pt2) { try { double x1 = pt1.R * Math.Cos(pt1.ThetaRad); double y1 = pt1.R * Math.Sin(pt1.ThetaRad); double z1 = pt1.Z; double x2 = pt2.R * Math.Cos(pt2.ThetaRad); double y2 = pt2.R * Math.Sin(pt2.ThetaRad); double z2 = pt2.Z; Col = pt1.Col; Point1 = new Vector3(x1, y1, z1); Point2 = new Vector3(x2, y2, z2); } catch (Exception) { throw; } }
static public CartData UnrollCylinderRing(CartData cartData, double scaling, double unrollRadius) { try { var strip = new CartData(cartData.FileName); var thetaStart = new PointCyl(cartData[0]).ThetaRad; double thetaoffset = Math.PI / 2.0; foreach (var pt in cartData) { var ptCyl = new PointCyl(pt); strip.Add(UnrollCylPt(ptCyl, thetaoffset, scaling, unrollRadius)); } return(strip); } catch (Exception) { throw; } }
public CylData CorrectData(CylData points) { var result = new CylData(points.FileName); points.SortByTheta(); for (int i = 0; i < points.Count; i++) { foreach (SegmentFitData segmentFit in dataSegments) { if (points[i].ThetaRad >= segmentFit.StartPoint.ThetaRad && points[i].ThetaRad < segmentFit.EndPoint.ThetaRad) { double r = points[i].R - segmentFit.FitFunction(points[i].ThetaRad); var pt = new PointCyl(r, points[i].ThetaRad, points[i].Z); result.Add(pt); break; } } } return(result); }
private ICylData TranslateToCenter(IVector2 center) { try { var translation = new Vector3(-1.0 * center.X, -1.0 * center.Y, 0); CylData cylData = new CylData(this.FileName); foreach (var pt in data) { var pttrans = pt.Translate(translation); PointCyl pointCyl = new PointCyl(pttrans); cylData.Add(pointCyl); } return(cylData); } catch (Exception) { throw; } }
static public PointCyl[] SortByIndex(CylData points) { try { int i = 0; var indexArr = new int[points.Count]; var pointArr = new PointCyl[points.Count]; foreach (PointCyl pt in points) { indexArr[i] = pt.ID; pointArr[i] = pt.Clone(); i++; } Array.Sort(indexArr, pointArr); return(pointArr); } catch (Exception) { throw; } }
static PointCyl[] SortByTheta(PointCyl[] points) { try { int i = 0; var indexArr = new double[points.Length]; var pointArr = new PointCyl[points.Length]; foreach (PointCyl pt in points) { indexArr[i] = pt.ThetaRad; pointArr[i] = pt.Clone(); i++; } Array.Sort(indexArr, pointArr); return(pointArr); } catch (Exception) { throw; } }
private void BuildDisplayData(ViewPlane viewPlane) { try { var pts = new List <PointF>(); displayData = new DisplayData(FileName); displayData.Color = Color; foreach (IVector3 v in data) { switch (viewPlane) { case ViewPlane.THETAR: var ptc = new PointCyl(v); pts.Add(new PointF((float)ptc.ThetaDeg, (float)ptc.R)); break; case ViewPlane.XZ: pts.Add(new PointF((float)v.X, (float)v.Z)); break; case ViewPlane.YZ: pts.Add(new PointF((float)v.Y, (float)v.Z)); break; case ViewPlane.XY: default: pts.Add(new PointF((float)v.X, (float)v.Y)); break; } } displayData.AddRange(pts); } catch (Exception) { throw; } }
public IList <IPointCyl> TrimToWindow(System.Drawing.RectangleF rectangleF, ViewPlane viewPlane) { try { var winData = new CylData(); var dd = AsDisplayData(viewPlane); foreach (var pt in dd) { if (rectangleF.Contains(pt)) //if (pt.X >= minX && pt.X <= maxX && pt.Y >= minY && pt.Y < maxY) { switch (viewPlane) { case ViewPlane.THETAR: winData.Add(new PointCyl(pt.Y, PointCyl.ToRadians(pt.X), 0)); break; case ViewPlane.ZR: winData.Add(new PointCyl(pt.Y, 0, pt.X)); break; case ViewPlane.XY: break; case ViewPlane.XZ: break; case ViewPlane.YZ: break; } } } return(winData); } catch (Exception) { throw; } }
/// <summary> /// find min radius and reset radii to nominal /// </summary> /// <param name="singleRing"></param> /// <param name="setPt"></param> /// <param name="knownRadius"></param> /// <returns></returns> static public CylData ResetToKnownRadius(CylData singleRing, PointCyl setPt, double knownRadius) { try { var result = new CylData(singleRing.FileName); double rCorrection = knownRadius - setPt.R; foreach (var pt in singleRing) { PointCyl newPt; newPt = new PointCyl(pt.R + rCorrection, pt.ThetaRad, pt.Z); result.Add(newPt); } result.MinRadius = singleRing.MinRadius; return(result); } catch (Exception) { throw; } }
/// <summary> /// get intersection point at given theta /// </summary> /// <param name="thetaRad"></param> /// <param name="points"></param> /// <returns></returns> PointCyl GetIntersectionAt(double thetaRad, List <PointCyl> points) { try { PointCyl pt = new PointCyl();; for (int i = 0; i < points.Count - 1; i++) { if (thetaRad >= points[i].ThetaRad && thetaRad < points[i + 1].ThetaRad) { double dr = (points[i + 1].R - points[i].R); double dz = points[i + 1].Z - points[i].Z; double dth = points[i + 1].ThetaRad - points[i].ThetaRad; double rMin = Math.Min(points[i + 1].R, points[i].R); double thMin = Math.Min(points[i + 1].ThetaRad, points[i].ThetaRad); double zMin = Math.Min(points[i + 1].Z, points[i].Z); if (dth == 0) { pt = new PointCyl(points[i].R, thetaRad, points[i].Z); } else { double thInc = (thetaRad - thMin) / dth; double r = dr * thInc + rMin; double z = dz * thInc + zMin; pt = new PointCyl(r, thetaRad, z); } break; } } return(pt); } catch (Exception) { throw; } }