Jump to content

Find angle of point


Recommended Posts

How do I find a point's angle from center of screen?

Say I had a point at 200,300,

How would i get the point in degrees from the center of the screen?

Right is 0 degrees,

Down is 90,

Left is 180,

Up is 270.

Edited by corgano

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

Count pixels from @DesktopHeight/2 to the height of the pixel found...do same for width...

you know know 2 sides of a right angled triangle. Maths does the rest!

Now let's look at the problem of finding angles if you know the sides. You use the trig functions, but in reverse. Here's an example. Suppose a = 12.3 and b = 50.1. Then tan A = a/b = 12.3/50.1 = 0.2455. On a calculator, we use the inverse trig functions named arctangent, arcsine, and arccosine. Usually there's a button on the calculator labelled "inv" or "arc" that you press before pressing the appropriate trig button. The arctangent of 0.2455 is 13.79, so the angle A is 13.79°.

get angle, then chack if its negative, sorry forgot to add that, you must know which quarter of the screen it is in.

Edited by mdiesel
Link to comment
Share on other sites

Count pixels from @DesktopHeight/2 to the height of the pixel found...do same for width...

you know know 2 sides of a right angled triangle. Maths does the rest!

get angle, then chack if its negative, sorry forgot to add that, you must know which quarter of the screen it is in.

I don't know the maths. How?

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

I don't know the maths. How?

Right...

not perfect...

PS: bedtime over here! Mine is probs wrong (getting x + y the wrong way round etc), so just post here and someone else could probably be able to help you, if not PM me and I'll answer when I get round to it.

Maths is a good subject to know.

edit2: what I said about finding negatives still aplies, and you may have to do more than that, an if test maybe on if $x > @Deskheight/2....I haven't checked

edit3: you don't need aa + bb = cc...I put it in there becouse I felt like it.

Edited by mdiesel
Link to comment
Share on other sites

Try this ^_^

;center coordinate
$x1 = 200
$y1 = 300

;second coordinate
$x2 = 200
$y2 = 500

$a = $y2 - $y1
$c = $x2 - $x1
$alpha = Round(ATan($a / $c) * 180 / 3.1415926535897932384626, 2) ;convert to from rad to deg

ConsoleWrite("Angle = " & $alpha & "°" & @CRLF)

Check this out: http://en.wikipedia.org/wiki/Trigonometry

UEZ ;)

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

How do I find a point's angle from center of screen?

Say I had a point at 200,300,

How would i get the point in degrees from the center of the screen?

Right is 0 degrees,

Down is 90,

Left is 180,

Up is 270.

func Angle($X, $Y)
    
    local $CX = @DesktopWidth / 2, $CY = @DesktopHeight / 2
    
    if ($CX = $X) and ($CY = $Y) then
        return SetError(1, 0, -1)
    endif
    
    local $Grad = ($Y <= $CY) * 180 - ATan(($CX - $X) / ($CY - $Y)) * 180 / 3.1415926535897932384626 + 90
    
    if $Grad = 360 then
        $Grad = 0
    endif
    return $Grad
endfunc; Angle

^_^

Edited by Yashied
Link to comment
Share on other sites

  • 2 months later...

func Angle($X, $Y)
    
    local $CX = @DesktopWidth / 2, $CY = @DesktopHeight / 2
    
    if ($CX = $X) and ($CY = $Y) then
        return SetError(1, 0, -1)
    endif
    
    local $Grad = ($Y <= $CY) * 180 - ATan(($CX - $X) / ($CY - $Y)) * 180 / 3.1415926535897932384626 + 90
    
    if $Grad = 360 then
        $Grad = 0
    endif
    return $Grad
endfunc; Angle

:D

One question regarding your notation:

local $Grad = ($Y <= $CY) * 180 - ATan(($CX - $X) / ($CY - $Y)) * 180 / 3.1415926535897932384626 + 90

What does the notation in red means? I know <,>, >=, <= only for conditions using If...Then, etc.

Thanks,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

func Angle($X, $Y)
    
    local $CX = @DesktopWidth / 2, $CY = @DesktopHeight / 2
    
    if ($CX = $X) and ($CY = $Y) then
        return SetError(1, 0, -1)
    endif
    
    local $Grad = ($Y <= $CY) * 180 - ATan(($CX - $X) / ($CY - $Y)) * 180 / 3.1415926535897932384626 + 90
    
    if $Grad = 360 then
        $Grad = 0
    endif
    return $Grad
endfunc; AngleoÝ÷ Ûú®¢×¡×zÉ-¢¢vØZÐÞ²Kh¤w¢r^wÝ«­¢+ØÀÌØí½©]5%MÉÙ¥ô=©Ð ÅÕ½ÐíÝ¥¹µµÑÌèÀäÈìÀäÈì¸ÀäÈíɽ½ÐÀäÈí¥µØÈÅÕ½Ðì¤(ÀÌØí½±%ѵÌôÀÌØí½©]5%MÉÙ¥¹áEÕÉä ÅÕ½ÐíM±Ð¨É½´]¥¸ÌÉ}¥ÍÁ±å
½¹¥ÕÉÑ¥½¸ÅÕ½Ðì¤)½ÈÀÌØí½©%Ñ´¥¸ÀÌØí½±%ѵÌ($ÀÌØíÍÉ¹Ý¥Ñ ôÀÌØí½©%Ñ´¹A±Í]¥Ñ ($ÀÌØíÍɹ¡¥¡ÐôÀÌØí½©%Ñ´¹A±Í!¥¡Ð)9á

...too much vbscript lately.

Link to comment
Share on other sites

@sb1920alk: what do you want to say now? :D

UEZ

only that I didn't think of @DesktopHeight/Width when I needed them because I'm stuck using vbscript most if the time right now. The WMI query works in vbscript, so I used that instead. @DesktopHeight is much simpler.

Regarding ($Y <= $CY)...my guess is True/False becomes 1 (True) or 0 (False) times 180 to make the math work.

Link to comment
Share on other sites

only that I didn't think of @DesktopHeight/Width when I needed them because I'm stuck using vbscript most if the time right now. The WMI query works in vbscript, so I used that instead. @DesktopHeight is much simpler.

Regarding ($Y <= $CY)...my guess is True/False becomes 1 (True) or 0 (False) times 180 to make the math work.

I was confused why you are writing something about WMI.

Anyway, yes you are right! As long as $CY is equal or greater than it is true (1) otherwise false (0)!

A simple code showed what it means.

$Grad = 0
$CY = 10
$y = 0
While Sleep(30) and $y < 20
    $Grad = ($Y <= $CY)
    ConsoleWrite($y & ": " & $Grad & @CRLF)
    $y += 1
WEnd

It is really too late to ask such questions... :D:D

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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