# Support Vector

## Recommended Posts

Hi,

Is the following function for a support vector correct?

class Vector2
{
public Vector2 SupportVector()
{
if (Math.Abs(X) > Math.Abs(Y))
return new Vector2(X, 0);
else
return new Vector2(0, Y);
}
}

Edited by Gavin Williams

##### Share on other sites
alvaro    21246
I don't think "support vector" means anything without context. Do you have a definition or something else we can work with?

##### Share on other sites

Oh right, so I'm working on a physics engine ... contact normals. I've read about support vectors, but I can't find a definition, or code. I'm assuming a support vector is the orthogonal projection with greatest influence on V.

##### Share on other sites
jmpep    375

I'm sure it would help us if you gave name to letters. What's X and Y in your function? (I mean, coordinates of what?). What's V in your latest post?

##### Share on other sites
Doublefris    316

I think you mean the support vertex, which is the max dot product of a particular direction vector with the vertices of a (convex) polygon A.

Look at Dirk Gregorius 2013 slides, he explains it well.

##### Share on other sites
DonDickieD    2751

The support point is the furthest (extreme) point in a given direction:

int Support( const std::vector< vector2 >& vertices, const vector2& vDirection )
{
float flBestDistance = -FLT_MAX;
int nBestVertex = -1;

for ( int nVertex = 0; nVertex < nVertexCount; ++nVertex )
{
float flDistance = DotProduct( vertices[ nVertex ], vDirection );
if ( flDistance > flBestDistance )
{
flBestDistance = flDistance;
nBestVertex = nVertex;
}
}

return nBestVertex;
}

Edited by Dirk Gregorius

##### Share on other sites

@Javier - The X and Y are the x and y ordinates of a Vector2, this is c#, not c++, so a Vector is a geometric vector, not an array, or anything like that.

I wanted to make sure that i was using the right terminology, but it seems from the mixed responses that there is no single definition, and it can mean any number of things. I'll just call it a support vector for now.

Thanks all.

##### Share on other sites
Buckeye    10747

@Javier - The X and Y are the x and y ordinates of a Vector2, this is c#, not c++, so a Vector is a geometric vector, not an array, or anything like that.

Editing your posted code and then criticizing a previous response is bad style. Your original post did not define X or Y or provide any context.

##### Share on other sites
ferrous    6137

In a Vector2, X and Y seem fairly obvious.  Support Vector, the definition seems a bit different than how Dirk defined it (I kinda love that someone mentions the GDC slides of someone, and then that someone then replies to the thread).  If you're looking for the vector orthogonal, that's not right.

Vector2 perpVector = new Vector2(-Y, X);  (or the negative of that for the other direction, and I'd have to double check, but that first one is the 'left' vector, the negative is the 'right' vector, if you consider the existing vector to be 'forward')

Edited by ferrous

##### Share on other sites
jmpep    375

In a Vector2, X and Y seem fairly obvious.

Sure, but at the first version of your post the SupportVector function was not inside a Vector2 class. It can be seen in your post's history: http://www.gamedev.net/index.php?app=forums&module=extras&section=postHistory&pid=5143649. I imagined they were components of a vector, but even if they were I had no clue about what that vector would be. Saying something is a vector is as useful as saying something is a number. Both entities have no meaning by themselves...

Anyway, this doesn't contribute to the subject. I hope the answers you have are what you were looking for.

##### Share on other sites

@Javier - The X and Y are the x and y ordinates of a Vector2, this is c#, not c++, so a Vector is a geometric vector, not an array, or anything like that.

Editing your posted code and then criticizing a previous response is bad style. Your original post did not define X or Y or provide any context.

Sorry if it sounded like a criticism, I didn't mean it as a criticism. I meant it as a clarification. And i edited the question to clarify what X and Y are. Though I can see that such an edit then degrades the clarity of the conversation.

##### Share on other sites
alvaro    21246

Hi,

Is the following function for a support vector correct?

class Vector2
{
public Vector2 SupportVector()
{
if (Math.Abs(X) > Math.Abs(Y))
return new Vector2(X, 0);
else
return new Vector2(0, Y);
}
}


I would call that function something like `LongestProjectionToCoordinateAxis'.