/* * public static Vector2D[] Next2(Vector2D seed) * { * Vector2D lineUnitVector = (seed - ProjectionPoint).UnitVector; * Vector2D linePoint = ProjectionPoint - lineUnitVector * lineUnitVector.Dot(ProjectionPoint); * Vector2D top = linePoint + lineUnitVector * Math.Sqrt(1 - linePoint.MagnitudeSquared); * Vector2D rotatedTop = new Vector2D(top.x / -2, top.y); * Vector2D target = ArcLeft * rotatedTop.Dot(ArcLeft) + ArcLeft.Rotate90 * (rotatedTop.Dot(ArcLeft.Rotate90) * ScaleOut); * Vector2D strikeThroughLineVector = (target - ScaledProjectionPoint).UnitVector; * Vector2D strikeThroughLinePoint = ScaledProjectionPoint - strikeThroughLineVector * strikeThroughLineVector.Dot(ScaledProjectionPoint); * Vector2D primaryScaled = strikeThroughLinePoint + strikeThroughLineVector * Math.Sqrt(1 - strikeThroughLinePoint.MagnitudeSquared); * double distanceToScaledCenterLine = MirrorPerpendicular.Dot(primaryScaled); * Vector2D secondaryScaled = primaryScaled - MirrorPerpendicular * (distanceToScaledCenterLine * 2); * Vector2D primary = ArcLeft * primaryScaled.Dot(ArcLeft) + ArcLeft.Rotate90 * (primaryScaled.Dot(ArcLeft.Rotate90) * ScaleIn); * Vector2D secondary = ArcLeft * secondaryScaled.Dot(ArcLeft) + ArcLeft.Rotate90 * (secondaryScaled.Dot(ArcLeft.Rotate90) * ScaleIn); * return new Vector2D[] { primary, secondary }; * } */ /* * public static Vector2D[] Next3(Vector2D v0) * { * double v0x = v0.x; * double v0y = v0.y; * double v1x = ProjectionPoint.x; * double v1y = ProjectionPoint.y; * double v2x = ArcLeft.x; * double v2y = ArcLeft.y; * double v3x = ScaledProjectionPoint.x; * double v3y = ScaledProjectionPoint.y; * double v4x = MirrorPerpendicular.x; * double v4y = MirrorPerpendicular.y; * * double v5 = ScaleOut; * double v6 = ScaleIn; * * double t0x = v0x - v1x; * double t0y = v0y - v1y; * double t0m = Math.Sqrt(t0x * t0x + t0y * t0y); * * double ax = t0x / t0m; * double ay = t0y / t0m; * double av1d = ax * v1x + ay * v1y; * * double bx = v1x - ax * av1d; * double by = v1y - ay * av1d; * double binv = Math.Sqrt(1 - bx * bx - by * by); * * double dx = (bx + ax * binv) / -2; * double dy = by + ay * binv; * * double dv2d = dx * v2x + dy * v2y; * double dv2drot = dx * v2y - dy * v2x; * * double ex = v2x * dv2d + v2y * dv2drot * v5; * double ey = v2y * dv2d - v2x * dv2drot * v5; * * double t1x = ex - v3x; * double t1y = ey - v3y; * double t1m = Math.Sqrt(t1x * t1x + t1y * t1y); * * double fx = t1x / t1m; * double fy = t1y / t1m; * double fv3d = fx * v3x + fy * v3y; * * double gx = v3x - fx * fv3d; * double gy = v3y - fy * fv3d; * double ginv = Math.Sqrt(1 - gx * gx - gy * gy); * * double hx = gx + fx * ginv; * double hy = gy + fy * ginv; * * double i = v4x * hx + v4y * hy; * * double jx = hx - v4x * i * 2; * double jy = hy - v4y * i * 2; * * double hv2d = hx * v2x + hy * v2y; * double hv2drot = hx * v2y - hy * v2x; * * double kx = v2x * hv2d + v2y * hv2drot * v6; * double ky = v2y * hv2d - v2x * hv2drot * v6; * * double jv2d = jx * v2x + jy * v2y; * double jv2drot = jx * v2y - jy * v2x; * * double lx = v2x * jv2d + v2y * jv2drot * v6; * double ly = v2y * jv2d - v2x * jv2drot * v6; * * return new Vector2D[] { new Vector2D(kx,ky), new Vector2D(lx,ly) }; * * //Mark: We are mostly interested in i. This is the distance to the centerline. * }*/ /* * public static Vector2D[] Next(Vector2D v0) * { * //Mark: i is the most interesting number. This is the distance to the centerline. * * //gather variables. * double v0x = v0.x;//the seed * double v0y = v0.y; * double v1x = ProjectionPoint.x; * double v1y = ProjectionPoint.y; * double v2x = ArcLeft.x; * double v2y = ArcLeft.y; * double v3x = ScaledProjectionPoint.x; * double v3y = ScaledProjectionPoint.y; * double v4x = MirrorPerpendicular.x; * double v4y = MirrorPerpendicular.y; * double v5 = ScaleOut; * double v6 = ScaleIn; * * //starting calculation. * double ax = v0x - v1x; * double ay = v0y - v1y; * double a0 = Math.Sqrt(ax * ax + ay * ay); * * double bx = ax / a0; * double by = ay / a0; * double b0 = bx * v1x + by * v1y; * * //c is the base-point of the line from projectionpoint to the seed. * double cx = v1x - bx * b0; * double cy = v1y - by * b0; * double c0 = Math.Sqrt(1 - cx * cx - cy * cy); * * //d is the rotated new target point * double dx = (cx + bx * c0) / -2; * double dy = cy + by * c0; * * double t1 = dx * v2x + dy * v2y; * double t2 = dx * v2y - dy * v2x; * * //e is the scaled target * double ex = v2x * t1 + v2y * t2 * v5; * double ey = v2y * t1 - v2x * t2 * v5; * * double t3x = ex - v3x; * double t3y = ey - v3y; * double t3 = Math.Sqrt(t3x * t3x + t3y * t3y); * * double fx = t3x / t3; * double fy = t3y / t3; * double f0 = fx * v3x + fy * v3y; * * double gx = v3x - fx * f0; * double gy = v3y - fy * f0; * double g0 = Math.Sqrt(1 - gx * gx - gy * gy); * * //h is the scaled primary point * double hx = gx + fx * g0; * double hy = gy + fy * g0; * * //i is the distance to the scaled centerline. * double i = v4x * hx + v4y * hy; * double i2 = i * 2; * * //j is the scaled secondary point * double jx = hx - v4x * i2; * double jy = hy - v4y * i2; * * double h0 = hx * v2x + hy * v2y; * double h1 = (hx * v2y - hy * v2x)*v6; * * //k is the unscaled primary point * double kx = v2x * h0 + v2y * h1; * double ky = v2y * h0 - v2x * h1; * * double j0 = jx * v2x + jy * v2y; * double j1 = (jx * v2y - jy * v2x)*v6; * * //l the unscaled secondary point * double lx = v2x * j0 + v2y * j1; * double ly = v2y * j0 - v2x * j1; * * return new Vector2D[] { new Vector2D(kx, ky), new Vector2D(lx, ly) }; * } */ public static ScaledCenterlinePair NextBasic(Vector2D v0, long index) { //gather variables. double v0x = v0.x;//the seed double v0y = v0.y; //starting calculation. double ax = v0x - v1x; double ay = v0y - v1y; double a0 = Math.Sqrt(ax * ax + ay * ay); double bx = ax / a0; double by = ay / a0; double b0 = bx * v1x + by * v1y; //c is the base-point of the line from projectionpoint to the seed. double cx = v1x - bx * b0; double cy = v1y - by * b0; double c0 = Math.Sqrt(1 - cx * cx - cy * cy); //d is the rotated new target point double dx = (cx + bx * c0) / -2; double dy = cy + by * c0; double t1 = dx * v2x + dy * v2y; double t2 = dx * v2y - dy * v2x; //e is the scaled target double ex = v2x * t1 + v2y * t2 * v5; double ey = v2y * t1 - v2x * t2 * v5; double t3x = ex - v3x; double t3y = ey - v3y; double t3 = Math.Sqrt(t3x * t3x + t3y * t3y); double fx = t3x / t3; double fy = t3y / t3; double f0 = fx * v3x + fy * v3y; double gx = v3x - fx * f0; double gy = v3y - fy * f0; double g0 = Math.Sqrt(1 - gx * gx - gy * gy); //h is the scaled primary point double hx = gx + fx * g0; double hy = gy + fy * g0; //i is the distance to the scaled centerline. double i = v4x * hx + v4y * hy; double i2 = i * 2; //j is the scaled secondary point double jx = hx - v4x * i2; double jy = hy - v4y * i2; double h0 = hx * v2x + hy * v2y; double h1 = (hx * v2y - hy * v2x) * v6; //k is the unscaled primary point double kx = v2x * h0 + v2y * h1; double ky = v2y * h0 - v2x * h1; double j0 = jx * v2x + jy * v2y; double j1 = (jx * v2y - jy * v2x) * v6; //l the unscaled secondary point double lx = v2x * j0 + v2y * j1; double ly = v2y * j0 - v2x * j1; ScaledCenterlinePair result = new ScaledCenterlinePair() { distanceToScaledCenterLine = i, primary = new Vector2D(kx, ky), secondary = new Vector2D(lx, ly), primaryIndex = index << 1, secondaryIndex = index << 1 | 1 }; return(result); }
/* * private void TestMinimal2Button_Click(object sender, EventArgs e) * { * MinimalEquation.Initialize(); * Vector3D[] first = MinimalEquation.NextEquational(MinimalEquation.FirstSeedE); * }*/ private void GeodesicAnalysisButton_Click(object sender, EventArgs e) { using (SaveFileDialog sfd = new SaveFileDialog() { Filter = "*.csv|*.csv" }) { if (sfd.ShowDialog() != DialogResult.OK) { return; } List <ScaledCenterlinePair> current = new List <ScaledCenterlinePair>(); List <ScaledCenterlinePair> next = new List <ScaledCenterlinePair>(); MinimalEquation.Initialize(); Vector2D seed = MinimalEquation.FirstSeed; ScaledCenterlinePair basicSet = new ScaledCenterlinePair(); basicSet.primary = seed; basicSet.distanceToScaledCenterLine = 0; basicSet.primaryIndex = 1; current.Add(basicSet); List <string> lines = new List <string>(); string header = "Count;Index;IndexBin;Distance;X;Y;"; lines.Add(header); long i = 1; long generations = Convert.ToInt32(GenerationBox.Text); for (int g = -1; g < generations; g++) { foreach (ScaledCenterlinePair set in current) { string line = i.ToString() + ";"; i++; line += set.primaryIndex.ToString() + ";"; line += Convert.ToString(set.primaryIndex, 2) + ";"; line += (-set.distanceToScaledCenterLine).ToString() + ";"; line += set.primary.x.ToString() + ";"; line += set.primary.y.ToString() + ";"; lines.Add(line); line = ""; if (set.secondary != null) { line += i.ToString() + ";"; i++; line += set.secondaryIndex.ToString() + ";"; line += Convert.ToString(set.secondaryIndex, 2) + ";"; line += set.distanceToScaledCenterLine.ToString() + ";"; line += set.secondary.x.ToString() + ";"; line += set.secondary.y.ToString() + ";"; lines.Add(line); } if (g < generations - 1) { next.Add(MinimalEquation.NextBasic(set.primary, set.primaryIndex)); if (set.secondary != null) { next.Add(MinimalEquation.NextBasic(set.secondary, set.secondaryIndex)); } } } current = next; next = new List <ScaledCenterlinePair>(); } File.WriteAllLines(sfd.FileName, lines); } }