Vani Sweety

Ranch Hand

Posts: 93

1

posted 1 year ago

hello

i have been trying to implement a reflection in java using matrices

Here is my matrix

and here is the class:

i have been trying to implement a reflection in java using matrices

Here is my matrix

and here is the class:

Campbell Ritchie

Marshal

Posts: 56533

172

Vani Sweety

Ranch Hand

Posts: 93

1

Campbell Ritchie

Marshal

Posts: 56533

172

Vani Sweety

Ranch Hand

Posts: 93

1

posted 1 year ago

The problem here is this: You say your "reflecting" code doesn't do what you want. But you only show us the code and don't tell us what it is supposed to do. Neither do you give us any examples.

And we don't even know what "reflecting" means to you. In geometry you can reflect with respect to any plane; you seem to have a special plane in mind.

So:

1. What does "reflect" mean?

2. Give us an example of some output which disagrees with your definition of "reflect" and tell us what you think the right output would be.

And we don't even know what "reflecting" means to you. In geometry you can reflect with respect to any plane; you seem to have a special plane in mind.

So:

1. What does "reflect" mean?

2. Give us an example of some output which disagrees with your definition of "reflect" and tell us what you think the right output would be.

Vani Sweety

Ranch Hand

Posts: 93

1

posted 1 year ago

i have a graph panel where i can draw a polygon

i can translate the polygon

rotate the polygon by degree(input by user) at any point on the plane

and i must also implement the reflection of the polygon along a line

the problem is that the way i have implemented the class reflectPolygon is not working

it is drawing the polygon on the polygon itself

i have use matrix@D to implement the matrices to get the points of polygon

i can translate the polygon

rotate the polygon by degree(input by user) at any point on the plane

and i must also implement the reflection of the polygon along a line

the problem is that the way i have implemented the class reflectPolygon is not working

it is drawing the polygon on the polygon itself

i have use matrix@D to implement the matrices to get the points of polygon

Campbell Ritchie

Marshal

Posts: 56533

172

Piet Souris

Master Rancher

Posts: 2042

75

posted 1 year ago

A standard and simple way is: rotate your reflection axis so that it coincides with either the x- or the y-axis.

Do the reflection (chance the sign of either the x- or the y-coordinate), and rotate back.

That is a multiplication of three simple matrices.

If your reflection axis does not pass through the origin, you also need a translation. In that case, it is handy

to look at the way the 'AffineTransform' class works.

If this isn't an assignment, I would suggest using a Shape for your Polygon (Path2D). That would greatly

simplify your methods.

Do the reflection (chance the sign of either the x- or the y-coordinate), and rotate back.

That is a multiplication of three simple matrices.

If your reflection axis does not pass through the origin, you also need a translation. In that case, it is handy

to look at the way the 'AffineTransform' class works.

If this isn't an assignment, I would suggest using a Shape for your Polygon (Path2D). That would greatly

simplify your methods.