Simplify 3-D Plot (C#) folder structure

This commit is contained in:
Zev Spitz
2022-01-17 15:11:35 +02:00
parent eded164f64
commit eaed38c036
4 changed files with 11 additions and 20 deletions

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
namespace Plot
{
internal static class Function
{
internal static IEnumerable<IEnumerable<int>> GetRows()
{
for (var x = -30f; x <= 30f; x += 1.5f)
{
yield return GetValues(x);
}
}
private static IEnumerable<int> GetValues(float x)
{
var zPrevious = 0;
var yLimit = 5 * (int)(Math.Sqrt(900 - x * x) / 5);
for (var y = yLimit; y >= -yLimit; y -= 5)
{
var z = GetValue(x, y);
if (z > zPrevious)
{
zPrevious = z;
yield return z;
}
}
}
private static int GetValue(float x, float y)
{
var r = (float)Math.Sqrt(x * x + y * y);
return (int)(25 + 30 * Math.Exp(-r * r / 100) - 0.7f * y);
}
}
}