From: Roger Stafford on
"Beho nashed" <beho86(a)yahoo.com> wrote in message <hvejah$ab6$1(a)fred.mathworks.com>...
> Hello Roger,
> I keep selecting points for an angle bigger than 90 degree, but the program is giving me an angle less than 90 deg!!!
> .......

There must be something amiss, either with the way you are selecting your points or the way their coordinates are being collected. I have done a copy and paste on the three different forms of the formulas we have discussed and after supplying a missing left bracket in the last one, (sorry about that) they all give the same answer which can be anywhere between zero and pi radians, or in degrees, anywhere between 0 and 180 degrees. I illustrate with one example here which yields the correct answer of 135 degrees (after multiplying by 180/pi to transform from radians to degrees) for all three formulas.

P1 = [2,1];
P2 = [6,3];
P3 = [-7,4];
x = [P1(1);P2(1);P3(1)];
y = [P1(2);P2(2);P3(2)];
x1 = x(1); y1 = y(1);
x2 = x(2); y2 = y(2);
x3 = x(3); y3 = y(3);
ang1 = atan2(abs(det([x1,x2,x3;y1,y2,y3;1,1,1])), ...
(x2-x1)*(x3-x1)+(y2-y1)*(y3-y1));
ang2 = atan2(abs(det([x(1),x(2),x(3);y(1),y(2),y(3);1,1,1])), ...
(x(2)-x(1))*(x(3)-x(1))+(y(2)-y(1))*(y(3)-y(1)));
ang3 = atan2(abs(det([P2-P1;P3-P1])),dot(P2-P1,P3-P1));

180/pi*[ang1;ang2;ang3] =

135
135
135

Roger Stafford
From: Beho nashed on
"Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <hvet7b$b6c$1(a)fred.mathworks.com>...
> "Beho nashed" <beho86(a)yahoo.com> wrote in message <hvejah$ab6$1(a)fred.mathworks.com>...
> > Hello Roger,
> > I keep selecting points for an angle bigger than 90 degree, but the program is giving me an angle less than 90 deg!!!


Hello Roger,
I actually noticed the bracket and fixed it. I just noticed something in the image displayed. the Y-axis starts from the top!!!

I tried to use set(gca,'ydir','normal') , but it flips the picture and the axis, not just the axis. I am not sure how to flip the axis only, I believe that's the problem.

Thanks
From: us on
"Beho nashed" <beho86(a)yahoo.com> wrote in message <hvg0i3$khr$1(a)fred.mathworks.com>...
> "Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <hvet7b$b6c$1(a)fred.mathworks.com>...
> > "Beho nashed" <beho86(a)yahoo.com> wrote in message <hvejah$ab6$1(a)fred.mathworks.com>...
> > > Hello Roger,
> > > I keep selecting points for an angle bigger than 90 degree, but the program is giving me an angle less than 90 deg!!!
>
>
> Hello Roger,
> I actually noticed the bracket and fixed it. I just noticed something in the image displayed. the Y-axis starts from the top!!!
>
> I tried to use set(gca,'ydir','normal') , but it flips the picture and the axis, not just the axis. I am not sure how to flip the axis only, I believe that's the problem.
>
> Thanks

one of the solutions

axis image;

us
From: Beho on
can I just use this (2 points)

I = imread('angle.jpg');
figure, imshow(I);
axis image;
[x, y] = ginput;
line(x,y,'color',[0 1 0]);

ang1= 180 - subspace(x,y)*180/pi
From: Roger Stafford on
Beho <newparadize2002(a)gmail.com> wrote in message <e615968b-18d6-489f-bbfc-343a546f8869(a)g19g2000yqc.googlegroups.com>...
> can I just use this (2 points)
>
> I = imread('angle.jpg');
> figure, imshow(I);
> axis image;
> [x, y] = ginput;
> line(x,y,'color',[0 1 0]);
>
> ang1= 180 - subspace(x,y)*180/pi

No, I don't think that would work for what you are doing. The angle given by subspace is never greater than 90 degrees (pi/2,) so if you subtract it from 180, it will never be less than 90. I understood that you wanted the angle between two (directed) vectors which can range anywhere between 0 and 180.

If you only want the smaller of the two angles between two lines without regard to direction along the lines and if both lines pass through the origin, then subspace, (without the subtraction from 180,) would indeed give you that answer.

Note: As I pointed out in another thread a week ago, there is an erroneous statement made in MathWorks' description of subspace. They state that, "If A and B are column vectors of unit length, this is the same as acos(A'*B)." It would actually be acos(abs(A'*B)), and that is why the angle from subspace can never be greater than 90 degrees (pi/2.)

Roger Stafford