#### Archived

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

# Reflection in an arbitrary line

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

## Recommended Posts

Hi, need help to reflect a triangle in a arbutrary line in 2D. Dont now how to calc it... thx /Luger

##### Share on other sites

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

##### 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 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);

1. 1
Rutin
26
2. 2
3. 3
4. 4
5. 5

• 9
• 13
• 19
• 14
• 9
• ### Forum Statistics

• Total Topics
632940
• Total Posts
3009329
• ### Who's Online (See full list)

There are no registered users currently online

×