Some quick parametrics. See how fast it is to homebrew this? I know I haven't completed a bunch of stuff but I'll get to it soon.

This commit is contained in:
That_One_Nerd 2024-04-02 09:53:42 -04:00
parent e5c985c060
commit 3b6ebc7b99
2 changed files with 65 additions and 1 deletions

View File

@ -0,0 +1,63 @@
using Graphing.Abstract;
using Graphing.Forms;
using Graphing.Parts;
using System;
using System.Collections.Generic;
namespace Graphing.Graphables;
public class ParametricEquation : Graphable, ITranslatableXY
{
private static int equationNum;
public double OffsetX { get; set; }
public double OffsetY { get; set; }
public double InitialT { get; set; }
public double FinalT { get; set; }
protected readonly ParametricDelegate equX, equY;
public ParametricEquation(double initialT, double finalT,
ParametricDelegate equX, ParametricDelegate equY)
{
equationNum++;
Name = $"Parametric Equation {equationNum}";
InitialT = initialT;
FinalT = finalT;
this.equX = equX;
this.equY = equY;
}
public override Graphable ShallowCopy() => new ParametricEquation(InitialT, FinalT, equX, equY);
public override IEnumerable<IGraphPart> GetItemsToRender(in GraphForm graph)
{
const int step = 10;
double epsilon = Math.Abs(graph.ScreenSpaceToGraphSpace(new Int2(0, 0)).x
- graph.ScreenSpaceToGraphSpace(new Int2(step / 2, 0)).x) / 5;
epsilon *= graph.DpiFloat / 192;
List<IGraphPart> lines = [];
Float2 previousPoint = GetPointAt(InitialT);
for (double t = InitialT; t <= FinalT; t += epsilon)
{
Float2 currentPoint = GetPointAt(t);
lines.Add(new GraphLine(previousPoint, currentPoint));
previousPoint = currentPoint;
}
return lines;
}
public Float2 GetPointAt(double t)
{
return new(equX(t) + OffsetX, equY(t) + OffsetY);
}
}
public delegate double ParametricDelegate(double t);

View File

@ -19,7 +19,8 @@ internal static class Program
Equation equA = new(Math.Sin),
equB = new(Math.Cos);
EquationDifference diff = new(2, equA, equB);
graph.Graph(equA, equB, diff);
ParametricEquation equC = new(0, 4, t => t * t - 1, t => Math.Sqrt(t) + t + 1);
graph.Graph(equA, equB, diff, equC);
Application.Run(graph);
}