Advertisement

Problems understanding Magic's source

Started by March 15, 2002 03:07 PM
5 comments, last by FXO 22 years, 10 months ago
Hey there! I''m trying to test the "distance between triangle and sphere"-code from Magic Software, but I don''t understand it all (and even less when I read the .pdf). I don''t understand what "rkTri.EdgeX()" does. The triangles are stored in a strange way, they only store the origin, and two vectors... Also, I don''t get what the parameters "pfSParam" and "pfTParam" are. Does anybody know/have any pointer to additional documentation?
  
const real Vector3::SqrDistance (const Vector3& rkPoint, const Triangle& rkTri, real* pfSParam, real* pfTParam) const
{
    Vector kDiff = rkTri.Origin() - rkPoint;
    real fA00 = rkTri.Edge0().SquaredLength();
    real fA01 = rkTri.Edge0().Dot(rkTri.Edge1());
    real fA11 = rkTri.Edge1().SquaredLength();

    real fB0 = kDiff.Dot(rkTri.Edge0());
    real fB1 = kDiff.Dot(rkTri.Edge1());

  
Thank you for your time. /Fredrik Olsson
Perhaps the other two points are obtained by adding the vectors to the origin point of the tri? Looking at that code I have no idea the variable names are slightly cryptic looking to me, I mean fA00 what the hell is that for?
Advertisement
quote:

Perhaps the other two points are obtained by adding the vectors to the origin point of the tri?



Yes, that seems reasonable.

quote:

Looking at that code I have no idea the variable names are slightly cryptic looking to me, I mean fA00 what the hell is that for?



I''ll drink to that.
I''m just trying to make it so that I can test the code, then it will probably be easier to understand it.

I think your right about the triangle structure, but what could edge0 be?
To me it looks like it''s taking the squared length of the first edge of the triangle, taking the dot product of the first two edges of the triangle then taking the squared length of the second edge. Then I think it''s taking dot products of the two edges with the difference between the point and the triangle origin. What the point of that is I have no idea heh.
quote:
I don''t understand what "rkTri.EdgeX()" does.
The triangles are stored in a strange way, they only store the origin, and two vectors...

Also, I don''t get what the parameters "pfSParam" and "pfTParam" are.



Hej Fredrik!

Given a triangle specified by three points, A, B, and C,
an equivalent formulation is as:

Point Origin = A;
Vector Edge0 = B-A;
Vector Edge1 = C-A;

This is the representation Dave''s using in the code you
posted.

The parameters pfSParam and pfTParam specify the point on
the triangle closest to the query point (the sphere center).
In fact, they are two of the three barycentric coordinates
for that point.

The actual position of the closest point on the triangle can
be computed as:

Point P = A + Edge0 * (*pfSParam) + Edge1 * (*pfTParam);

---
Christer Ericson
Sony Computer Entertainment, Santa Monica
Thank you very much!

You have no idea of how glad I am to finally have this working

/Fredrik Olsson
Advertisement
Ignore this message, I found the problem.
I found old code (pre-this-post , that I used to try to get the function working:

Vector kDiff = rkTri.Center() - rkPoint;
instead of:
Vector kDiff = rkTri[0] - rkPoint;



=============================================================
My intersectionpoint on the triangle has got a litte offset...
It is at "i" when the point is at "p", this is always true, no matter the dimensions/origin of the triangle.


             _________       A       /B      / \  i  /         \   /    /  p  \ /    _ _ _ _C// p = point center// i = intersection point got by:// Point P = A + Edge0 * (*pfSParam) + Edge1 * (*pfTParam);// (and in code)Vector Edge0(Tri[1] - Tri[0]);Vector Edge1(Tri[2] - Tri[0]);Vector ClosestPoint(Tri[0] + Edge0 * pfSParam + Edge1 * pfTParam);      


I tried to change lots of +/- in the final point calculation, but I only get even stanger values.


[edited by - FXO on March 16, 2002 10:43:46 AM]

[edited by - FXO on March 16, 2002 10:54:41 AM]

This topic is closed to new replies.

Advertisement