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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:34:37+00:00 2026-06-10T20:34:37+00:00

I’m looking for a way to draw an infinite line (a line with no

  • 0

I’m looking for a way to draw an infinite line (a line with no end, also known as a ray) through 2 points. I can draw a line between 2 points with Line2D, no problem here.

Next the infinite part needed a look. With my simple mind I thought, lets multiply the x and y coordinates from the second point with 100 and redraw the line. This works, but only in simple cases.

For example here is a case in which it produces lines with different angles:

    g.setColor(Color.red);
    g2.setStroke(new BasicStroke(4.0f));
    g2.draw(new Line2D.Double(0, 61.632653061218946, 944, 217.25510204080692));
    g.setColor(Color.blue);
    g2.setStroke(new BasicStroke(1.0f));
    g2.draw(new Line2D.Double(0, 61.632653061218946, 944*10, 217.25510204080692*10));

This will first draw a fat red line, next it will draw a blue thin line.

The blue line has a different angle compared the the red line. Here’s a screenshot to illustrate this effect:

enter image description here

Does somebody know a way to fix this, or maybe a better way to draw a infinite line through 2 points?

  • 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-10T20:34:39+00:00Added an answer on June 10, 2026 at 8:34 pm

    Let’s do the math for a second.

    • The first line is (0, 61.632653061218946)-(944, 217.25510204080692). Slope is rise/run, therefore m = 0.16485428917329234533898305084746.
    • The second line is (0, 61.632653061218946)-(9440, 2172.5510204080692); m = 0.22361423382911549300847457627119.

    The slopes are different, which is just another way of saying the angles are different.

    What you need to do is extend the line. You cannot just multiply both coordinates of one of the points by 10. First determine either an x or a y beyond the bounds of your canvas, then solve for the other value.

    How do you do this?

    1. First, get the equation for the line. A line is defined by y=m*x+b, where m is the slope, and b is the y-intercept.

      1. We already know how to calculate the slope (rise/run = y2 - y1 / x2 - x1). We get 0.16485428917329234533898305084746
      2. Plug in the slope and solve for b (y - m*x), you get 61.632653061218946. In your case you already have this value as the y-intercept is the y-coordinate when x=0.
      3. You then get the equation y = 0.16485428917329234533898305084746 * x + 61.632653061218946
    2. Now, pick a sufficiently large x, say 10000. Plug this value in and solve for y. You get 1710.1755447941423993898305084746.

    3. Finally, draw your line to this new point, (0, 61.632653061218946)-(10000,1710.1755447941423993898305084746)

    Great, now let’s generalize this.

    • We have two points (x1, y1) and (x2, y2). We want to solve for (10000, y3).
    • Therefore, y3 = m*x3 + b, or y3 = m * 10000 + b.
    • We also know that b = y - m * x, so plugging this in and arbitrarily choosing point 1, y3 = m * 10000 + y1 - m * x1.
    • Ok, let’s factor out the m: y3 = m * (10000 + x1) - y1.
    • We know m = (y2 - y1) / (x2 - x1), so plugging this in: y3 = ((y2 - y1) / (x2 - x1)) * (10000 + x1) - y1.

    If your line doesn’t start at x = 0, you will need to repeat this process for x = 0, meaning you should plot a line (0, ((y2 - y1) / (x2 - x1)) * x1 - y1)-(10000,((y2 - y1) / (x2 - x1)) * (10000 + x1) - y1).

    Note: If x2 - x1 is 0, you have an infinite slope. This is a vertical line, and you’ll have to handle this case separately.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.