Author |
Message |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
Hi,
Just about to put pen to paper to work this out but thought I'd post here so I can check my answer when I finish.
OK, here's the problem...
I have 2 points (coords in 2D space). point A = (xa, ya), point B = (xb, yb) (read "xa" as "x subscript a" not "x * a" and so on...)
OK, simple enough so far.
Now I have a circle drawn around each point of radius 5.
I also have a line AB connecting the two points.
The problem is that I want the line to start and end at the edge of each circle but also at the points on each circle nearest each other. (If that makes sense).
Can anyone come up with a sensible way of calculating the adjusted points from A and from B? All I need is a dx and a dy value to add to one and subtract from the other but just trying to figure them out.
Thanks for any help.
|
Mon Nov 28, 2011 8:23 pm |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
Hmm... I think it was easier than I was thinking.
If the circles are radius r then...
the length of AB l = sqrt((xb - xa)^2 + (yb - ya)^2) (Pythagorus)
change in x from A to B = xb - xa change in y from A to B = yb - ya
so...
the line will intersect the circle at x value = xa + (xb - xa) * r/l and y value = ya + (yb - ya) * r /l
(assuming that xb >= xa and yb >= ya)
(then just have to subtract instead of add for the other end).
|
Mon Nov 28, 2011 8:31 pm |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
Almost! It works in some cases and goes absolutely mental in others 
|
Mon Nov 28, 2011 8:45 pm |
|
 |
belchingmatt
I haven't seen my friends in so long
Joined: Fri May 15, 2009 3:16 am Posts: 6146 Location: Middle Earth
|
Whilst you're on the subject of mental, have you considered that posting to yourself could be a sign that something is amiss? 
_________________ Dive like a fish, drink like a fish!
><(((º>`•.¸¸.•´¯`•.¸><(((º> •.¸¸.•´¯`•.¸><(((º>`•.¸¸.•´¯`•.¸><(((º>
If one is diving so close to the limits that +/- 1% will make a difference then the error has already been made.
|
Mon Nov 28, 2011 8:48 pm |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
 Anyway, I was right but I'd put a - in the Pythagorus bit instead of a +. For some reason it doesn't like calculating the square root of negative numbers  Stupid computers... they've got no imagination! 
|
Mon Nov 28, 2011 9:00 pm |
|
 |
l3v1ck
What's a life?
Joined: Fri Apr 24, 2009 10:21 am Posts: 12700 Location: The Right Side of the Pennines (metaphorically & geographically)
|
|
Mon Nov 28, 2011 9:02 pm |
|
 |
leeds_manc
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 8:19 pm Posts: 5071 Location: Manchester
|
I just looked for the "like" button under that post.
|
Mon Nov 28, 2011 9:20 pm |
|
 |
finlay666
Spends far too much time on here
Joined: Thu Apr 23, 2009 9:40 pm Posts: 4876 Location: Newcastle
|
As you are just calculating distance use the absolute method Abs(-n) = n 
_________________TwitterCharlie Brooker: Macs are glorified Fisher-Price activity centres for adults; computers for scaredy cats too nervous to learn how proper computers work; computers for people who earnestly believe in feng shui.
|
Tue Nov 29, 2011 9:20 am |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
 no one got my joke 
|
Wed Nov 30, 2011 11:51 am |
|
 |
Linux_User
I haven't seen my friends in so long
Joined: Tue May 05, 2009 3:29 pm Posts: 7173
|
|
Wed Nov 30, 2011 11:53 am |
|
 |
finlay666
Spends far too much time on here
Joined: Thu Apr 23, 2009 9:40 pm Posts: 4876 Location: Newcastle
|
I got it.... it wasn't funny though  Did you hear about the constipated mathemitician? He worked it out with a pencil
_________________TwitterCharlie Brooker: Macs are glorified Fisher-Price activity centres for adults; computers for scaredy cats too nervous to learn how proper computers work; computers for people who earnestly believe in feng shui.
|
Wed Nov 30, 2011 1:33 pm |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
 Anyway, I've got another question and this time it's a bit harder. Tried (for about 5 mins) and gave up. I've got a line now from point A to B but there are some lines that need to be drawn as double lines (i.e. like ======= but without the dashed pattern) if that makes sense. So, I need to offset the start and end points and draw 2 lines. i.e. if point A is (0, 0) and point B is (100, 0) then I draw one of the lines between the points... (0, 1) and (100, 1) and the other line between (0, -1) and (100, -1) to get 2 parallel lines. However, I need to do it no matter what the coords are. I really just need a single offset calculation and then need to add/subtract it from the start and end points. Hope that makes sense and someone can help.
|
Wed Nov 30, 2011 1:52 pm |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
OK, done it again  It's actually really simple to calculate. Line from (a,b) to (x,y). Length l = sqrt((x-a)^2 + (y-b)^2) Change = c dx = (x - a) * c / l dy = (y - b) * c / l The shorter line (i.e. the one from the first question) is... (a + dx, b + dy) to (x - dx, y - dy) The parallel lines... First one... (a - dy, b + dx) to (x - dy, y + dx) Second one... (a + dy, b - dx) to (x + dy, y - dx) That should work for all possible points.
|
Wed Nov 30, 2011 2:19 pm |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
Got home and it works perfectly  Also, because I realised I only have to work out the unit value (i.e. change of distance 1) of dx and dy once it has improved the performance of it  Thanks for the help 
|
Thu Dec 01, 2011 11:13 am |
|
 |
leeds_manc
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 8:19 pm Posts: 5071 Location: Manchester
|
No problem mate, any time. 
|
Thu Dec 01, 2011 12:39 pm |
|
|