drawing a line with angle and one co-ordinate

hi,

i want to draw the perpendicular bisector of two points. i obtained the midpoint and used the drawline method to draw the bisector.

g2.drawLine(x,y,(x+Math.cos(90/180.0*Math.PI)*length),

(y-Math.sin(90/180.0*Math.PI)*length));

is there any way to do this without specifying the length of the line? I want the bisector to extend on both sides until they touch the panel border. can anyone tell me how to acheive this?

thanks in advance,

daffodils

[493 byte] By [daffodils_wordsa] at [2007-10-2 8:30:18]
# 1
Well, the simple way would just to have a large number for length, bigger than you think the panel will ever be. That way you can just let the clipping take care of it. Otherwise you would have to get fancy and either find the intersection or something.
Talchasa at 2007-7-16 22:31:10 > top of Java-index,Other Topics,Java Game Development...
# 2
hi,thanks 4 the reply. the problem is, the line is drawn starting from the given point with the specified angle. But I want the line to pass through the point and extend on both sides. How can I acheive this?thanks in advance,Archana
daffodils_wordsa at 2007-7-16 22:31:10 > top of Java-index,Other Topics,Java Game Development...
# 3

How I understand you is there will be two random dots on the plane and you want to draw a line in the middle of them that would be perpendicular ?

If the lines were always going to be perfectly horizontal or vertical relative to the panel you could just set y to 0 if it were going to be a horizontal or x to 0 if it were a vertical line and the draw a line the length of the panel using getWidth() or getHeight(). That would cause the line to draw the length of the panel in either direction each time.

If the perpendicular bisector has a chance of traveling diagnolly across the panel then you could use what you have, if it works that way, and do what talcha suggested and draw the line starting from the midpoint to the edge of the panel using a large length (probably the distance from one corner of your panel to an opposite corner), and then to make the line look as though it's passing through the midpoint and not just shooting off from it, draw another line starting from the midpoint using the same method , just turn the angle 180 degrees and draw the line.

if the line needs to be 1 line starting from the edge of the panel and needs the capability of going diagnolly then you would probably need to get the point at which the first line you draw using the method above leaves the panel. I believe you could retrieve this value by creating a rectangle the size of your panel then getting the slope of the line using the standard slope formula then place points using the slope of the line as your x and y until the rectangle no longer contains the point your placing. The first point that is no longer contained is the startpoint of your line. then using your slope place points to the other end of the bounding rectangle the same way you did up to it from the midpoint. then see when the rectangle no longer contains the points and thats your endpoint. Then draw the line using the startpoint and endpoints and you then should have a perpendicular bisector no longer than it has to be. This would probably take a while to calculate so this is probably a horrible idea for a game. but if this is all the program has to do this should work. However I'm sure there are easier ways of doing this, this is all I can think of right now ...... =(

Twistedchaosa at 2007-7-16 22:31:10 > top of Java-index,Other Topics,Java Game Development...
# 4
Hi,thanks 4 ur reply. i have already implemented the first method u r talking abt. but i was just wondering if there were better methods to acheive it.anyway, thanks a lot.
daffodils_wordsa at 2007-7-16 22:31:10 > top of Java-index,Other Topics,Java Game Development...