GMMorris Posted April 1, 2004 Posted April 1, 2004 Hi, I am trying to, programaticaly, calculate two points in my form, and although I am very easily capable of calculating these points on paper, I can't find a way to transfer the calculations into code, perhaps you can help. :cool: To the details - I have two imaginary cicrles, located on my form (the specifics of why, are not at my disposale to reveal). I know the center locations of the two circles, and I know the radius. What I need is the (X,Y) locations of the two nearest points oin the two circles. What I mean is - two points, one on each circle, between which the shortest line can be drawn. Conclusions my calculations brought me to: 1)The two points will sit on the two points where the line running between the two circle's centers hits the actual circles. 2)The length of the shortest line = the distance between the two centers minus (-) twice the radius. Look at the picture for extra clarification. Please help me - this is very important Quote Latly it would seem as though I'm don't abnegate from anything... except women. :( :)
Leaders Iceplug Posted April 1, 2004 Leaders Posted April 1, 2004 OK. Radius1 is upper left radius, Radius2 is bottom right radius First of all, you can determine the length of the line like this: Length = Math.Sqrt( (J - M)^2 + (K - N)^2 ) Next, you can find the slope of the line like this: (It is important that the second part is subtracted from the first or vice versa consistently.) dY = (K - N) / Length dX = (J - M) / Length m = dY/dX Then, you can find the first point like this: A = J + dX * Radius1 B = K + dY * Radius1 Finally, the second point: C = M - dX * Radius2 D = N - dY * Radius2 Hope that helps. :) You'll probably have to declare most of those variables as singles. (esp. dY, dX, and m, if you need it) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
GMMorris Posted April 1, 2004 Author Posted April 1, 2004 how do you figure that? Then, you can find the first point like this: A = J + dX * Radius1 B = K + dY * Radius1 Finally, the second point: C = M - dX * Radius2 D = N - dY * Radius2 oh, and if this is correct - you are my king :) Quote Latly it would seem as though I'm don't abnegate from anything... except women. :( :)
Leaders Iceplug Posted April 1, 2004 Leaders Posted April 1, 2004 dX and dY form a unit vector for the line... if a line is flat on the x-axis, dX = 1, dY = 0 if a line is standing on y-axis, dX = 0, dY = 1 if it is leaning at 45 degrees, dX = 0.707 (1 / Sqrt(2)), dY = 0.707 So, whatever you multiply to both dX and dY will give you a point along this line at whatever distance you have multiplied by. Let me know if you want more detail. :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
GMMorris Posted April 2, 2004 Author Posted April 2, 2004 Well, its 2 AM here, and my brain is begining to make clack-clack sounds, so I'll just save my self the headache and assume your right :) thanks. Quote Latly it would seem as though I'm don't abnegate from anything... except women. :( :)
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.