Archived

This topic is now archived and is closed to further replies.

Reflection in an arbitrary line

This topic is 5113 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts




//--------------------------------------------------------

// calcualte the "plane" equation from the line

// the plane has a normal perpendicular to the line

//--------------------------------------------------------

Vector2 N = (-Line.Dir.y, Line.Dir.x);
float d = Line.Point * N;
float n2 = N * N; // Normal length squared


for(int i = 0; i < 3; i ++)
{
//---------------------------------------

// calculate the siatance of the vertex to the plane

//---------------------------------------

float vn = V[i] * N;
float dist2 = d - vn;

//---------------------------------------

// mirror the point from the plane, by

// moving the point twice the distance

// towards the plane.

//---------------------------------------

V[i] += (2.0f * (dist2 / n2)) * N;
}


if line direction is normalised, n2 = 1.0f, so you can remove it from the equation.

Share this post


Link to post
Share on other sites
oliii,
N is a struct, white x and y (N.x, N.y)?
how do calc:
"float d = Line.Point * N;"
"float n2 = N * N;"
"float vn = V * N;"

thx


[edited by - lugerns on December 16, 2003 7:32:49 PM]

Share this post


Link to post
Share on other sites
this is a dot product

N is a vector

dot product of

A * B = A.x*B.x + A.y*B.y (2D)
A * B = A.x*B.x + A.y*B.y + A.z*Bz (3D)

the addition, multiplications, substraction are simple enough. they return vectors to

A + B = Vector(A.x+B.x, A.y+B.y);
A - B = Vector(A.x-B.x, A.y-B.y);
A * k = Vector(A.x*k, A.y*k);




Share this post


Link to post
Share on other sites