Code Monkey home page Code Monkey logo

Comments (6)

nyers33 avatar nyers33 commented on May 22, 2024 1

With commit 'f2871569f529413e55251dc794398ebf58bcd5e5' you can access the lambdas (barycentric coordinates for each vertex) and the points from P & Q that form the simplex. Somehow these are not available in more recent commits.
And the code for calculating the witness points is:

dd = gjk (bd1, bd2, &s);

// witness points
double wOnA[3];
double wOnB[3];

wOnA[0] = 0.0f; wOnA[1] = 0.0f; wOnA[2] = 0.0f;
wOnB[0] = 0.0f; wOnB[1] = 0.0f; wOnB[2] = 0.0f;
for (int idx = 0; idx < s.nvrtx; idx++)
{
	wOnA[0] += s.p[idx][0] * s.lambdas[idx];
	wOnA[1] += s.p[idx][1] * s.lambdas[idx];
	wOnA[2] += s.p[idx][2] * s.lambdas[idx];
	
	wOnB[0] += s.q[idx][0] * s.lambdas[idx];
	wOnB[1] += s.q[idx][1] * s.lambdas[idx];
	wOnB[2] += s.q[idx][2] * s.lambdas[idx];
}

I haven't tested it too much but works fine for the tutorial sample.

And my issue: somehow the code doesn't return the correct witness point when one of the input object is a single point (distance is correct). Any ideas?

from opengjk.

MattiaMontanari avatar MattiaMontanari commented on May 22, 2024

This is similar to #2 as the weights are the barycentric coordinates. However, the way to implement this correctly requires more referencing and data cache that I avoided to keep the code faster. Also, the separating vector is in general not unique and this may cause problems in to the applications. For these reasons, I decided not to included this feature.

However, you can easily add it: The coordinates are stored here, the paper shows how to link these to the witness points.

You'll see that the distance sub-algorithm returns the subset of points whose barycentric coordinates
are greater than zero. The points with zero or negative barycentric coordinates are discarded from the simplex. So, in your example, rather than [(0.5, 0.5), (1, 0, 0)] you'll get [(0.5, 0.5), (1)]. Knowing these and the associated vertices (hence the data cache) you can compute the separating vector between the objects.

from opengjk.

magicbycalvin avatar magicbycalvin commented on May 22, 2024

Excellent, thank you! I will look into that.

from opengjk.

maaaaadn avatar maaaaadn commented on May 22, 2024

To the ones previously asking for witness points.
Did you implement this extra already and would like to share your contribution?
Otherwise, I'll try my luck as well.

from opengjk.

MattiaMontanari avatar MattiaMontanari commented on May 22, 2024

@nyers33 I cannot remember why took that away, but your code seems to be doing the right thing - thanks for sharing!

If you've got only one point and GJK exits quickly enough perhaps you end up processing garbage or default values. Can you printout what's in lambdas when you loop over idx? Maybe check also p and q.
In principle it should work, if it doesn't, please share the coordinates of the polygon and point that cause issue. I can look into that.

from opengjk.

nyers33 avatar nyers33 commented on May 22, 2024

@MattiaMontanari All the values from the simplex seem to be valid.

nvrtx = 3
lambdas = {0.5, 0.1, 0.4, garbage}
s.p = {{-50., -26., 0.}, {-50., -24., 5.}, {-50., -24., 0.}, {garbage}}
s.q = {{0., 0., 3.}, {0., 0., 3.}, {0., 0., 3.}, {garbage}}

input for dataP:

8
-50.0000000 -26.0000000 0.00000000
 50.0000000 -26.0000000 0.00000000
-50.0000000 -24.0000000 0.00000000
-50.0000000 -26.0000000 5.00000000
 50.0000000 -24.0000000 5.00000000
-50.0000000 -24.0000000 5.00000000
 50.0000000 -26.0000000 5.00000000
 50.0000000 -24.0000000 0.00000000

dataQ:

1
0.00000000 0.00000000 3.00000000

witness point on P calculated from simplex values: {-50.0, -25.0, 0.5}
correct answer: {0.0, -24.0, 3.0}
beam_pt_gjk
Thank you for having a look!

from opengjk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.