public StrikeThroughPointPair(Geodesic geodesic, Vector3D seed, int index) { Line line = Line.Construct(geodesic.ProjectionPoint, seed.Front); Vector3D top = line.UnitSphereIntersectionPositiveZ; Vector3D rotatedTop = top.RotateTop120Front; Vector3D target = Geodesic.ScaleEllipseOut(rotatedTop); Line strikeThrough = Line.Construct(Geodesic.ScaleEllipseOut(geodesic.ProjectionPoint), target); Vector3D primaryScaled = strikeThrough.UnitSphereIntersectionPositiveZ; DistanceToScaledCenterLine = Geodesic.MirrorPerpendicular.Dot(primaryScaled); Vector3D secondaryScaled = primaryScaled - Geodesic.MirrorPerpendicular * (DistanceToScaledCenterLine * 2); Right = Geodesic.ScaleEllipseIn(primaryScaled); Left = Geodesic.ScaleEllipseIn(secondaryScaled); RightIndex = index << 1; LeftIndex = RightIndex | 1; if (Left.X > Right.X) { Vector3D swap = Left; Left = Right; Right = swap; int swapIndex = LeftIndex; LeftIndex = RightIndex; RightIndex = swapIndex; } Parent = geodesic; }
private void SavePointsButton_Click(object sender, EventArgs e) { using (SaveFileDialog sfd = new SaveFileDialog()) { if (sfd.ShowDialog() != DialogResult.OK) { return; } Geodesic geodesic = new Geodesic(Convert.ToInt32(GenerationBox.Text)); List <string> lines = new List <string>(); for (int i = 0; i < geodesic.MaxGridIndex; i++) { GridIndex index = geodesic.GetGridIndex(i); GeodesicGridTriangle triangle = index.GeodesicGridTriangle; foreach (Vector3D point in triangle.Points) { lines.Add(point.ToString()); } } System.IO.File.WriteAllLines(sfd.FileName, lines); } }
/// <summary> /// Calculate the area variance with a shifting projection point. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MultipleVarianceButton_Click(object sender, EventArgs e) { using (SaveFileDialog sfd = new SaveFileDialog() { Filter = "*.csv|*.csv" }) { if (sfd.ShowDialog() != DialogResult.OK) { return; } double min = 0; double max = 2; double step = 0.001; int steps = Convert.ToInt32((Math.Round((max - min) / step))); double current = step; int generation = Convert.ToInt32(GenerationBox.Text); List <string> content = new List <string>(); content.Add("Position,Variance,"); for (int i = 0; i < steps; i++, current += step) { Geodesic geodesic = new Geodesic(Convert.ToInt32(generation) - 2, Geodesic.DefaultProjectionPoint * current); double variance = VarianceOf(geodesic).variance; content.Add(current.ToString() + "," + variance.ToString() + ","); } File.WriteAllLines(sfd.FileName, content); } }
/* * private void Button7_Click(object sender, EventArgs e) * { * List<double> sigmas = new List<double>(); * List<string> lines = new List<string>(); * Geodesic geodesic = new Geodesic(); * * Equation step = new Equation(1) / geodesic.MaxRibIndex; * for (int i =0; i<=geodesic.MaxRibIndex;i++) * { * Vector3D point = geodesic.GetStrikePoint(i); * double sigma = geodesic.Sigma(point); * sigmas.Add(sigma); * lines.Add((step * i).ToString() + "\t" + sigma.ToString());// + "\t" + sigma.Equation); * } * using (SaveFileDialog sfd = new SaveFileDialog()) * { * if (sfd.ShowDialog() != DialogResult.OK) * return; * * System.IO.File.WriteAllLines(sfd.FileName, lines); * } * }*/ private void Button8_Click(object sender, EventArgs e) { List <double> sigmas = new List <double>(); List <string> lines = new List <string>(); Geodesic geodesic = new Geodesic(); for (int i = 0; i <= geodesic.MaxRibIndex; i++) { Vector3D point = geodesic.GetStrikePoint(i); double sigma = geodesic.Sigma(point); sigmas.Add(sigma); //List<string> equation = sigma.GetFullEquation(); //lines.Add((step * i).ToString() + "\t" + sigma.ToString()); //lines.AddRange(equation); lines.Add(point.X.ToString()); lines.Add(point.Y.ToString()); lines.Add(point.Z.ToString()); lines.Add(sigma.ToString()); lines.Add("-----------------------------------"); } using (SaveFileDialog sfd = new SaveFileDialog()) { if (sfd.ShowDialog() != DialogResult.OK) { return; } System.IO.File.WriteAllLines(sfd.FileName, lines); } }
public Variance VarianceOf(Geodesic geodesic) { List <double> areas = new List <double>(); double totalArea = 0; double maxArea = -10; double minArea = 10; double lengthMin = 10; double lengthMax = 0; double lengthTotal = 0; for (int i = 0; i < geodesic.MaxGridIndex; i++) { GridIndex index = geodesic.GetGridIndex(i); GeodesicGridTriangle triangle = index.GeodesicGridTriangle; double area = triangle.Area; areas.Add(area); totalArea += area; if (area > maxArea) { maxArea = area; } if (area < minArea) { minArea = area; } double a = (triangle.PointCA - triangle.PointAB).Magnitude; double b = (triangle.PointAB - triangle.PointBC).Magnitude; double c = (triangle.PointBC - triangle.PointCA).Magnitude; double maxLength = a > b ? a > c ? a : c : b > c ? b : c; double minLength = a < b ? a < c ? a : c : b < c ? b : c; if (maxLength > lengthMax) { lengthMax = maxLength; } if (minLength < lengthMin) { lengthMin = minLength; } lengthTotal += a + b + c; } Variance variance = new Variance(); variance.variance = maxArea / minArea; variance.max = maxArea; variance.min = minArea; variance.average = totalArea / geodesic.MaxGridIndex; variance.lengthMin = lengthMin; variance.lengthMax = lengthMax; variance.lengthAverage = lengthTotal / geodesic.MaxGridIndex / 3; return(variance); }
/* * public StrikeThroughPointPair(Equation mirrorDistance) * { * DistanceToScaledCenterLine = MathE.Abs(mirrorDistance); * Equation primaryDistance = MathE.Sqrt(new Equation(1) - MathE.Squared(DistanceToScaledCenterLine)); * Vector3D primaryScaled = Geodesic.MirrorPoint * primaryDistance + Geodesic.MirrorPerpendicular * DistanceToScaledCenterLine; * Vector3D secondaryScaled = Geodesic.MirrorPoint * primaryDistance - Geodesic.MirrorPerpendicular * DistanceToScaledCenterLine; * Right = Geodesic.ScaleEllipseIn(primaryScaled); * Left = Geodesic.ScaleEllipseIn(secondaryScaled); * }*/ public StrikeThroughPointPair(double mirrorDistance) { DistanceToScaledCenterLine = Math.Abs(mirrorDistance); double primaryDistance = Math.Sqrt(1 - DistanceToScaledCenterLine * DistanceToScaledCenterLine); Vector3D primaryScaled = Geodesic.MirrorPoint * primaryDistance + Geodesic.MirrorPerpendicular * DistanceToScaledCenterLine; Vector3D secondaryScaled = Geodesic.MirrorPoint * primaryDistance - Geodesic.MirrorPerpendicular * DistanceToScaledCenterLine; Right = Geodesic.ScaleEllipseIn(primaryScaled); Left = Geodesic.ScaleEllipseIn(secondaryScaled); }
public HybridGrid(int geodesicGeneration, int bisectGeneration) { this.geodesicGeneration = geodesicGeneration; this.bisectGeneration = bisectGeneration; geodesic = new Geodesic(geodesicGeneration - 2); TriangleCount = 1; for (int i = 0; i < bisectGeneration; i++) { TriangleCount *= 4; } }
/* * private void Button10_Click(object sender, EventArgs e) * { * Equation IcosahedronRibLength = new Equation(4) / MathE.Sqrt(new Equation(10) + MathE.Sqrt(new Equation(20))); * * Equation FrontViewLength = MathE.Sqrt(new Fraction(new Product(MathE.Squared(IcosahedronRibLength), 3), 4)); * Equation FrontViewLength13 = FrontViewLength / 3; * Equation FrontViewLength23 = FrontViewLength13 * 2; * * Vector3D ArcLeft = new Vector3D(-FrontViewLength23, 0, MathE.Sqrt(new Equation(1) - FrontViewLength23 * FrontViewLength23)); * Vector3D ArcRight = new Vector3D(FrontViewLength13, IcosahedronRibLength / 2, ArcLeft.Z); * Vector3D DefaultProjectionPoint = new Vector3D(ArcLeft.X, 0, ArcRight.Z * -2); * Equation length = DefaultProjectionPoint.Magnitude; * }*/ /* * private void OpenEquationFormButton_Click(object sender, EventArgs e) * { * using (SimplifyForm form = new SimplifyForm()) * form.ShowDialog(); * }*/ private void AnalyseButton_Click(object sender, EventArgs e) { using (SaveFileDialog sfd = new SaveFileDialog() { Filter = "*.csv|*.csv" }) { if (sfd.ShowDialog() != DialogResult.OK) { return; } Geodesic geodesic = new Geodesic(Convert.ToInt32(GenerationBox.Text)); List <string> lines = new List <string>(); string header = "Count;Index;IndexBin;Distance;DistanceEquation;X;Y;"; lines.Add(header); int i = 0; foreach (StrikeThroughPointPair pair in geodesic.StrikeThroughPoints) { string line = i.ToString() + ";"; i++; line += pair.LeftIndex.ToString() + ";"; line += Convert.ToString(pair.LeftIndex, 2) + ";"; line += (-pair.DistanceToScaledCenterLine).ToString() + ";"; //line += (-pair.DistanceToScaledCenterLine.Value).ToString()+";"; //line += (-pair.DistanceToScaledCenterLine).Content.Equation + ";"; //line += pair.Left.X.Value.ToString() + ";"; //line += pair.Left.Y.Value.ToString() + ";"; line += pair.Left.X.ToString() + ";"; line += pair.Left.Y.ToString() + ";"; lines.Add(line); line = ""; line += i.ToString() + ";"; i++; line += pair.RightIndex.ToString() + ";"; line += Convert.ToString(pair.RightIndex, 2) + ";"; line += pair.DistanceToScaledCenterLine.ToString() + ";"; //line += pair.DistanceToScaledCenterLine.Value.ToString() + ";"; //line += pair.DistanceToScaledCenterLine.Content.Equation + ";"; line += pair.Right.X.ToString() + ";"; line += pair.Right.Y.ToString() + ";"; //line += pair.Right.X.Value.ToString() + ";"; //line += pair.Right.Y.Value.ToString() + ";"; lines.Add(line); } } }
public GridIndex(Geodesic geodesic, int index) { Parent = geodesic; Width = geodesic.MaxRibIndex; A = index % Width; B = index / Width; C = Width - A - B - 1; Inverted = A >= Width - B; if (Inverted) { A = Width - A; B = Width - B; C = Width - A - B + 1; } }
private void Button4_Click(object sender, EventArgs e) { Geodesic geodesic = new Geodesic(); List <string> points = new List <string>(); for (int i = 0; i <= 64; i++) { points.Add(geodesic.GetStrikePoint(i).ToString()); } using (SaveFileDialog sfd = new SaveFileDialog()) { if (sfd.ShowDialog() != DialogResult.OK) { return; } System.IO.File.WriteAllLines(sfd.FileName, points); } }
private void Button5_Click(object sender, EventArgs e) { Geodesic geodesic = new Geodesic(1); List <string> areas = new List <string>(); for (int i = 0; i < geodesic.MaxGridIndex; i++) { GridIndex index = geodesic.GetGridIndex(i); GeodesicGridTriangle triangle = index.GeodesicGridTriangle; areas.Add(triangle.Area.ToString()); } using (SaveFileDialog sfd = new SaveFileDialog()) { if (sfd.ShowDialog() != DialogResult.OK) { return; } System.IO.File.WriteAllLines(sfd.FileName, areas); } }
private void DrawAreaVarianceButton_Click(object sender, EventArgs e) { int generation = Convert.ToInt32(GenerationBox.Text); Geodesic geodesic = new Geodesic(generation - 2); BisectGeodesic bisectGeodesic = new BisectGeodesic(generation); List <DrawTriangle> triangles = new List <DrawTriangle>(); List <DrawTriangle> bisectTriangles = new List <DrawTriangle>(); double minArea = 10; double maxArea = 0; double totalArea = 0; double totalBisectArea = 0; for (int i = 0; i < geodesic.MaxGridIndex; i++) { GridIndex index = geodesic.GetGridIndex(i); GeodesicGridTriangle triangle = index.GeodesicGridTriangle; double area = triangle.Area; if (area < minArea) { minArea = area; } if (area > maxArea) { maxArea = area; } totalArea += area; } foreach (SphericalTriangle triangle in bisectGeodesic.SphericalTriangles) { double area = triangle.Area; if (area < minArea) { minArea = area; } if (area > maxArea) { maxArea = area; } totalBisectArea += area; } double averageArea = totalArea / geodesic.MaxGridIndex; double averageBisectArea = totalBisectArea / bisectGeodesic.SphericalTriangles.Count; for (int i = 0; i < geodesic.MaxGridIndex; i++) { GridIndex index = geodesic.GetGridIndex(i); GeodesicGridTriangle triangle = index.GeodesicGridTriangle; DrawTriangle drawTriangle = new DrawTriangle() { point1 = triangle.PointAB, point2 = triangle.PointBC, point3 = triangle.PointCA }; drawTriangle.fillColor = GenerateEnhancedColorFor(triangle.Area, minArea, maxArea, averageArea); triangles.Add(drawTriangle); } foreach (SphericalTriangle triangle in bisectGeodesic.SphericalTriangles) { DrawTriangle drawTriangle = new DrawTriangle() { point1 = triangle.A, point2 = triangle.B, point3 = triangle.C }; drawTriangle.fillColor = GenerateEnhancedColorFor(triangle.Area, minArea, maxArea, averageBisectArea); bisectTriangles.Add(drawTriangle); } IllustrationForm illustrationForm = new IllustrationForm(); //using (IllustrationForm illustrationForm = new IllustrationForm()) { illustrationForm.triangles = triangles; illustrationForm.fill = true; illustrationForm.lines = false; illustrationForm.Text = "Cut Geodesic Grid"; illustrationForm.Show(); } IllustrationForm bisectForm = new IllustrationForm(); //using (IllustrationForm illustrationForm = new IllustrationForm()) { bisectForm.triangles = bisectTriangles; bisectForm.fill = true; bisectForm.lines = false; bisectForm.Text = "Bisect Geodesic Grid"; bisectForm.Show(); } DrawScale(minArea, maxArea, averageArea); }
/* * private void Button1_Click(object sender, EventArgs e) * { * StrikeThroughPointPair center = new StrikeThroughPointPair(0); * StrikeThroughPointPair bound = new StrikeThroughPointPair(Geodesic.ArcLeft.Dot(Geodesic.MirrorPerpendicular)); * * Equation oneThird = (center.Sigma * 2 + bound.Sigma) / 3; * Equation centerLineX = Math.Sin(oneThird); * Equation centerLineY = Math.Cos(oneThird); * * StrikeThroughPointPair topStrikeThrough = new StrikeThroughPointPair(centerLineX); * Line strikeLine = Line.Construct(topStrikeThrough.Right, new Vector3D(0, 0, 1)); * Vector3D projectionPoint = strikeLine.Intersect(Line.Construct(Geodesic.ArcTopRight, new Vector3D(0, 0, 0))); * StrikeThroughPointPair test = new StrikeThroughPointPair(bound.DistanceToScaledCenterLine); * * //Geodesic geodesic = new Geodesic(4,projectionPoint); * Geodesic geodesic = new Geodesic(7); * * Equation variance = VarianceOf(geodesic); * * using (SaveFileDialog sfd = new SaveFileDialog()) * { * if (sfd.ShowDialog() != DialogResult.OK) * return; * * List<string> lines = new List<string>(); * foreach(StrikeThroughPointPair pointPair in geodesic.StrikeThroughPoints) * { * lines.Add(pointPair.DistanceToScaledCenterLine.ToString() + "\t" + pointPair.DistanceOnScaledCenterLine.ToString()); * } * System.IO.File.WriteAllLines(sfd.FileName, lines); * } * * }*/ /* * private void Button2_Click(object sender, EventArgs e) * { * VarianceLabel.Text = (VarianceOf(new Geodesic(Convert.ToInt32(GenerationBox.Text)-2))*100-100).ToString()+"%"; * }*/ private void Button3_Click(object sender, EventArgs e) { Geodesic geodesic = new Geodesic(4); Plane plane = geodesic.StrikeThroughPoints[13].RightPlane; }
/* * private void DownShiftBox_Click(object sender, EventArgs e) * { * ShiftBox.Text = (Convert.ToDouble(ShiftBox.Text) / 2).ToString(); * } * * private void UpShiftBox_Click(object sender, EventArgs e) * { * ShiftBox.Text = (Convert.ToDouble(ShiftBox.Text) * 2).ToString(); * } * * private void UpButton_Click(object sender, EventArgs e) * { * VarianceBox.Text = (Convert.ToDouble(VarianceBox.Text) + Convert.ToDouble(ShiftBox.Text)).ToString(); * } * * private void DownButton_Click(object sender, EventArgs e) * { * VarianceBox.Text = (Convert.ToDouble(VarianceBox.Text) - Convert.ToDouble(ShiftBox.Text)).ToString(); * }*/ /* * private void VarianceBox_TextChanged(object sender, EventArgs e) * { * try * { * Vector3D projectionPoint = Geodesic.DefaultProjectionPoint * new Equation(Convert.ToDouble(VarianceBox.Text),"Custom"); * Geodesic geodesic = new Geodesic(0, projectionPoint); * Equation variance = VarianceOf(geodesic); * VarianceLabel.Text = variance.ToString(); * } * catch * { * * } * }*/ /// <summary> /// Calculate the area variance for both bisect and new geodesic grid for each generation up to the given one. /// This is put in a csv file. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void VarianceButton_Click(object sender, EventArgs e) { using (SaveFileDialog sfd = new SaveFileDialog() { Filter = "*.csv|*.csv" }) { if (sfd.ShowDialog() != DialogResult.OK) { return; } List <string> result = new List <string>(); result.Add("generation,bisect min,bisect max, bisect average, projection point min, projection point max, projection point average," + "bisect length min, bisect length max, bisect length average, projection length min, projection length max, projection length average"); int maxGeneration = Convert.ToInt32(GenerationBox.Text); for (int generation = 1; generation <= maxGeneration; generation++) { BisectGeodesicLowMemory bisectGeodesic = new BisectGeodesicLowMemory(generation); double min = 10; double max = 0; double total = 0; double lengthMin = 10; double lengthMax = 0; double lengthTotal = 0; //foreach (SphericalTriangle triangle in bisectGeodesic.SphericalTriangles) for (int i = 0; i < bisectGeodesic.TriangleCount; i++) { SphericalTriangle triangle = bisectGeodesic.GetTriangle(i); double area = triangle.Area; if (area < min) { min = area; } if (area > max) { max = area; } total += area; double ab = (triangle.A - triangle.B).Magnitude; double bc = (triangle.B - triangle.C).Magnitude; double ca = (triangle.C - triangle.A).Magnitude; double maxLength = ab > bc ? ab > ca ? ab : ca : bc > ca ? bc : ca; double minLength = ab < bc ? ab < ca ? ab : ca : bc < ca ? bc : ca; if (maxLength > lengthMax) { lengthMax = maxLength; } if (minLength < lengthMin) { lengthMin = minLength; } lengthTotal += ab + bc + ca; } double average = total / bisectGeodesic.TriangleCount; double averageLength = lengthTotal / bisectGeodesic.TriangleCount / 3; double bisectVariance = max / min; Geodesic geodesic = new Geodesic(generation - 2); Variance geodesicViariance = VarianceOf(geodesic); result.Add(generation.ToString() + "," + min.ToString() + "," + max.ToString() + "," + average.ToString() + "," + geodesicViariance.min.ToString() + "," + geodesicViariance.max.ToString() + "," + geodesicViariance.average.ToString() + "," + lengthMin.ToString() + "," + lengthMax.ToString() + "," + averageLength.ToString() + "," + geodesicViariance.lengthMin.ToString() + "," + geodesicViariance.lengthMax.ToString() + "," + geodesicViariance.lengthAverage.ToString() ); } File.WriteAllLines(sfd.FileName, result); } }