-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/BenoitGeslain/Visuo-haptic-…
- Loading branch information
Showing
5 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/InverseWeightedDistance.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Linq; | ||
using UnityEngine; | ||
using VHToolkit; | ||
|
||
namespace VHToolkit | ||
{ | ||
public static class InverseWeightedDistance | ||
{ | ||
public static Vector3 Interpolate(Vector3[] x, Vector3[] target, float p, Vector3 position) { | ||
var weights = new float[x.Length]; | ||
int idx = 0; | ||
foreach (var (origin, targ) in x.Zip(target)) { | ||
var d = Vector3.Distance(origin, position); | ||
if (Mathf.Approximately(d, 0)) { | ||
return targ; | ||
} | ||
else { | ||
weights[idx++] = Mathf.Pow(d, -p); | ||
} | ||
} | ||
return target.Zip(weights, (t, w) => w * t).Aggregate(Vector3.zero, (a, b) => a + b) / weights.Sum(); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/InverseWeightedDistance.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters