Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 131611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:07:58+00:00 2026-05-11T06:07:58+00:00

Okay I’m trying to rotate a Java Polygon based on it’s original position of

  • 0

Okay I’m trying to rotate a Java Polygon based on it’s original position of angle 0. x, and y end up being converted to an int at the end of me using them, so I could understand not seeing some change, but when the difference in angles is big like 0 to 180 I think I should see something.

I’ve been at this for a little while and can’t think of what it is. Here’s the method. (Sorry if it messes up in the code tags, my firefox messes them up.)

public void rotate(double x, double y, obj o1) {     double dist = Math.sqrt(Math.pow(x - (o1.x + (o1.w/2)), 2) + Math.pow(y - (o1.y + (o1.h/2)),2));      x +=  (Math.sin(Math.toRadians(o1.a)) * dist);     y -=  (Math.cos(Math.toRadians(o1.a)) * dist);   } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:07:58+00:00Added an answer on May 11, 2026 at 6:07 am

    The values of x and y that are being manipulated in the rotate method will not be seen in the method that is calling it because Java passes method arguments by value.

    Therefore, the x and y values that are being changed in the rotate method is a local copy, so once it goes out of scope (i.e. returning from the rotate method to its calling method), the values of x and y will disappear.

    So currently, what is happening is:

    x = 10; y = 10; o1 = new obj(); o1.a = 100; rotate(x, y, obj); System.out.println(x);  // Still prints 10 System.out.println(y);  // Still prints 10 

    The only way to get multiple values back from a method in Java is to pass an object, and manipulate the object that is passed in. (Actually, a copy of the reference to the object is passed in when an method call is made.)

    For example, redefining rotate to return a Point:

    public Point rotate(int x, int y, double angle) {     // Do rotation.     return new Point(newX, newY); }  public void callingMethod() {     int x = 10;     int y = 10;     p = rotate(x, y, 45);     System.out.println(x);  // Should print something other than 10.     System.out.println(y);  // Should print something other than 10. } 

    That said, as Pierre suggests, using the AffineTransform would be much easier in my opinion.

    For example, creating a Rectangle object and rotating it using AffineTransform can be performed by the following:

    Rectangle rect = new Rectangle(0, 0, 10, 10);  AffineTransform at = new AffineTransform(); at.rotate(Math.toRadians(45));  Shape rotatedRect = at.createTransformedShape(rect); 

    AffineTransform can be applied to classes which implement the Shape interface. A list of classes implementing Shape can be found in the linked Java API specifications for the Shape interface.

    For more information on how to use AffineTransform and Java 2D:

    • Trail: 2D Graphics
    • Lesson: Advanced Topics in Java2D
      • Transforming Shapes, Text, and Images
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The std::exception class is defined as: namespace std { class… May 11, 2026 at 11:50 pm
  • Editorial Team
    Editorial Team added an answer You're missing the namespace on the DataOjbectMethod type. Either of… May 11, 2026 at 11:50 pm
  • Editorial Team
    Editorial Team added an answer Here's my unit that does it. I put this together… May 11, 2026 at 11:50 pm

Related Questions

Okay I'm still learning the ropes with the Entity Framework and I came across
Okay I know I asked about this before, and the answer was basically cache
Okay i am working on someone elses code. They do alot of this: char
Okay I have this RewriteRule which is supposed to redirect any request for the
Okay I'm trying to rotate a Java Polygon based on it's original position of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.