x404.co.uk http://x404.co.uk/forum/ |
|
A little bit of maths help please? http://x404.co.uk/forum/viewtopic.php?f=3&t=15256 |
Page 1 of 1 |
Author: | Fogmeister [ Mon Nov 28, 2011 8:23 pm ] |
Post subject: | A little bit of maths help please? |
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. |
Author: | Fogmeister [ Mon Nov 28, 2011 8:31 pm ] |
Post subject: | Re: A little bit of maths help please? |
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). |
Author: | Fogmeister [ Mon Nov 28, 2011 8:45 pm ] |
Post subject: | Re: A little bit of maths help please? |
Almost! It works in some cases and goes absolutely mental in others ![]() |
Author: | belchingmatt [ Mon Nov 28, 2011 8:48 pm ] |
Post subject: | Re: A little bit of maths help please? |
Whilst you're on the subject of mental, have you considered that posting to yourself could be a sign that something is amiss? ![]() |
Author: | Fogmeister [ Mon Nov 28, 2011 9:00 pm ] | |||||||||
Post subject: | Re: A little bit of maths help please? | |||||||||
![]() 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! ![]() |
Author: | l3v1ck [ Mon Nov 28, 2011 9:02 pm ] | |||||||||
Post subject: | Re: A little bit of maths help please? | |||||||||
![]() ![]() ![]() |
Author: | leeds_manc [ Mon Nov 28, 2011 9:20 pm ] | ||||||||||||||||||
Post subject: | Re: A little bit of maths help please? | ||||||||||||||||||
I just looked for the "like" button under that post. |
Author: | finlay666 [ Tue Nov 29, 2011 9:20 am ] | |||||||||
Post subject: | Re: A little bit of maths help please? | |||||||||
As you are just calculating distance use the absolute method Abs(-n) = n ![]() |
Author: | Fogmeister [ Wed Nov 30, 2011 11:51 am ] | |||||||||
Post subject: | Re: A little bit of maths help please? | |||||||||
![]() ![]() |
Author: | Linux_User [ Wed Nov 30, 2011 11:53 am ] | |||||||||
Post subject: | Re: A little bit of maths help please? | |||||||||
![]() |
Author: | finlay666 [ Wed Nov 30, 2011 1:33 pm ] | |||||||||
Post subject: | Re: A little bit of maths help please? | |||||||||
I got it.... it wasn't funny though ![]() Did you hear about the constipated mathemitician? He worked it out with a pencil |
Author: | Fogmeister [ Wed Nov 30, 2011 1:52 pm ] | ||||||||||||||||||
Post subject: | Re: A little bit of maths help please? | ||||||||||||||||||
![]() 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. |
Author: | Fogmeister [ Wed Nov 30, 2011 2:19 pm ] |
Post subject: | Re: A little bit of maths help please? |
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. |
Author: | Fogmeister [ Thu Dec 01, 2011 11:13 am ] |
Post subject: | Re: A little bit of maths help please? |
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 ![]() |
Author: | leeds_manc [ Thu Dec 01, 2011 12:39 pm ] | |||||||||
Post subject: | Re: A little bit of maths help please? | |||||||||
No problem mate, any time. ![]() |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |