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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:53:19+00:00 2026-06-09T09:53:19+00:00

I am having a user draw a line on the screen, there is a

  • 0

I am having a user draw a line on the screen, there is a start point and a end point. If the user extends over a certain angle I change the position of the endpoint so the user cannot extend beyond the specified angle. However it seems that when I cacluate the angle the user is drawing and make suer it is not over MAX ANGLE, and set the angle to the MAX ANGLE, there is a difference. This can be seen by when I draw the line, once i get to a certain angle, the line jumps and locks at the MAX ANGLE, but there shouldnt be any jump, it should be smooth, like the line ran into a invisible barrier. This could just be me though, my PosX and PosY are floats.

    private void CheckAngle() {
    double adj = Math.abs(PosX - PosX2);
    double c1 = adj;
    double c2 = Math.abs(PosY - PosY2);
    double hyp = Math.hypot(c1, c2);


    double angle = Math.cos((adj/hyp));
    angle = angle * 100;


    if (angle > MAX_ANGLE) {


        double opp = (Math.tan(MAX_ANGLE) * Math.abs(PosX - PosX2));


        if (PosY > PosY2) {
            PosY2 =(float) (PosY - opp);
        } else {
            PosY2 =(float) (PosY + opp);
        }

    }
}

My answer was a combination of using radians, as well as unsing

    Math.acos() & Math.atan()

so the final code looks like this

    private void CheckAngle() {
    double adj = Math.abs(PosX - PosX2);
    double opp = Math.abs(PosY - PosY2);
    double hyp = Math.sqrt((adj*adj)+(opp*opp));


    double angle = Math.acos((adj/hyp));
    angle = angle * 100;
    angle = Math.toRadians(angle);

    if (angle > MAX_ANGLE) {


        opp = (Math.atan(MAX_ANGLE) * adj);


        if (PosY > PosY2) {
            PosY2 =(float) (PosY - opp);
        } else {
            PosY2 =(float) (PosY + opp);
        }

    }
}
  • 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-09T09:53:20+00:00Added an answer on June 9, 2026 at 9:53 am

    Here’s the conversion:

    final double MAX_ANGLE = Math.toRadians(80);
    

    Note that this is identical to saying:

    final double MAX_ANGLE = 80 * Math.PI / 180;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made this application that lets the user draw a line on the screen
I'm creating an application where the user can draw a line on a screen
i'm trying to draw a Graph with a user-friendly timeline having every day/week (to
I'm experimenting with letting the iPhone user draw using the canvas and then having
I am making an app that allows the user to draw on the screen
I'm having a user control (referred to as 'parent') which dynamically adds or removes
I am having a user object which has one-to-many relation with Address object. My
I just want to get email id of user having phone number given. so
Hai am having a WPF user control in my WPF Form, when i click
Hai am having a WPF user control, when i use that control in another

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.