I'm writing a tool to draw shapes in OneNote 2016 and having trouble with the sin and cos functions.
I'm using this code to draw a right angle triangle and a rotated square.
Code: Select all
!q::{
pi := 3.14159265358979323846
MouseGetPos(x, y)
; Draw a square rotated by 120 degrees from mouse position
Scale := 150
rad:=120*pi/180
cosRad := cos(rad)
sinRad := sin(rad)
; This is set up so that when rad = 0 the mouse is in the top left corner
; rad then rotates it counter clockwise
MouseClickDrag("LButton",x,y,x+Scale*cosRad,y-Scale*sinRad,1)
MouseClickDrag("LButton",0,0, Scale*sinRad, Scale*cosRad,1,"R")
MouseClickDrag("LButton",0,0,-Scale*cosRad, Scale*sinRad,1,"R")
MouseClickDrag("LButton",0,0,-Scale*sinRad,-Scale*cosRad,1,"R")
; Draw a right angle triangle with 30 degree angle and mouse position
Scale := 500
rad:=30*pi/180
MouseClickDrag("LButton",x,y,x+scale,y,1)
MouseClickDrag("LButton",x+scale,y,x+scale,y-scale*sin(rad),1)
MouseClickDrag("LButton",x+scale,y-scale*sin(rad),x,y,1)
}
As we can see, they are not parallel. And if you look really close at the square we can see The corners don't line up.
I'm wondering if there's a simple solution to this or if there is just a more precise sin function I could use?
What method does autohotkey use for sin?