Reflection in an arbitrary line
Hi, need help to reflect a triangle in a arbutrary line in 2D.
Dont now how to calc it...
thx
/Luger
//--------------------------------------------------------// 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 squaredfor(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.
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]
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]
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);
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);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement