4 Replies - 1193 Views - Last Post: 04 April 2012 - 11:54 AM Rate Topic: -----

#1 Zel2008  Icon User is offline

  • D.I.C Addict

Reputation: 14
  • View blog
  • Posts: 790
  • Joined: 06-January 09

Determine if line exists between two points

Posted 04 April 2012 - 10:40 AM

Hi everybody,

I'm trying to create a string representation of a panel. The panel has two points on it, A and B, and may or may not have a line drawn between those two points. If the line is not drawn, I'd like to save only the coordinates of A and B in a string. If the line is drawn, I'd like to save the coordinates of A and B, and then repeat them in the string as the endpoints of the line.

Essentially, to do this, all I need to know is if A and B are connected. This isn't trivial in Java 2D, as far as I can see, and I'm not looking for someone to do this for me, but I'd appreciate it if someone could give me a kickstart to get me started. I know how to find points A and B, it's figuring out the connection that I'm stuck on.

If anyone could give me some advice, I'd appreciate it.

Thanks,
Zel2008

Is This A Good Question/Topic? 0
  • +

Replies To: Determine if line exists between two points

#2 SwiftStriker00  Icon User is offline

  • No idea why my code works
  • member icon

Reputation: 433
  • View blog
  • Posts: 1,599
  • Joined: 25-December 08

Re: Determine if line exists between two points

Posted 04 April 2012 - 10:57 AM

Are you trying to just see if a line is drawn between the two points? If so

you would have to find componenets of the line, then pick a point on that line. So:

y=mx+b

we know m = delta Y / delta X
so m = (By - Ay) / ( Bx - Ax )

now we use a point, lets take A, and solve for B

Ay = m ( Ax ) + b
b = Ay / ( m * Ax )

now that we know m and B, we can pick some X where Ax < X < Bx.
Solve for that Y, and finally look and see if that point is painted on the line
Was This Post Helpful? 2
  • +
  • -

#3 Zel2008  Icon User is offline

  • D.I.C Addict

Reputation: 14
  • View blog
  • Posts: 790
  • Joined: 06-January 09

Re: Determine if line exists between two points

Posted 04 April 2012 - 11:08 AM

Thanks SwiftStriker,
That's exactly what I need, thank you. :) I guess I was focusing too much on Java 2D and ignoring my basic math. Thanks again! :)
Zel2008
Was This Post Helpful? 0
  • +
  • -

#4 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1156
  • View blog
  • Posts: 2,538
  • Joined: 05-May 05

Re: Determine if line exists between two points

Posted 04 April 2012 - 11:10 AM

Can you articulate? Or better yet, can you reduce your problem to something more rudimentary? You're mixing information about Java 2D, points, strings, and panels. Quite confusing. Whatever geometric problems you're trying to solve need not be complicated with talks of Swing and all that.

This post has been edited by blackcompe: 04 April 2012 - 11:11 AM

Was This Post Helpful? 1
  • +
  • -

#5 Zel2008  Icon User is offline

  • D.I.C Addict

Reputation: 14
  • View blog
  • Posts: 790
  • Joined: 06-January 09

Re: Determine if line exists between two points

Posted 04 April 2012 - 11:54 AM

Thanks blackcompe,
I'm fine now, I just needed to know if a line was drawn between two points. I'm still trying to figure out how to determine if a particular point is part of a painted line, but I'm sure I'll figure it out.
Thanks,
Zel2008
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1