eclectictech , FreeRaider is right, that's not an issue of the Atan2 function, with your modification, the length of the line (through the LineLength option of the [MeterLineAtoB] meter) is always equal with 0. I'm not sure this approach is good (to be honest I had no time yet to study the Atan2 function, which I didn't used for lately).
Instead probably the following LineLength option will work: LineLength=(Sqrt((([MeterPointA:X][MeterPointB:X])**2)+(([MeterPointA:Y][MeterPointB:Y])**2))). Here I used the Pythagorean theorem.
It is currently April 1st, 2020, 8:19 am
Atan2 math function

 Rainmeter Sage
 Posts: 10023
 Joined: October 11th, 2010, 6:27 pm
 Location: Gheorgheni, Romania

 Rainmeter Sage
 Posts: 3847
 Joined: April 12th, 2012, 9:40 pm
 Location: Cedar Point, Ohio, USA
Re: Atan2 math function
Well, I used the example that was provided, for the LineLength value.balala wrote:eclectictech , FreeRaider is right, that's not an issue of the Atan2 function, with your modification, the length of the line (through the LineLength option of the [MeterLineAtoB] meter) is always equal with 0. I'm not sure this approach is good (to be honest I had no time yet to study the Atan2 function, which I didn't used for lately).
Instead probably the following LineLength option will work: LineLength=(Sqrt((([MeterPointA:X][MeterPointB:X])**2)+(([MeterPointA:Y][MeterPointB:Y])**2))). Here I used the Pythagorean theorem.
I was wondering what need to be changed in the formula for LineLength (which uses Atan2) to eliminate the zero value, rather than replace it use the Pythagorean theorem; or is that the only solution? (I am not a mathematician, and I'm just getting older!)
If so, then in the example, Atan2 is only used to determine the Rotation angle, and the LineLength formula should be changed to use the Pythagorean theorem.
Thanks balala and freeraider for the insight!

 Posts: 791
 Joined: November 20th, 2012, 11:58 pm
Re: Atan2 math function
Yes, because in your case, you use the polar coordinate system for the LineLength (x=r*cos(theta) and y=r*sin(theta) where theta=atan2(y,x) and r is the radius or the ray or the hypotenuse).eclectictech wrote:Well, I used the example that was provided, for the LineLength value.
I was wondering what need to be changed in the formula for LineLength (which uses Atan2) to eliminate the zero value, rather than replace it use the Pythagorean theorem; or is that the only solution? (I am not a mathematician, and I'm just getting older!)
If so, then in the example, Atan2 is only used to determine the Rotation angle, and the LineLength formula should be changed to use the Pythagorean theorem.
Thanks balala and freeraider for the insight!
When you use the inverse formula r=x/cos(theta), the problem is in x and in cos(theta) because x=0 and theta=atan2(y,0)=PI()/2 or PI()/2 (it depends if y > 0 or y < 0), thus cos(PI()/2)=0
So, for the line length, I would use the Pythagorean theorem.

 Rainmeter Sage
 Posts: 10023
 Joined: October 11th, 2010, 6:27 pm
 Location: Gheorgheni, Romania
Re: Atan2 math function
For sure this is not the most elegant and precise solution, but a trick could be used to can use the initial formula.
According to this idea, you'll have to add a very  very small numerical value, to each difference in the LineLength formula of the [MeterLineAtoB] meter. Something like this: LineLength=(([MeterPointB:X][MeterPointA:X]+0.0001)/Cos(Atan2([MeterPointB:Y][MeterPointA:Y]+0.0001, [MeterPointB:X][MeterPointA:X]+0.0001))). The added 0.0001 in reality don't change anything in the result, but the 0 result will be avoided.
Theoretically this added value should be the possible smallest, but in reality (due to the screen resolution), not really matter if you use 0.0001 or 1, both (or any other value, smaller than 1) will give the same result.
According to this idea, you'll have to add a very  very small numerical value, to each difference in the LineLength formula of the [MeterLineAtoB] meter. Something like this: LineLength=(([MeterPointB:X][MeterPointA:X]+0.0001)/Cos(Atan2([MeterPointB:Y][MeterPointA:Y]+0.0001, [MeterPointB:X][MeterPointA:X]+0.0001))). The added 0.0001 in reality don't change anything in the result, but the 0 result will be avoided.
Theoretically this added value should be the possible smallest, but in reality (due to the screen resolution), not really matter if you use 0.0001 or 1, both (or any other value, smaller than 1) will give the same result.

 Rainmeter Sage
 Posts: 3847
 Joined: April 12th, 2012, 9:40 pm
 Location: Cedar Point, Ohio, USA
Re: Atan2 math function
Thanks for the expanded info FreeRaider (you are more of a mathematician than I am)
Balala's trick is also an option, Thanks!
I think it is 'clearer' to just use the theorem in this case.
Guess I need to clean the dust of my 50 year old math skills... Nah!
Thanks again for the answers!
Balala's trick is also an option, Thanks!
I think it is 'clearer' to just use the theorem in this case.
Guess I need to clean the dust of my 50 year old math skills... Nah!
Thanks again for the answers!

 Rainmeter Sage
 Posts: 10023
 Joined: October 11th, 2010, 6:27 pm
 Location: Gheorgheni, Romania
Re: Atan2 math function
For sure that's the best approach.eclectictech wrote:I think it is 'clearer' to just use the theorem in this case.

 Posts: 27
 Joined: October 12th, 2014, 5:27 pm
Re: Atan2 math function
Hey, could you update the first message with the Pythagore version ?
I spend too much time trying to understand why my vertical line didn't show up
I spend too much time trying to understand why my vertical line didn't show up

 Rainmeter Sage
 Posts: 10023
 Joined: October 11th, 2010, 6:27 pm
 Location: Gheorgheni, Romania
Re: Atan2 math function
It is, by eclectictech himself. He edited the initial code, replacing the initial LineLength option of the [MeterLineAtoB] meter. Now his code uses the Pythagorean theorem (see his Edit).mistic100 wrote:Hey, could you update the first message with the Pythagore version ?
I spend too much time trying to understand why my vertical line didn't show up
On the other hand, another approach (and solution) would be this. You have to add some small numerical values to each difference in the initial LineLength option (if you want to try this, just replace in eclectictech's code, the LineLength option with that posted here).

 Posts: 27
 Joined: October 12th, 2014, 5:27 pm
Re: Atan2 math function
Ok but it's not the first message, someone (like me) seing an apparently working guide/solution at the beginning of the thread won't read everything.

 Rainmeter Sage
 Posts: 3847
 Joined: April 12th, 2012, 9:40 pm
 Location: Cedar Point, Ohio, USA
Re: Atan2 math function
Here is the code from JSMorley's example with the change. (Only JSMorley can edit his post)mistic100 wrote:Ok but it's not the first message, someone (like me) seing an apparently working guide/solution at the beginning of the thread won't read everything.
Code: Select all
[Rainmeter]
Update=1000
BackgroundMode=2
SolidColor=20,30,40,255
[MeasureCounterX]
Measure=Calc
Formula=Random
UpdateRandom=1
LowBound=100
HighBound=300
[MeasureCounterY]
Measure=Calc
Formula=Random
UpdateRandom=1
LowBound=50
HighBound=150
[MeterPointA]
Meter=Image
X=0
Y=[MeasureCounterY]
W=6
H=6
SolidColor=255,0,0,255
DynamicVariables=1
[MeterPointB]
Meter=Image
X=[MeasureCounterX]
Y=0
W=6
H=6
SolidColor=191,235,255,255
DynamicVariables=1
[MeterLineAtoB]
Meter=Roundline
X=([MeterPointA:X]+([MeterPointA:W]/2))
Y=([MeterPointA:Y]+([MeterPointA:H]/2))
LineColor=255,255,255,255
LineWidth=2
LineLength=(Sqrt((([MeterPointA:X][MeterPointB:X])**2)+(([MeterPointA:Y][MeterPointB:Y])**2)))
StartAngle=Rad(360)
RotationAngle=(Atan2([MeterPointB:Y][MeterPointA:Y], [MeterPointB:X][MeterPointA:X]))
AntiAlias=1
DynamicVariables=1