Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitGeslain committed Jun 26, 2024
1 parent 6b9d60c commit 0694103
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static Func<Vector3, float> RepulsivePotential3D(List<Collider> obstacles
(x) => obstacles.Sum(o => 1 / Vector3.Distance(x, o.ClosestPoint(x)));

public static Func<Vector3, float> RepulsivePotential3D(List<Vector3> obstacles) =>
(x) => obstacles.Sum(o => 1 / (x - o).sqrMagnitude);
(x) => obstacles.Sum(o => 1 / Vector3.Distance(x, o));


public static Vector2 Gradient2v2(Vector2 x, List<Collider2D> obstaclescolliders) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using UnityEngine;

using VHToolkit;
using VHToolkit.Redirection;

public class PhysicalEnvironmentCalibration : MonoBehaviour {

Expand All @@ -18,19 +17,16 @@ void Start() {

// Update is called once per frame
void Update() {
List<Vector3> obs = new();


var dir = (bounds.First() - bounds.Last()).normalized;
int n = (int)(Vector3.Distance(bounds.Last(), bounds.First()) / eps);
for (int j = 0; j < n; j++) {
obs.Add(bounds.Last() + (j + 0.5f) * eps * dir);
}
for (int i = 1; i < bounds.Count; i++) {
dir = (bounds[i] - bounds[i - 1]).normalized;
n = (int) (Vector3.Distance(bounds[i - 1], bounds[i]) / eps);
for (int j = 0; j < n; j++) {
obs.Add(bounds[i - 1] + (j + 0.5f) * eps * dir);
}
List<Vector3> obs = new();
foreach (var(a, b) in bounds.Zip(bounds.Skip(1).Append(bounds.First())))
{
dir = (b - a).normalized;
n = (int) (Vector3.Distance(a, b) / eps);
obs.AddRange(Enumerable.Range(0, n - 1).Select(j => a + (j + 0.5f) * eps * dir));
}
Debug.Log(obs.Count);
obs.ForEach(o => Debug.Log(o));
Expand All @@ -39,10 +35,9 @@ void Update() {
}

private void OnDrawGizmos() {
for (int i = 1; i < bounds.Count; i++) {
Gizmos.DrawLine(bounds[i - 1], bounds[i]);
foreach (var (a, b) in bounds.Zip(bounds.Skip(1).Append(bounds.First()))) {
Gizmos.DrawLine(a, b);
}
Gizmos.DrawLine(bounds.Last(), bounds.First());
}

private Vector3 ComputeGradient(Transform user, List<Vector3> dividedObstacles) => Vector3.ProjectOnPlane(MathTools.Gradient3(
Expand Down

0 comments on commit 0694103

Please sign in to comment.