• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Polygon Reflection

 
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello
i have been trying to implement a reflection in java using matrices
Here is my matrix


and here is the class:
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
… and what happens? Please write down what the algorithm you are using is. Then one can see whether you are reflecting the points correctly.
 
Vani Sweety
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is my class matrix:


Here is where i perform the transformation:


and here is in my main where i call the function:



it is not working
mayB the matrix or the functionis not well implemented
how can i implement reflection using matrix
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't show us any code at this stage; show us the algorithm.
 
Vani Sweety
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vani Sweety wrote:


 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That does not help.
 
Vani Sweety
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have use only method to implement the reflection
it takes the points of a polygon put in a matrix then perform sme calculation
put the data of the"reflected points" in another array
then add it to the graph
 
Marshal
Posts: 28175
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Vani Sweety
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what is the formula for reflection along a line? You need to work out the formula before you try writing any code.
 
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic