Skip to content

Instantly share code, notes, and snippets.

@adrianseeley
adrianseeley / LTTBD.cs
Created May 3, 2015 13:22
Largest-Triangle-Three Bucket Downsampling Graphs in C# (For an Array of Floats) http://i.imgur.com/UwhvV45.png
public float[] Downsample(float[] array, int Length)
{
int insert = 0;
float[] window = new float[Length];
float[] window_x = new float[Length];
int bucket_size_less_start_and_end = Length - 2;
float bucket_size = (float)(array.Length - 2) / bucket_size_less_start_and_end;
int a = 0;
int next_a = 0;
@DanielWJudge
DanielWJudge / LargestTriangleThreeBuckets.cs
Last active March 16, 2024 15:23
Largest-Triangle-Three Bucket Downsampling Graphs in C#
public static IEnumerable<Tuple<double, double>> LargestTriangleThreeBuckets(List<Tuple<double, double>> data, int threshold)
{
int dataLength = data.Count;
if (threshold >= dataLength || threshold == 0)
return data; // Nothing to do
List<Tuple<double, double>> sampled = new List<Tuple<double, double>>(threshold);
// Bucket size. Leave room for start and end data points
double every = (double)(dataLength - 2) / (threshold - 2);