Trouble with math function!!Plz help me

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
D4ng_kun
Posts: 11
Joined: 06 Jun 2021, 23:32

Trouble with math function!!Plz help me

23 Jun 2021, 23:02

I am writing a simple script to calculate mouse coordiation but stuck with the simple math function
The problem is I use Asin and Acos to get 2 different angle (ang1 and ang2) which i confirmed the result with Msgbox
But the next step is a simple subtraction "ang3 := ang2 - ang1", but the script just gave me a blank answer
I already tried with "ang3 = %ang2% - %ang1%" but the it also led me to same result
Asked google but it seems Im the 1st (or mb the only) one met this kind of trouble

here the code:

Code: Select all

r := 200
x0 := 773
y0 := 711
x1 := 1160
y1 := 349

; CALCULATION START HERE

l := sqrt((x0-x1)**2 +(y0-y1)**2)
Msgbox % "distance is " l
ang1 := asin(r/l)   
if(y0>y1){
ang2 := acos((y0-y1)/l)  
}
ang3 = %ang2% - %ang1% ; Angle3 = for cast point X Y final calculation
xplus := r*cos(ang3)
yplus := r*sin(ang3)
xtrg := x0 + xplus
ytrg := y0+ yplus
Msgbox, Angle 1 = %ang1%`nAngle 2 = %ang2%`nAngle 3 = %ang3%`nTarget Coord X = %xtrg% , Y = %ytrg%

return
[Mod edit: [code][/code] tags added.]
TAC109
Posts: 1112
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Trouble with math function!!Plz help me

23 Jun 2021, 23:53

Code: Select all

ang3 := ang2 - ang1
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
D4ng_kun
Posts: 11
Joined: 06 Jun 2021, 23:32

Re: Trouble with math function!!Plz help me

24 Jun 2021, 00:02

TAC109 wrote:
23 Jun 2021, 23:53

Code: Select all

ang3 := ang2 - ang1
sorry but what do u mean ?
gregster
Posts: 9020
Joined: 30 Sep 2013, 06:48

Re: Trouble with math function!!Plz help me

24 Jun 2021, 00:05

Yes,

Code: Select all

ang3 := ang2 - ang1		; ideographic space removed
should work.

but without the non-printable Unicode character you have behind ang3 in your code:

Code: Select all

ang3 = %ang2% - %ang1%
which is still present in TAC109's code above... it seems to be an "Ideographic Space" (U+3000) instead of a normal space, and throws off the AHK parser.
Paste here and check: https://www.soscisurvey.de/tools/view-chars.php

Perhaps you copypasted it from some math source.
D4ng_kun
Posts: 11
Joined: 06 Jun 2021, 23:32

Re: Trouble with math function!!Plz help me

24 Jun 2021, 00:18

gregster wrote:
24 Jun 2021, 00:05
Yes,

Code: Select all

ang3 := ang2 - ang1		; ideographic space removed
should work.

but without the non-printable Unicode character you have behind ang3 in

Code: Select all

ang3 = %ang2% - %ang1%
which is still present in TAC109's edited code above... it seems to be an "Ideographic Space" (U+3000) and throws off the AHK parser.
Paste here and check: https www.soscisurvey.de /tools/view-chars.php Broken Link for safety

Probably you copypasted it from some math source.
Thank you man, u saved my day. I usually use space bettween all variables and math function operators and it all worked till this one as u can see in the upper part . Did like u said, remove all the space and voila!
Actually i wrote this one myself, not copypasted from any other source. And still a little bit confuse why ahk recognized "space" as another character only in this line.
Anyway, thank you again, have a good day sir
gregster
Posts: 9020
Joined: 30 Sep 2013, 06:48

Re: Trouble with math function!!Plz help me

24 Jun 2021, 00:23

A "normal" space (or more than one) wouldn't be a problem here - but I guess you are from a country with a language that uses these spaces (sometimes ?) ?
But there was only one of it in your whole code which you needed to remove/replace. The rest are regular space characters - they can stay.

At least, I have never "seen" this kind of space before. But I have encountered other special space characters (and other non-printable characters) in the past, which lead to similar problems. Usually, they get copied from some website, but there might be other sources... once or twice, it might drive you mad, before you get an eye for it ;).
Attachments
space.png
space.png (21.85 KiB) Viewed 316 times
TAC109
Posts: 1112
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Trouble with math function!!Plz help me

24 Jun 2021, 01:07

@gregster
Unfortunately I didn’t see the hidden character as I replied on my iPad

Cheers
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
gregster
Posts: 9020
Joined: 30 Sep 2013, 06:48

Re: Trouble with math function!!Plz help me

24 Jun 2021, 01:22

No problem, that's understandable. I only noticed it when I thought: why wouldn't this work? And then I had a suspicion.
D4ng_kun
Posts: 11
Joined: 06 Jun 2021, 23:32

Re: Trouble with math function!!Plz help me

24 Jun 2021, 01:53

gregster wrote:
24 Jun 2021, 00:23
A "normal" space (or more than one) wouldn't be a problem here - but I guess you are from a country with a language that uses these spaces (sometimes ?) ?
But there was only one of it in your whole code which you needed to remove/replace. The rest are regular space characters - they can stay.

At least, I have never "seen" this kind of space before. But I have encountered other special space characters (and other non-printable characters) in the past, which lead to similar problems. Usually, they get copied from some website, but there might be other sources... once or twice, it might drive you mad, before you get an eye for it ;).
Oh, now your answer just gave me a clear reason. Ur right, im living in Japan and Japanese keyboard had 2 modes, 1 for english and 1 for Japanese Kanji typing.
And i might be accidently switch to the Kanji one when type that "special space". Silly me !!
Thanks gregster

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: gongnl, hedehede81 and 266 guests