The basic works, the recursion is next

This commit is contained in:
MarcUs7i 2024-10-08 12:10:58 +02:00
parent 442e9be83f
commit 26d51b9423

View file

@ -1,4 +1,5 @@
using LeoTurtle;
using Avalonia.Controls.Selection;
using LeoTurtle;
namespace PinwheelTiling;
@ -7,6 +8,8 @@ public static class PinwheelTilingPath
private const double Alpha = 26.57D;
private const double Beta = 90D - Alpha;
private const double Gamma = 90D;
private static Point _startPoint = new Point(0, 0.2);
private static Point _endPoint = new Point(0, 0);
/// <summary>
/// Executes the logic for adding turtle path steps.
@ -17,10 +20,71 @@ public static class PinwheelTilingPath
{
var initialTriangle = new Triangle(new Point(2.5D, 10.0D), new Point(82.5D, 50.0D), new Point(82.5D, 10.0D));
// TODO - call your drawing/subdivision method
const double sideA = 40.0D;
const double sideB = 80.0D;
double sideC = CalculateHyptonuse(sideA, sideB);
MakeTriangle(turtle, sideA, sideB, sideC);
}
// TODO - implement your algorithm
private static void MakeTriangle(SmartTurtle turtle, double sideA, double sideB, double sideC)
{
double height = CalculateHeight(sideA, sideB, sideC);
double sideE = height / 2;
double sideF = CalculateHyptonuse(sideE, height);
_endPoint = new Point(_startPoint.X + sideB, _startPoint.Y + sideA);
//Draw it now
DrawTriangle(turtle, sideA, sideB, sideC, height, sideE, sideF);
double CalculateHeight(double a, double b, double c)
{
double s = (a + b + c) / 2;
return (2 / c) * Math.Sqrt(s * (s - a) * (s - b) * (s - c));
}
}
private static void DrawTriangle(SmartTurtle turtle, double a, double b, double c, double h, double e, double f)
{
//Draw base triangle
turtle.Teleport(_startPoint.X, _startPoint.Y);
turtle.Turn(90);
DrawLine(turtle, b, -Gamma);
DrawLine(turtle, a, -(Gamma + Alpha));
DrawLine(turtle, c);
//Draw the height
turtle.Teleport(_endPoint.X, _startPoint.Y);
turtle.Turn(-Alpha);
DrawLine(turtle, e, -90);
double[] halfHeightPosition = turtle.GetPosition();
DrawLine(turtle, h);
turtle.Teleport(halfHeightPosition[0], halfHeightPosition[1]);
turtle.Turn(-Alpha);
DrawLine(turtle, e, -(90 + Alpha));
DrawLine(turtle, f);
//reset angle
ResetAngle(turtle);
turtle.Turn(-Alpha);
DrawLine(turtle, e);
void DrawLine(SmartTurtle turtle, double distance, double angle = 0)
{
turtle.MoveForward(distance);
turtle.Turn(angle);
}
void ResetAngle(SmartTurtle turtle)
{
turtle.Teleport(turtle.GetPosition()[0], turtle.GetPosition()[1]);
}
}
private static double CalculateHyptonuse(double a, double b)
{
return Math.Sqrt(Math.Pow(a, 2) + Math.Pow(b, 2));
}
/// <summary>
/// Converts an angel from degrees to radians.