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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:25:54+00:00 2026-05-29T10:25:54+00:00

I know this isn’t a hard trig issue, but sadly I am math retarded.

  • 0

I know this isn’t a hard trig issue, but sadly I am math retarded.

I need to draw a line of 50 pixels from a known starting point along a known angle to an unknown ending point. The angle is derived from a starting point (400,400) and a mouse click; the line needs to be drawn towards the mouse click, but only 50 pixels towards the click.

I’ve google’d extensively and found a number of solutions, but it’s just not coming together for me.

Here is how I’m getting the angle.:

float angle = (float) Math.toDegrees(Math.atan2(400 - event.getY(), 400 - event.getX()));
float angleInDegrees = (angle + 270) % 360;

“event” is a mouse click.

float endX = 250 + 50 * (float)Math.cos(angleInDegrees);
float endY 250 + 50 * (float)Math.sin(angleInDegrees);

line.setStartX(400);
line.setStartY(400);
line.setEndX(endX);
line.setEndY(endY);

Everything I’ve found revolved around Math.cos and Math.sin but I’m still not getting it. I think the issue is related to mapping radians to scene coordinates, but I’m not sure. So people, in what way am I stupid? I’d appreciate any help.

  • 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-05-29T10:25:55+00:00Added an answer on May 29, 2026 at 10:25 am

    You don’t even have to deal with radians/degrees. Go back to the geometrical definition of sine and cosine: sine is opposite/hypotenuse, cosine is adjacent/hypotenuse. (“Opposite” and “adjacent” mean the legs of the right triangle respectively opposite and adjacent to the angle you’re taking the sine or cosine of).

    So:

    float opposite = event.getY() - 400;
    float adjacent = event.getX() - 400;
    float hypotenuse = Math.sqrt(opposite*opposite + adjacent*adjacent);
    
    float cosine = adjacent/hypotenuse;
    float sine = opposite/hypotenuse;
    
    float endX = 400 + 50 * cosine;
    float endY = 400 + 50 * sine;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this isn't the most ideal solution, but I need to add an
I know this isn't a unique issue but I've not had much luck finding
I know this isn't very relevant to programming, but I need to know how
I know this isn't hard, but I'm not having any luck. I want to
I know this isn't strictly a programming question but y'all must have experienced this.
I know this isn't strictly speaking a programming question but something I always hear
I know this isn't best practice, but can I include all of the dependencies
I know this isn't so complicated but I can't remember how to do. I
I know this isn't right, but for the sake of illustration I'd like to
I know this isn't directly related to programming, but I was wondering if anyone

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.