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
Determine if line exists between two points
Page 1 of 14 Replies  1193 Views  Last Post: 04 April 2012  11:54 AM
Replies To: Determine if line exists between two points
#2
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
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
#3
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
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
#4
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
#5
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
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
Page 1 of 1
