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 8685297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:31:57+00:00 2026-06-12T22:31:57+00:00

this is my first time posting on a forum. But I guess I will

  • 0

this is my first time posting on a forum. But I guess I will just jump in and ask.. I am trying to draw a rectangle with x, y, width, height, and angle. I do not want to create a graphics 2D object and use transforms. I’m thinking that’s an inefficient way to go about it. I am trying to draw a square with rotation using a for loop to iterate to the squares width, drawing lines each iteration at the squares height. My understanding of trig is really lacking so… My current code draws a funky triangle. If there is another question like this with an answer sorry about the duplicate. If you have got any pointers on my coding I would love some corrections or pointers.

/Edit: Sorry about the lack of a question. I was needing to know how to use sine and cosine to draw a square or rectangle with a rotation centered at the top left of the square or rectangle. By using sin and cos with the angle to get the coordinates (x1,y1) then using the sin and cos functions with the angle plus 90 degrees to get the coordinates for (x2,y2). Using the counter variable to go from left to right drawing lines from top to bottom changing with the angle.

for (int s = 0; s < objWidth; s++){

       int x1 = (int)(s*Math.cos(Math.toRadians(objAngle)));
       int y1 = (int)(s*Math.sin(Math.toRadians(objAngle)));

       int x2 = (int)((objWidth-s)*Math.cos(Math.toRadians(objAngle+90)));
       int y2 = (int)((objHeight+s)*Math.sin(Math.toRadians(objAngle+90)));

       b.setColor(new Color((int)gArray[s]));
       b.drawLine(objX+x1, objY+y1, objX+x2, objY+y2);

}
  • 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. Editorial Team
    Editorial Team
    2026-06-12T22:31:59+00:00Added an answer on June 12, 2026 at 10:31 pm

    It is called the Rotation matrix.
    If your lines has the following coordinates before rotation:

    line 1: (0, 0) – (0, height)

    line 2: (1, 0) – (1, height)

    …

    line width: (width, 0) – (width, height)

    Then applying the rotation matrix transform will help you:

    for (int s = 0; s < objWidth; s++){
      int x1 = cos(angle)*s
      int y1 = sin(angle)*s
    
      int x2 = s * cos(angle) - objHeight * sin(angle)
      int y2 = s * sin(angle) + objHeight * cos(angle) 
    
    //the rest of code
    }
    

    Hope I didn’t make a mistakes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first time posting on StackOverflow but this site is awesome. Thanks
use this website a lot but first time posting. My program creates a number
This is my first time posting -- I found similar issues but not anything
This is my first time posting to stackoverflow, but these threads have helped me
this is my first time posting here, but I didn't know where else to
First time posting, I will try to adhere to best practices. I'm trying to
This is my first time posting to Stack Overflow. I'm trying to build a
So this is my first time posting here but I'm more or less stumped.
First time posting here, will try to be succinct. This is a classic 'can't
First time posting on this forum, and also very new to coding. Sorry if

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.