Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Find a point on a line given distance.

  • 11-11-2009 12:47pm
    #1
    Registered Users, Registered Users 2 Posts: 2,236 ✭✭✭


    Hi,

    Basically, I have a line - (x1,y1) (x2,y2) and I would like to find the point of the line when I travel z along this line from say, (x1,y1).

    Is this possible?

    My aim is to take a line and draw an equilateral triangle on it, where the base is 1/3 of the length of the line and parallel to and on the line?

    Any pointers? Thanks.


Comments

  • Registered Users, Registered Users 2 Posts: 13,091 ✭✭✭✭bnt


    You could call this a Vector problem or a Trigonometry problem. There's more than one way to do it, and while we're not allowed to offer full solutions here, you may want to read up on conversions between Rectangular and Polar co-ordinates. Short version: you can resolve that distance z in to x and y displacements, then add them to x1 and y1 respectively. To do that you need the angle θ of the vector:

    [latex]\displaystyle tan(\theta)=\frac{y_2-y_1}{x_2-x_1}[/latex]

    You are the type of what the age is searching for, and what it is afraid it has found. I am so glad that you have never done anything, never carved a statue, or painted a picture, or produced anything outside of yourself! Life has been your art. You have set yourself to music. Your days are your sonnets.

    ―Oscar Wilde predicting Social Media, in The Picture of Dorian Gray



  • Registered Users, Registered Users 2 Posts: 1,595 ✭✭✭MathsManiac


    There's a formula for dividing a line segment in a given ratio. Is that what you need?

    The point dividing the line segment from (x1,y1) to (x2,y2) in the ratio a:b is:
    ( (bx1 + ax2)/(b+a)) , (by1 + ay2)/(b+a) ).

    Going a third of the way along a segment is the same as dividing it in the ratio 1:2, so the above formula will do that for you.


  • Registered Users, Registered Users 2 Posts: 2,236 ✭✭✭techguy


    Cool, thanks for that. I'll give it a go.

    I'll give you a bit of a background to my problem. I'm trying to create a Koch Snowflake. This is a programming assignment so the maths isn't really whats being tested here.

    Now that I have the line trisected I need to construct an equilateral triangle with the middle section of this existing line as the base. I am having trouble finding the coordinated of the thrid point in the triangle.

    I know that both the new vertices are at 60 Degrees to the existing line. What I need to do now is calculate the equations for both the new vertices using the angle and the point. I will then use these to equiations simulataneously to ge the point of intersection, i.e. the third point.

    My problem: finding a formula to calculate the equation of a line given angle and a point.

    Can anybody help me on this?


  • Registered Users, Registered Users 2 Posts: 13,091 ✭✭✭✭bnt


    I think what I said before is still useful, actually - It's still Trigonometry. You have a line already, and that line has a Length (r) (see Pythagoras) and an Angle (θ) (the formula I gave).

    Now you want to draw another line, of the same Length (r), at 60° to the first line - so you add 60° to the angle θ to get θ2 = θ + 60°. Then convert back to Rectangular co-ordinates to get (dx, dy), the relative offsets of the new point. dx = r*Cos(θ2), dy = r * Sin(θ2)

    Then add (dx, dy) to (x1, y1) respectively to get the co-ordinates of the new point. It's hard to explain this stuff without pictures ... have you looked at LOGO? :cool:

    PS: in computer languages, you might find that the trig. functions use angles in Radians, where 180° = π , so 60° = π/3. You may also have a "draw relative" command, which lets you specify co-ordinates relative to the last thing you drew, which might make life easier. IIRC Visual Basic does.

    You are the type of what the age is searching for, and what it is afraid it has found. I am so glad that you have never done anything, never carved a statue, or painted a picture, or produced anything outside of yourself! Life has been your art. You have set yourself to music. Your days are your sonnets.

    ―Oscar Wilde predicting Social Media, in The Picture of Dorian Gray



  • Registered Users, Registered Users 2 Posts: 2,236 ✭✭✭techguy


    Ok so i'm still pretty lost. I though that I was able to find D and E already but am comlpetely muddled now and have got myself lost again.

    triangle.GIF

    @bnt: Please excuse me if this seems dumb but at this point I'm so frustrated I can't even think straight. Can you please demonstrate how to find D,E and F from the provided details?

    Funnily enough this is actually a programming assignment in Haskell, which works in Radians. Whats frustrating me most is that I can't even get as far as programming because I just can't do the maths.

    Also, in Haskell the coordinates system is different meaning (0,0) is at the top left of the screen. Does this complicate things?? How will it affect my results here?

    This assignment is due tonight at 12 so any help would be greatly appreciated..


    Thanks.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 5,083 ✭✭✭RoundTower


    you can think of D and E as weighted averages of A and B. So D is 2/3 B and 1/3 A, and vice versa for E.

    Let's say A is (xa, ya) and B is (xb, yb), D is (xd, yd), etc.

    Then xe is (2xa + xb)/3 and ye is (2ya + yb)/3
    xd is (xa + 2xb)/3 and yd is (ya + 2yb)/3

    trying this method with the numbers you gave:

    xd is (2(4) + 6) / 3 = 14/3
    yd is (2(3) + 6) / 3 = 4

    so D is (14/3, 4) etc. You can see easily that the 4 here is 1/3 of the way along from 3 to 6 - that is the important thing to keep in mind.

    To find F is a little more complicated. Don't forget to make sure that it finds F outside the large triangle, instead of inside.

    The method should still work exactly the same with the Haskell co-ordinate system, however it will be confusing for you if you are drawing diagrams on paper with one co-ordinate system and trying to fix bugs in the other.


  • Registered Users, Registered Users 2 Posts: 2,236 ✭✭✭techguy


    Thanks for that, I'm getting there now..but if you don't mind me asking how would I go about finding F ??


  • Registered Users, Registered Users 2 Posts: 13,091 ✭✭✭✭bnt


    OK, at the risk of incurring the wrath of the Moderators, I'll do some of it. As the charter says, we're not here to do your homework for you. :o

    You have line BA, so convert it to Polar (r, θ) form:

    Length: [latex]r = \sqrt{\Delta x^2 \text{+} \Delta y^2} = \sqrt{(6-4)^2 \text{+} (6-3)^2 } = \sqrt{4\text{+}9} = \sqrt{13}[/latex]

    Angle θ: [latex]tan(\theta) = \frac{\Delta y}{\Delta x} = \frac{3}{2} => \theta = tan^{-1}(3/2) = 0.983\,radians = 56.3 deg[/latex]
    So, BA in Polar (r, θ) form is [latex](\sqrt{13}, 0.983)[/latex].

    (Is that supposed to be an equilateral triangle? It's not, since the angle is not 60°.)

    So, to find point D relative to B, what do you have? The vector angle is the same as BA (since it's along the line), while the length is 1/3 of BA's length. So, the vector DB is [latex](\frac{\sqrt{13}}{3}, 0.983)[/latex]. Now you find the co-ordinates of D relative to B:
    [latex]\Delta x = r\, Cos(\theta) = \frac{\sqrt{13}}{3} Cos(0.983) = 2/3[/latex]
    [latex]\Delta y = r\, Sin(\theta) = \frac{\sqrt{13}}{3} Sin(0.983) = 1[/latex]
    Add those to the co-ordinates of point B, and you get [latex]D = (4 \frac{2}{3}, 4)[/latex]

    The point of using Polar co-ordinates to work this stuff out is that it describes lines in terms of Length and Angle, rather than X and Y. Your problem is one of Lengths and Angles - you're looking for 1/3 the Length, and rotating things by 60 degrees. To find point F relative to D, for example, you know the Length from D will be the same as DB [latex]\frac{\sqrt{13}}{3}[/latex], and the angle will be the angle of DB plus 60 degrees - so you add [latex]\frac{\pi}{3}[/latex] radians to the angle of DB (0.983 + 1.047 = 2.03). So, FD in Polar (r, θ) form is [latex](\frac{\sqrt{13}}{3}, 2.03)[/latex]. You just rotate 60 degrees by adding or subtracting [latex]\frac{\pi}{3}[/latex] at a time. Now you know the vector FD, you can use the trigonometry to get the co-ordinates of F relative to D.

    You are the type of what the age is searching for, and what it is afraid it has found. I am so glad that you have never done anything, never carved a statue, or painted a picture, or produced anything outside of yourself! Life has been your art. You have set yourself to music. Your days are your sonnets.

    ―Oscar Wilde predicting Social Media, in The Picture of Dorian Gray



  • Registered Users, Registered Users 2 Posts: 5,083 ✭✭✭RoundTower


    that is probably a better way to approach the problem, and certainly will be prettier, but if he has an assignment due tonight I don't think it's a good time to start learning about polar co-ordinates.


  • Registered Users, Registered Users 2 Posts: 5,083 ✭✭✭RoundTower


    to find F, I think there will be some tricks that make it easier if ABC is guaranteed to be an equilateral triangle. Is it? The one in your diagram isn't.

    For example, if ABC is equilateral, EF is parallel to BC, so if BC is parallel to the x-axis then F has the same y-coordinate as E, and given that it should also be pretty clear what the x-coordinate is.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 13,091 ✭✭✭✭bnt


    My thinking is that if he's going to try and program it in algorithmically, and he's going to get marked on it, then this is the way to go.

    I don't know exactly what that lecturer is expecting, but as I understand it, the Koch Snowflake is a fractal, an exercise in recursive programming: a subroutine that calls itself again at a different scale. If you look at the Koch Snowflake article on Wikipedia, it has programming examples in LOGO, which uses Polar notation throughout (but degrees rather than radians). You can program a complete Koch Snowflake in just a few lines of LOGO.

    The whole problem is radically simplified if you are able to think of the lines as vectors in Polar notation. All you're doing in drawing them in different lengths and rotating them where necessary.

    You are the type of what the age is searching for, and what it is afraid it has found. I am so glad that you have never done anything, never carved a statue, or painted a picture, or produced anything outside of yourself! Life has been your art. You have set yourself to music. Your days are your sonnets.

    ―Oscar Wilde predicting Social Media, in The Picture of Dorian Gray



  • Registered Users, Registered Users 2 Posts: 5,083 ✭✭✭RoundTower


    Let's say ABC is an equilateral triangle with one side parallel to the x-axis (it probably should be). Then no matter which line AB is, either

    - EF is parallel to the x-axis
    - DF is parallel to the x-axis
    - MF is parallel to the y-axis, where MF is the midpoint of AB.

    You also know the lengths |EF|, |DF| and |MF| or can calculate them easily, so it will be trivial to find F based on this.


  • Registered Users, Registered Users 2 Posts: 2,236 ✭✭✭techguy


    This is great input guys, thanks a million.

    I'm sorry about the rough diagram but all triangles will be equilateral. Does that simplify things??


  • Registered Users, Registered Users 2 Posts: 5,083 ✭✭✭RoundTower


    bnt wrote: »
    My thinking is that if he's going to try and program it in algorithmically, and he's going to get marked on it, then this is the way to go.

    yes if he is being marked for writing a nice program. If he gets full marks for something kludgy that works, I think he should probably go with the kludgy one that he is at least familiar with how it will work.

    Also, the comparison to LOGO is a bit tough: LOGO might as well have been purpose-written to solve this problem, it is so perfect for the task. Maybe he should write a LOGO interpreter in Haskell and then feed that program to it.


  • Registered Users, Registered Users 2 Posts: 5,083 ✭✭✭RoundTower


    techguy wrote: »
    This is great input guys, thanks a million.

    I'm sorry about the rough diagram but all triangles will be equilateral. Does that simplify things??

    very much so, see my post above

    you should see if you understand what bnt is suggesting though, and use his method if you think you grasp it, because it really is nicer. We are suggesting two totally different things though, so you will have to ignore one of us.


  • Closed Accounts Posts: 4 BryanThompson


    bnt wrote: »
    OK, at the risk of incurring the wrath of the Moderators, I'll do some of it. As the charter says, we're not here to do your homework for you. :o

    You have line BA, so convert it to Polar (r, θ) form:

    Length: [latex]r = \sqrt{\Delta x^2 \text{+} \Delta y^2} = \sqrt{(6-4)^2 \text{+} (6-3)^2 } = \sqrt{4\text{+}9} = \sqrt{13}[/latex]

    Angle θ: [latex]tan(\theta) = \frac{\Delta y}{\Delta x} = \frac{3}{2} => \theta = tan^{-1}(3/2) = 0.983\,radians = 56.3 deg[/latex]
    So, BA in Polar (r, θ) form is [latex](\sqrt{13}, 0.983)[/latex].

    (Is that supposed to be an equilateral triangle? It's not, since the angle is not 60°.)


    So, to find point D relative to B, what do you have? The vector angle is the same as BA (since it's along the line), while the length is 1/3 of BA's length. So, the vector DB is [latex](\frac{\sqrt{13}}{3}, 0.983)[/latex]. Now you find the co-ordinates of D relative to B:
    [latex]\Delta x = r\, Cos(\theta) = \frac{\sqrt{13}}{3} Cos(0.983) = 2/3[/latex]
    [latex]\Delta y = r\, Sin(\theta) = \frac{\sqrt{13}}{3} Sin(0.983) = 1[/latex]
    Add those to the co-ordinates of point B, and you get [latex]D = (4 \frac{2}{3}, 4)[/latex]

    The moderator's furious Joe.

    Polar form coordinate geometry is the coordinate geometry of the Divil.
    A lot of this here is counter-intuitive...you can't see the wood for the trees as it were. What the chap is tryin to do can be solved with some simple honours LC maths, notions of polar form and vectors are not required and only make a simple problem unnecessarily complicated.


Advertisement