private void GenerateButton_Click(object sender, EventArgs e) { using (SaveFileDialog sfd = new SaveFileDialog() { Filter = "*.csv|*.csv" }) { if (sfd.ShowDialog() != DialogResult.OK) { return; } int finalLevel = Convert.ToInt32(LevelBox.Text); List <string> result = new List <string>(); for (int level = 0; level <= finalLevel; level++) { if (level == 0) { result.Add(new Vector3D().ToString(true)); continue; } List <Plane> planes = new List <Plane>(); List <Plane> rotatedPlanes = new List <Plane>(); double range = 1; double step = 1.0 / level; for (int i = 0; i <= level; i++, range -= step) { if (range < 0) { range = 0; } Vector2D cutPoint = MinimalEquation.GetVector2DByRange(range); Plane plane = MinimalEquation.GetPlane(cutPoint); planes.Add(plane); rotatedPlanes.Add(plane.RotateTop120); } List <Vector3D> points = new List <Vector3D>(); for (int i = 0; i <= level; i++) { for (int j = 0; j + i <= level; j++) { Plane a = planes[i]; Plane b = rotatedPlanes[j]; Line intersection = b.Intersection(a); Vector3D point = intersection.UnitSphereIntersection1; points.Add(point); } } foreach (Vector3D point in points) { result.Add((point * level).ToString(true)); } } File.WriteAllLines(sfd.FileName, result); } }
private void GetByIndexButton_Click(object sender, EventArgs e) { try { long index = Convert.ToInt64(IndexBox.Text); Vector2D result = MinimalEquation.ByIndex(index); XBox.Text = result.x.ToString(); YBox.Text = result.y.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }
private void RangePositionButton_Click(object sender, EventArgs e) { try { double position = Convert.ToDouble(RangeBox.Text); BoundPair pair = MinimalEquation.GetByRange(position); UpperPositionBox.Text = pair.upperIndex.ToString(); UpperXBox.Text = pair.upper.x.ToString(); UpperRangeBox.Text = pair.upperRange.ToString(); LowerPositionBox.Text = pair.lowerIndex.ToString(); LowerXBox.Text = pair.lower.x.ToString(); LowerRangeBox.Text = pair.lowerRange.ToString(); ItterationsBox.Text = pair.itterations.ToString(); NextGenerationCallsBox.Text = pair.nextGenerationCalls.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }
public static BoundPair GetByX(double x) { long lowerIndex = 0; long upperIndex = -1; Vector2D lower = MinimalEquation.ByIndex(lowerIndex); Vector2D upper = MinimalEquation.ByIndex(upperIndex); long mostSignificant = 1; long rest = 0; long current = mostSignificant | rest; double lowerRange = 0; double upperRange = 1; double midRange = 0.5; double incrementRange = 0.25; if (x < lower.x || x > upper.x) { throw new Exception("Out of bounds (" + lower.x.ToString() + " to " + upper.x.ToString() + ")"); } Vector2D mid = MinimalEquation.ByIndex(1); if (x < mid.x) { upper = mid; upperIndex = 1; upperRange = midRange; } else { lower = mid; lowerIndex = 1; lowerRange = midRange; } //counter for testing performance int n = 0; for (int i = 0; i < SearchDepth; i++) { long flipBit = mostSignificant; mostSignificant <<= 1; long i1 = rest | mostSignificant; long i2 = i1 | flipBit; midRange = lowerRange + incrementRange; incrementRange /= 2; Vector2D v1 = MinimalEquation.ByIndex(i1); Vector2D v2 = MinimalEquation.ByIndex(i2); n += 2 * i + 2; if (v1.x > lower.x && v1.x < upper.x) { if (x < v1.x) { upper = v1; upperIndex = i1; upperRange = midRange; } else { lower = v1; lowerIndex = i1; lowerRange = midRange; } } else if (v2.x > lower.x && v2.x < upper.x) { if (x < v2.x) { upper = v2; upperIndex = i2; upperRange = midRange; } else { lower = v2; lowerIndex = i2; lowerRange = midRange; } rest |= flipBit; } else { //cannot search any deeper. return(new BoundPair() { lower = lower, lowerIndex = lowerIndex, lowerRange = lowerRange, upper = upper, upperIndex = upperIndex, upperRange = upperRange, itterations = i, nextGenerationCalls = n }); } } return(new BoundPair() { upper = upper, upperIndex = upperIndex, upperRange = upperRange, lower = lower, lowerIndex = lowerIndex, lowerRange = lowerRange, itterations = SearchDepth, nextGenerationCalls = n }); }
/* * 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); } }
private void TestMinimalButton_Click(object sender, EventArgs e) { MinimalEquation.Initialize(); Vector2D[] first = MinimalEquation.Next1(MinimalEquation.FirstSeed); }