modified from side drawing to point drawing
This commit is contained in:
parent
26d51b9423
commit
55e38d49f4
1 changed files with 88 additions and 8 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
using Avalonia.Controls.Selection;
|
using System.Reflection.Metadata;
|
||||||
|
using Avalonia.Controls.Selection;
|
||||||
using LeoTurtle;
|
using LeoTurtle;
|
||||||
|
|
||||||
namespace PinwheelTiling;
|
namespace PinwheelTiling;
|
||||||
|
|
@ -23,27 +24,106 @@ public static class PinwheelTilingPath
|
||||||
const double sideA = 40.0D;
|
const double sideA = 40.0D;
|
||||||
const double sideB = 80.0D;
|
const double sideB = 80.0D;
|
||||||
double sideC = CalculateHyptonuse(sideA, sideB);
|
double sideC = CalculateHyptonuse(sideA, sideB);
|
||||||
MakeTriangle(turtle, sideA, sideB, sideC);
|
|
||||||
|
_endPoint = new Point(_startPoint.X + sideB, _startPoint.Y + sideA);
|
||||||
|
Triangle triangle = MakeTriangle(_startPoint, _endPoint);
|
||||||
|
Triangle[] subdivision = GetSubdivision(triangle);
|
||||||
|
|
||||||
|
DrawSubdivision(turtle, subdivision);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO - implement your algorithm
|
private static Triangle MakeTriangle(Point startingPoint,
|
||||||
private static void MakeTriangle(SmartTurtle turtle, double sideA, double sideB, double sideC)
|
Point endingPoint)
|
||||||
{
|
{
|
||||||
|
Point pointA = startingPoint;
|
||||||
|
Point pointB = endingPoint;
|
||||||
|
Point pointC = new Point(endingPoint.X, startingPoint.Y);
|
||||||
|
|
||||||
|
return new Triangle(pointA, pointB, pointC);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Triangle[] GetSubdivision(Triangle triangle)
|
||||||
|
{
|
||||||
|
double sideA = triangle.B.Y - triangle.C.Y;
|
||||||
|
double sideB = triangle.C.X - triangle.A.X;
|
||||||
|
double sideC = CalculateHyptonuse(sideA, sideB);
|
||||||
|
Point startingPoint = new Point(triangle.A.X, triangle.A.Y);
|
||||||
|
Point endingPoint = new Point(triangle.B.X, triangle.B.Y);
|
||||||
|
|
||||||
|
//calculate parent sides
|
||||||
double height = CalculateHeight(sideA, sideB, sideC);
|
double height = CalculateHeight(sideA, sideB, sideC);
|
||||||
double sideE = height / 2;
|
double sideE = height / 2;
|
||||||
double sideF = CalculateHyptonuse(sideE, height);
|
//double sideF = CalculateHyptonuse(sideE, height);
|
||||||
_endPoint = new Point(_startPoint.X + sideB, _startPoint.Y + sideA);
|
|
||||||
|
|
||||||
//Draw it now
|
//calculate additional sides that are part of the parent triangle
|
||||||
DrawTriangle(turtle, sideA, sideB, sideC, height, sideE, sideF);
|
double sideB1 = sideB / 2;
|
||||||
|
double sideC1 = Math.Sqrt(Math.Pow(sideA, 2) - Math.Pow(height, 2));
|
||||||
|
//double sideC2;
|
||||||
|
double sideC3 = Math.Sqrt(Math.Pow(sideB1, 2) - Math.Pow(sideE, 2));
|
||||||
|
|
||||||
|
//calculate additional sides that are |not part/not important at all| for the parent triangle
|
||||||
|
double heightOfTriangle0 = CalculateHeight(sideC1, height, sideA);
|
||||||
|
double heightOfTriangle1 = CalculateHeight(sideE, height, sideB1);
|
||||||
|
double heightOfTriangle2 = CalculateHeight(sideE, sideC3, sideB1);
|
||||||
|
double sideB1SegmentOfTriangle1 = Math.Sqrt(Math.Pow(sideE, 2) - Math.Pow(heightOfTriangle1, 2));
|
||||||
|
double sideB1SegmentOfTriangle2 = Math.Sqrt(Math.Pow(sideE, 2) - Math.Pow(heightOfTriangle2, 2));
|
||||||
|
double heightOfAllExceptTriangle0 = CalculateHeight(height, sideC - sideC1, sideB);
|
||||||
|
double sideB1SegmentOfAllTrianglesExcept0
|
||||||
|
= Math.Sqrt(Math.Pow(sideC - sideC1, 2) - Math.Pow(heightOfAllExceptTriangle0, 2));
|
||||||
|
|
||||||
|
//create Points
|
||||||
|
Point pointA = startingPoint;
|
||||||
|
Point pointB = endingPoint;
|
||||||
|
Point pointC = new Point(endingPoint.X, startingPoint.Y);
|
||||||
|
Point pointD = new Point(startingPoint.X + sideB1SegmentOfAllTrianglesExcept0, startingPoint.Y + heightOfAllExceptTriangle0);
|
||||||
|
Point pointE = new Point(startingPoint.X + sideB1 - sideB1SegmentOfTriangle2, startingPoint.Y + heightOfTriangle2);
|
||||||
|
Point pointF = new Point(startingPoint.X + sideB1, startingPoint.Y);
|
||||||
|
Point pointH = new Point(startingPoint.X + sideB - sideB1SegmentOfTriangle1, startingPoint.Y + heightOfTriangle1);
|
||||||
|
|
||||||
|
Triangle triangle0 = new Triangle(pointC, pointB, pointD);
|
||||||
|
Triangle triangle1 = new Triangle(pointF, pointC, pointH);
|
||||||
|
Triangle triangle2 = new Triangle(pointA, pointF, pointE);
|
||||||
|
Triangle triangle3 = new Triangle(pointF, pointD, pointH);
|
||||||
|
Triangle triangle4 = new Triangle(pointD, pointF, pointE);
|
||||||
|
|
||||||
|
Triangle[] subdivisionTriangles = { triangle0, triangle1, triangle2, triangle3, triangle4 };
|
||||||
|
|
||||||
|
return subdivisionTriangles;
|
||||||
|
|
||||||
double CalculateHeight(double a, double b, double c)
|
double CalculateHeight(double a, double b, double c)
|
||||||
{
|
{
|
||||||
|
//using Heron's formula
|
||||||
double s = (a + b + c) / 2;
|
double s = (a + b + c) / 2;
|
||||||
return (2 / c) * Math.Sqrt(s * (s - a) * (s - b) * (s - c));
|
return (2 / c) * Math.Sqrt(s * (s - a) * (s - b) * (s - c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void DrawSubdivision(SmartTurtle turtle, Triangle[] subdivision)
|
||||||
|
{
|
||||||
|
foreach (var triangle in subdivision)
|
||||||
|
{
|
||||||
|
DrawSimpleTriangle(turtle, triangle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void DrawSimpleTriangle(SmartTurtle turtle, Triangle triangle)
|
||||||
|
{
|
||||||
|
turtle.Teleport(triangle.A.X, triangle.A.Y);
|
||||||
|
|
||||||
|
double sideAB = DistanceBetweenPoints(triangle.A, triangle.B);
|
||||||
|
double sideBC = DistanceBetweenPoints(triangle.B, triangle.C);
|
||||||
|
double sideCA = DistanceBetweenPoints(triangle.C, triangle.A);
|
||||||
|
|
||||||
|
turtle.LookAt(triangle.B.X, triangle.B.Y);
|
||||||
|
turtle.MoveForward(sideAB);
|
||||||
|
|
||||||
|
turtle.LookAt(triangle.C.X, triangle.C.Y);
|
||||||
|
turtle.MoveForward(sideBC);
|
||||||
|
|
||||||
|
turtle.LookAt(triangle.A.X, triangle.A.Y);
|
||||||
|
turtle.MoveForward(sideCA);
|
||||||
|
}
|
||||||
|
|
||||||
private static void DrawTriangle(SmartTurtle turtle, double a, double b, double c, double h, double e, double f)
|
private static void DrawTriangle(SmartTurtle turtle, double a, double b, double c, double h, double e, double f)
|
||||||
{
|
{
|
||||||
//Draw base triangle
|
//Draw base triangle
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue