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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:17:32+00:00 2026-06-14T08:17:32+00:00

I need to draw a fill square, that square must be painted with lines

  • 0

I need to draw a fill square, that square must be painted with lines from center.
we can’t use java shapes

We have a center point and the pen must draw a line from center to the square edge in each angle.

The problem here is the Maths, what can i use to calculate the distance needed to paint. Because if i use always same distance it will draw a circle.

Thanks

  • 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-14T08:17:33+00:00Added an answer on June 14, 2026 at 8:17 am

    When drawing the square you can think of the length you need to draw at any angle as being the length of the hypoteneuse of a right-angled triangle. You can solve this with trigonometric ratios easily enough. The tricky part is that the base of the triangle moves around.

    Taking the example of a line at 45 degrees shown in the left half of the diagram below:

    You need to work out the length of the red line (hyp). You can use
    trigonometry to work out the length of hyp based on its angle to
    adj and the length of the
    adj. The length of the adj side is half the height of the
    square.

    The formula to use is:

    cos(angle) = adj/hyp

    rearranged:

    hyp = adj/cos(angle)

    The code would look something like this:

    public static double calculateLengthToPaint(double angle, double heightOfSquare){
          return  (heightOfSquare/2.0) / Math.cos(Math.toRadians(angle));
    }
    

    Unfortunately that’s not all though. This works perfectly for the first 45 degrees, but when angle > 45 degrees then the adjacent side of the triangle changes place (as can be seen in the right half of the diagram below). It keeps flipping over every 45 degrees.

    To handle this flipping you need to use the angle that’s passed into the method (the angle around the square from the 12 o’clock position) to work out the angle of the triangle we are imagining. I’ve modified the method above to add logic to work out the corrected angle.

    public static double calculateLengthToPaint(double angle, double heightOfSquare){
        double flippy = angle % 90;
        if (flippy > 45.0){
            flippy -= 90;
            flippy = Math.abs(flippy);
        }
          return  (heightOfSquare/2.0) / Math.cos(Math.toRadians(flippy));
    }
    

    Notes: This code takes it’s angle in degrees and only works for positive angles. Also, if you want to have the lines meet the square at even increments around the perimiter then you need to come up with a solution that uses the pythagorean theorem to work out the length of the hypoteneuse and then use trigonometry to work out the angle to draw it at.

    Hope that helps.

    Showing the triangle flipping over it's hypoteneuse at 45 degrees.

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

Sidebar

Related Questions

I need to draw a pushpin for the Bing Silverlight control that can have
I need to draw a Polygon from several points (I have their latitude, longitude).
I need to draw some simple lines within a Border control (or similar) that
I have a set of shapes created in visual basic that need to be
I need to draw a lot of lines. I'm using UIBezierPath for drawing lines
A need to draw an X in a View using Shapes , but the
I need to draw on a TPanel, ideally directly so I don't have another
I need to draw a .png image on an UIView. I have no clue
i need to draw a polygon of n sides given 2 points (the center
I have no experience in Quartz drawing. I need to draw a rectangle on

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.