Skip to content

Commit

Permalink
Fix Sliderator producing very wrong velocities in some rare edge-cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
OliBomby committed Feb 10, 2025
1 parent 54d78c7 commit a6d2a93
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Mapping_Tools/Classes/MathUtil/BinarySearchUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ public class BinarySearchUtil {
/// <param name="checkFunc">Function which checks the validity of an instance of <see cref="T"/></param>
/// <returns></returns>
public static T ContinuousBinarySearch<T>(T lower, T upper, double epsilon, Func<T, T, double> distanceFunc, Func<T, T, T> midFunc, Func<T,bool> checkFunc) {
if (!checkFunc(lower) && checkFunc(upper))
// Bounds seem to be reversed
(lower, upper) = (upper, lower);

if (!checkFunc(lower))
return lower;

if (checkFunc(upper))
return upper;

while (distanceFunc(lower, upper) > epsilon) {
var mid = midFunc(lower, upper);

Expand Down
4 changes: 2 additions & 2 deletions Mapping_Tools/Classes/Tools/SlideratorStuff/Sliderator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private double GetSpeedAtTime(double time, double epsilon) {
private void GenerateNeurons() {
// These values are placeholders. Experimentation has to be done to find better parameters
const double maxOvershot = 32; // Max error in wantedLength
const double epsilon = 0.01; // Resolution for for speed differentiation
const double epsilon = 0.01; // Resolution for speed differentiation
const double deltaT = 0.02; // Size of time step

slider = new List<Neuron>();
Expand Down Expand Up @@ -184,7 +184,7 @@ private void GenerateNeurons() {
var newNeuron = new Neuron(nearestLatticePoint, time);
currentNeuron.Terminal = newNeuron;

currentNeuron.WantedLength = actualLength;
currentNeuron.WantedLength += actualLength;
slider.Add(currentNeuron);

currentNeuron = newNeuron;
Expand Down

0 comments on commit a6d2a93

Please sign in to comment.