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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:11:02+00:00 2026-06-16T00:11:02+00:00

So I am having a big problem with drawing shapes using only lines. Lets

  • 0

So I am having a big problem with drawing shapes using only lines. Lets say I start to draw a line from a point on the middle of the screen and draw it forward at 100 distance in pixels and with angle 0 then I draw another line of the same length using angle 72 degrees and so on until 360 degrees. It should give me perfect pentagon where one line ends and another starts from that point, but the lines do not meet on the end it works perfect for squares where angles are 0/90/180/270 but I need to make it work for each shape even circles. I am using this thing for calculations:

_endingPointX = (_currentPostisionX + distance * _cosinuses[_angle]);

_endingPointY = (_currentPostisionY + distance * _sinuses[_angle]);

Where _cosinuses and _sinuses are arrays of doubles that contain the values for sinuses and cosinuses for each one of 360 degrees. And when drawing a line I need to cast these values to integer.

drawLine(_currentPostisionX, _currentPostisionY, (int) _endingPointX, (int) _endingPointY);

I do not know how to fix this and make the lines meet at the end of drawn shape. Been trying to figure out this for a few days but nothing comes to my mind.

Here is a screenshot:
enter image description here

Problem is solved thank you for the advice guys it was my mistake with using integer casting.

  • 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-16T00:11:03+00:00Added an answer on June 16, 2026 at 12:11 am

    Calculate all values in double and round immediately before drawing.
    Do not calculate further with the rounded ones.

    To draw a pentagon or a n- gon use something similar to:

         // number of corners of pentagon
        double numVertex = 5;
        // how much to change the angle for the next corner( of the turtle )
        double angleStep = 360.0 / numVertex;
        gc.moveTo(cx, cy - rad);
        for (int i= 1; i < numVertex; i++) {
             // total angle from 0 degrees
             double angle = i* angleStep;
             // px point of turtle is corner of pentagon
             double px = cx + rad * sin(angle * DEG_TO_RADIANS);
             // move turtle to
             gc.lineto((int)Math.round(px),
             (int)Math.round(py));
        }
         gc.lineTo(cx, cy - rad);
    

    If you use lineTo instead line chances are higher that the points meet.

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

Sidebar

Related Questions

I'm having a big problem when calling a web service from my WPF application.
The big problem I am having is when users copy things straight from WORD
I'm trying to draw on a map using markers. The problem I'm having is
So, I am having a big time problem. I am using CodeIgniter. I have
I'm using NET 2.0 with WinForms on C#. I am having a big problem
I'm having a big problem with my Lacie NAS 1TB drive, which doesn't seem
I'm having a pretty big problem trying to create navigation on my page. If
Here is a (big) example of the massive problem I am having, when this
I am having a big issue trying to delete from an UITableView. Just for
I have a big string having at most 100000 character. Instead of using string.charAt[index]

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.