From 26d51b9423bac61d860c99e12e0a437c0ce10a40 Mon Sep 17 00:00:00 2001 From: MarcUs7i <96580944+MarcUs7i@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:10:58 +0200 Subject: [PATCH] The basic works, the recursion is next --- PinwheelTiling/PinwheelTilingPath.cs | 68 +++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/PinwheelTiling/PinwheelTilingPath.cs b/PinwheelTiling/PinwheelTilingPath.cs index f292fde..b26b9e7 100644 --- a/PinwheelTiling/PinwheelTilingPath.cs +++ b/PinwheelTiling/PinwheelTilingPath.cs @@ -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); /// /// 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)); + } /// /// Converts an angel from degrees to radians.