dzek (varez) Posted September 21, 2010 Share Posted September 21, 2010 I'm bad in math and trigonometry, so I'm asking you to help. I have three 2D points (A, B and C). How to count the angle ABC theyre creating? Link to comment
Faw[Ful] Posted September 21, 2010 Share Posted September 21, 2010 use cos rule, but I need to know what the number u have (number in triangle u know , could be angle or edge) and what the number u want to find ? thats to make it for you, by yourself there the cos rule : if you cant with that I have another thing, but with the produit scalaire in french Link to comment
50p Posted September 21, 2010 Share Posted September 21, 2010 I'm bad in math and trigonometry, so I'm asking you to help.I have three 2D points (A, B and C). How to count the angle ABC theyre creating? Well, as far as I know, they all create a angle of 180 degrees.. Specify your question. Link to comment
dzek (varez) Posted September 22, 2010 Author Share Posted September 22, 2010 Of course they are points on the map, having their x, y, z coordinates. It's like path from A to C through B, and i want to know the angle of turn in point B. Im interested in x, y only, ignore third depth Link to comment
Faw[Ful] Posted September 22, 2010 Share Posted September 22, 2010 its a triangle ? Do they have the same z coordinates ? Link to comment
dzek (varez) Posted September 22, 2010 Author Share Posted September 22, 2010 Do they have the same z coordinates ? ignore third depth i only need all these on flat surfaces its a triangle ? Something like triangle. Look: I want to get the angle near "B". Left one should be like 150 degrees, and right one like 220 degrees. I have two functions, both of them are returning floats between 0-180, i need it in 0-360 scale. This is what i have so far. I'm thinking about comparing A, B and C points positions to decide if this is angle > 180 or not (it's like path - turning to left or right) function getAngleBetweenPoints2D(ax,ay,bx,by,cx,cy) local AB = { ax-bx, ay-by } local BC = { cx-bx, cy-by } local AB_ = getDistanceBetweenPoints2D(ax,ay,bx,by) local BC_ = getDistanceBetweenPoints2D(bx,by,cx,cy) local iloczynSkalarny = AB[1]*BC[1] + AB[2]*BC[2] local tmp = iloczynSkalarny/(AB_*BC_) local kat = math.acos(tmp) local degrees = kat*180/(22/7) outputChatBox("deg "..degrees) return degrees end function getAngleBetweenPoints2D2(ax,ay,bx,by,cx,cy) local AB_ = getDistanceBetweenPoints2D(ax,ay,bx,by) local BC_ = getDistanceBetweenPoints2D(bx,by,cx,cy) local CA_ = getDistanceBetweenPoints2D(cx,cy,ax,ay) local cos = (AB_^2+BC_^2-CA_^2)/(2*AB_*BC_) local kat = math.acos(cos) local degrees = kat*180/(22/7) outputChatBox("deg "..degrees) return degrees end EDIT: Problem resolved with this: function fy(x, ax, ay, cx, cy) return (((cy-ay)/(cx-ax))*(x-ax)+ay) end function getTurnLeftOrRight2D(ax,ay,bx,by,cx,cy) if (ax==cx and ay==cy) then -- 1 --guiSetText(w, "war 1") return 1 elseif (ax==cx and ay>cy) then -- 2 --guiSetText(w, "war 2") if (bx>ax) then return 1 else return 0 end elseif (ax==cx and ay -- guiSetText(w, "war 3") if (bx>ax) then return 0 else return 1 end elseif (ax>cx and ay==cy) then -- 4 -- guiSetText(w, "war 4") if (by>ay) then return 0 else return 1 end elseif (ax -- guiSetText(w, "war 7") if (by>ay) then return 1 else return 0 end elseif (ax>cx and ay>cy) then -- 5 -- guiSetText(w, "war 5 - "..by..'==='..fy(bx, ax, ay, cx, cy)) --if (by>fy(bx, ax, ay, cx, cy)) then return 0 else return 1 end if (by>fy(bx, ax, ay, cx, cy)) then return 0 else return 1 end elseif (ax>cx and ay -- guiSetText(w, "war 6") if (by>fy(bx, ax, ay, cx, cy)) then return 0 else return 1 end elseif (axcy) then -- 8 -- guiSetText(w, "war 8") if (by>fy(bx, ax, ay, cx, cy)) then return 1 else return 0 end elseif (ax -- guiSetText(w, "war 9") if (by>fy(bx, ax, ay, cx, cy)) then return 1 else return 0 end end end thanks. Link to comment
Xierra Posted September 23, 2010 Share Posted September 23, 2010 I'm even worse, I haven't even learnt this at all! (Because, I'm still in Junior High School) Link to comment
dzek (varez) Posted September 23, 2010 Author Share Posted September 23, 2010 so simple? o_O i'll try this later - if it works edit: This is reply for removed DarkDragon's post ... Link to comment
Dark Dragon Posted September 23, 2010 Share Posted September 23, 2010 math.deg ( math.atan2(Cy-By,Cx-Bx) - math.atan2(Ay-By,Ax-Bx) ) but i'm not sure if this works under any conditions, works for the examples above at least edit: yes i removed it temporarily because i forgot to use math.deg, which resulted in a weird result, which kinda confused me. but it should work now. at least i hope so Link to comment
dzek (varez) Posted September 23, 2010 Author Share Posted September 23, 2010 as you can see im using angle*180/(22/7) instead of math.deg Link to comment
Dark Dragon Posted September 23, 2010 Share Posted September 23, 2010 well so does it achieve what you want it to? Link to comment
dzek (varez) Posted September 23, 2010 Author Share Posted September 23, 2010 dunno yet, ill try this tommorow i think Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now