Jump to content

Math problem


dzek (varez)

Recommended Posts

Posted

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?

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

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

=Benox50=

My Youtube Channel

Posted

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

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted
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.

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

so simple? o_O

i'll try this later - if it works

edit:

This is reply for removed DarkDragon's post ...

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

as you can see im using angle*180/(22/7) instead of math.deg :P

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

dunno yet, ill try this tommorow i think

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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...