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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:26:37+00:00 2026-06-08T19:26:37+00:00

I currently have a bad method for doing this, it just translates the start

  • 0

I currently have a bad method for doing this, it just translates the start point by 1/-1 depending on if the x/y coordinate is over or under the current coordinates and adds it to an ArrayList until the start point .equals(end), this is a bad solution because it creates a really bad path that looks like the black path below.

https://dl.dropbox.com/u/64681860/paths.png

I’m trying to generate a direct path of points between two points (The same kind of line as Graphics.drawLine makes).

I’m guessing I need to use the Math class to get the angle, but I’m not very familiar with the Math API.

  • 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-08T19:26:38+00:00Added an answer on June 8, 2026 at 7:26 pm

    One somewhat naive way, is to work out the ratio of the slope, rather than the angle.

    Something like:

    float ratio = (y2 - y1) / (x2 - x1);
    

    Then:

    width = x2 - x1;
    for(int i = 0; i < width; i++) {
        float x = x1 + i;
        float y = y1 + (ratio * i);
        points.add(new Point(x,y));
    }
    

    If float isn’t what you need, you’ll need to do some conversion.

    You’ll also need to handle the special case of x1 == x2, or you’ll get divide-by-zero errors.

    Using this method, the steeper the line, the fewer points you will generate. If you want the points evenly spaced no matter what the angle, you’ll need to break out sin/cos/tan.

    Write unit tests for lines in at least the main 8 compass directions, to iron out any glitches.

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

Sidebar

Related Questions

Is this a problem / bad practice: I have the same method names in
currently I have this client code in my PHP MVC web app: try {
Currently I have some code that looks like this void calc_run(Calculation *c, Input *i);
Apple is doing this in a setter method for an instance variable mainSprocket: –
I currently have a method that prompts the user to rate my app on
I currently have a WCF service that exposes a SOAP enpoint. In this webservice
Currently I have a function, f(), which returns the current system clock in microseconds.
Currently have a drop down menu that is activated on a hover (from display:none
Currently have password protection on my main and sub directories, however I'd like to
I currently have a XSLT 2.0 Stylesheet that I am trying to remove empty

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.