Reflection in an arbitrary line

Started by
2 comments, last by Lugerns 20 years, 4 months ago
Hi, need help to reflect a triangle in a arbutrary line in 2D. Dont now how to calc it... thx /Luger
/Luger
Advertisement

//--------------------------------------------------------// 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.

Everything is better with Metal.

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]
/Luger
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);




Everything is better with Metal.

This topic is closed to new replies.

Advertisement