# 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

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

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

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

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

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

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

endif
endfunc; Angle```

Edited by Yashied

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

endif
endfunc; Angle```

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

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

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

endif

...too much vbscript lately.

##### Share on other sites

@sb1920alk: what do you want to say now?

UEZ

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

##### Share on other sites

@sb1920alk: what do you want to say now?

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.

##### 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
ConsoleWrite(\$y & ": " & \$Grad & @CRLF)
\$y += 1
WEnd```

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

UEZ

Edited by UEZ

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

## Create an account

Register a new account

×

• Wiki

• Back

• Git