Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2012-08-13 00:30:48

ronzul
Member
Registered: 2012-08-13
Posts: 6

angle from point to directed line segment

Apologies if you have already replied to this.. I posted this earlier but somehow it was deleted (as was my newly created account!!). I hope I didn't offend the powers that be with my question yikes

I have a directed line segment and a point, and I need to determine the angle of intersection between:
1.    The line from the point to the start of the directed line segment
2.    The directed line segment

For example if the directed line segment is from (2, 2) to (1, 1), and I have a point at (3, 1), then the angle would be 90 degrees. But from the point (1, 3) the angle would 270 degrees.

And if the segment was from (2, 2) to (3, 3), then from (3, 1) the angle would be 270 degrees, and from (1, 3) it would be 90 degrees

This is probably a one off question, so just the formula would be more than appreciated.. although if you don’t know the answer, any tips would be good as well.

Many thanks

Offline

#2 2012-08-13 01:20:28

Bob
Administrator
Registered: 2010-06-20
Posts: 10,582

Re: angle from point to directed line segment

hi ronzul

Welcome to the forum!

Don't know what happened to your first post / membership.  Maybe one of the administrators can answer that.

If your original post was the same as this one, then no one will have been offended.

If your post had an advert or spam then I can understand why. 

If your points are

then you could use gradients.

Then the angle between the x axis and that line is

Do the same for the line joining the end point to the third point.

Then subtract to get the difference.

The only snag with this is that inverse tan function will return the principle value of the angle which may lead to answers being wrong by some multiple of 90 degrees (I think .... I've got to go and cut a hedge so I'll muse on this while I cut)

LATER EDIT:

Make that 180.

Here's an example I made up:

(x1 = -3, y1 = -2) (x2 = -1, y2 = 1) (x3= -5,y3= 2)

G12 = 1.5, G31 = -2

angle = 119.7.....  Maybe you would prefer 60.13.....

It depends on what you want to do with the results.



There is a method that will avoid this using the scalar product but it is more complicated.

If the above makes sense** to you, I suggest you give it a try for some known answers and see if it works out OK.

If not, post again and I'll explain the scalar product method.

** And if it doesn't make sense post again for a longer explanation.

Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

#3 2012-08-13 17:09:30

ronzul
Member
Registered: 2012-08-13
Posts: 6

Re: angle from point to directed line segment

Thanks Bob for your time and the explanation. I hope you weren't too distracted whilst trimming your hedges and that they look ok.

I will give it a whirl and post my result.

And yes, the original post was the same - no spam, no advertisements, no bad jokes.

Cheers
Ronny

Last edited by ronzul (2012-08-13 17:11:28)

Offline

#4 2012-08-13 18:45:17

Bob
Administrator
Registered: 2010-06-20
Posts: 10,582

Re: angle from point to directed line segment

hi Ronny,

You're welcome.  Hedge looks neat and tidy. 

Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

#5 2012-08-13 19:31:10

ronzul
Member
Registered: 2012-08-13
Posts: 6

Re: angle from point to directed line segment

Thanks Bob for the detailed explanation, but I’m not sure if it gives me what I want, as I don’t think it takes the directed nature of the line segment into account.

Let me know if I’ve gotten this wrong:

But if the line segment starts at (2, 2) and ends at (1, 1) the slope is 1.

If it starts at (2, 2) and ends at (3, 3) the slope is also 1. The slope is the same, and therefore the end angle is the same, but I want a different answer.

Not sure if this is pushing the friendship, but what is the scalar product solution, and would that help with the directed line segment?

Much appreciated!

Cheers
Ronny

Offline

#6 2012-08-13 20:09:09

Bob
Administrator
Registered: 2010-06-20
Posts: 10,582

Re: angle from point to directed line segment

hi Ronny,

Yes, that's what I was trying to say.  And yes, again, the scalar product will take care of it.

You need to write each line segment as a vector.

Direction is now recorded so it'll fix the segment better than the slope will.

eg.

have the same 'slope' but the signs take care of the direction for you.

So let's say you have two vectors a and b and you want the angle between them ...

(i) the scalar product can be calculated like this

where a is the length of vector a, and b is the length of vector b

(ii)  and if, say,

then the scalar product can also be calculated with

So we have two ways to calculate the product and so can make the cosine the subject

The general formula would be

Hope that makes sense.  Post again if it doesn't.

Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

#7 2012-08-15 18:56:13

ronzul
Member
Registered: 2012-08-13
Posts: 6

Re: angle from point to directed line segment

Thanks Bob, that is so kind of you to give such a detailed explanation, but I am having some trouble.
I’m assuming:
That if my line segment is from

to

And my point is at

Then




So if

and
and

Then

is (1 + -1) = 0, which gives an angle of 90.

Good.

But if the line segment is going in the opposite direction, ie it still starts at

but ends at
,
is now (-1 + 1) and still is 0.

And I get an angle of 90, when I was hoping for 270.

Any clues?

Thanks once again for your assistance.

Cheers
Ronny

Offline

#8 2012-08-15 19:25:33

Bob
Administrator
Registered: 2010-06-20
Posts: 10,582

Re: angle from point to directed line segment

hi ronzul

Oh drat!  You're right.  This won't do at all. shame

I think some analysis of the coordinates is needed too.  It will be possible but it would help if you could give me some background to the problem.

Where do the coords come from?  And what do you want to do with the angle, once you've got it.

I could just say that cosine 270 = 0 too so the calculation is correct smile but that doesn't help you much.

So I'll go back to pencil and paper and get a clear idea of when the angle is acute / obtuse / reflex.

Thinking ..............................

LATER EDIT:

See diagram below.

For your example, the angle must be 90 when the sense of the vectors is anticlockwise and 270 when the sense is clockwise.

So we could devise a test for this to discriminate between the cases.

But check out the blue line.  If (x2,y2) = (3,1) what would you want the angles to be in the two cases?  Because the test will only work if there is a consistent rule.

Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

#9 2012-08-16 13:23:25

ronzul
Member
Registered: 2012-08-13
Posts: 6

Re: angle from point to directed line segment

Hi Bob

Many thanks once again for your ideas.

The background is that I'm writing some software that needs this result. So I think your idea of first testing which quadrant the line segment is in, and modifying the result could work. Might be easier than finding an ideal formula that works in every case.

I'll let you know how it goes.

Cheers
Ronny

Offline

#10 2012-08-17 00:29:39

Bob
Administrator
Registered: 2010-06-20
Posts: 10,582

Re: angle from point to directed line segment

hi ronzul,


I agree.  But I think you only need to test for clockwise and anticlockwise rotation as you go from (x2,y2) to (x0,y0) to (x1,y1).

And I think I've found a way of testing for this which is easy to compute.

Let's say that

Then

and it's clockwise if this calculation is < 0

I won't complicate matters with the underlying vector theory for this as it involves 3-D vector products but it seems to work out ok.

Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

#11 2012-08-17 17:42:12

ronzul
Member
Registered: 2012-08-13
Posts: 6

Re: angle from point to directed line segment

Hey Bob, you're the man.. seriously!

I haven't had a chance to test this out yet, but you are still the man.

Thanks
Ronny

Offline

#12 2012-08-17 18:58:18

Bob
Administrator
Registered: 2010-06-20
Posts: 10,582

Re: angle from point to directed line segment

You're welcome.

Let me know how it's going.

Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

Board footer

Powered by FluxBB