Jump to content

Math problem


dzek (varez)

Recommended Posts

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 :

88114193.png

if you cant with that I have another thing, but with the produit scalaire in french

Link to comment
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
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:

uklad.png

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...