Skip to content

Commit

Permalink
Move MinkowskiDifference to a separate class
Browse files Browse the repository at this point in the history
  • Loading branch information
notgiven688 committed Oct 3, 2024
1 parent a084ab8 commit 1ffd232
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 41 deletions.
41 changes: 0 additions & 41 deletions src/GJKEPA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,47 +31,6 @@ public sealed class GJKEPA

public struct Statistics { public double Accuracy; public int Iterations; }

public struct MinkowskiDifference
{
public ISupportMappable SupportA, SupportB;
public JMatrix OrientationA, OrientationB;
public JVector PositionA, PositionB;

private void SupportMapTransformedA(in JVector direction, out JVector result)
{
JVector.TransposedTransform(direction, OrientationA, out JVector tmp);
SupportA.SupportMapping(tmp, out result);
JVector.Transform(result, OrientationA, out result);
JVector.Add(result, PositionA, out result);
}

private void SupportMapTransformedB(in JVector direction, out JVector result)
{
JVector.TransposedTransform(direction, OrientationB, out JVector tmp);
SupportB.SupportMapping(tmp, out result);
JVector.Transform(result, OrientationB, out result);
JVector.Add(result, PositionB, out result);
}

public void Support(in JVector direction, out JVector vA, out JVector vB, out JVector v)
{
// Calculates the support function S_{A-B}(d) = S_{A}(d) - S_{B}(-d),
// where 'd' represents the direction.
SupportMapTransformedA(direction, out vA);
SupportMapTransformedB(-direction, out vB);
JVector.Subtract(vA, vB, out v);
}

public void SupportMapping(in JVector direction, out JVector result)
{
this.Support(direction, out _, out _, out result);
}

public void SupportCenter(out JVector center)
{
JVector.Subtract(PositionA, PositionB, out center);
}
}

public class GJKEPASolver
{
Expand Down
43 changes: 43 additions & 0 deletions src/MinkowskiDifference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace GJKEPADemo;

public struct MinkowskiDifference
{
public ISupportMappable SupportA, SupportB;
public JMatrix OrientationA, OrientationB;
public JVector PositionA, PositionB;

private void SupportMapTransformedA(in JVector direction, out JVector result)
{
JVector.TransposedTransform(direction, OrientationA, out JVector tmp);
SupportA.SupportMapping(tmp, out result);
JVector.Transform(result, OrientationA, out result);
JVector.Add(result, PositionA, out result);
}

private void SupportMapTransformedB(in JVector direction, out JVector result)
{
JVector.TransposedTransform(direction, OrientationB, out JVector tmp);
SupportB.SupportMapping(tmp, out result);
JVector.Transform(result, OrientationB, out result);
JVector.Add(result, PositionB, out result);
}

public void Support(in JVector direction, out JVector vA, out JVector vB, out JVector v)
{
// Calculates the support function S_{A-B}(d) = S_{A}(d) - S_{B}(-d),
// where 'd' represents the direction.
SupportMapTransformedA(direction, out vA);
SupportMapTransformedB(-direction, out vB);
JVector.Subtract(vA, vB, out v);
}

public void SupportMapping(in JVector direction, out JVector result)
{
this.Support(direction, out _, out _, out result);
}

public void SupportCenter(out JVector center)
{
JVector.Subtract(PositionA, PositionB, out center);
}
}

0 comments on commit 1ffd232

Please sign in to comment.