ZBrushCentral

How can i get this angle ?

Angle between the horizontal and the line define by mouseDown and mouseUp

I was triing to use ATAN, but i realise i allways get a number between 0 and 90 . Then somebody told me i should use ATAN2, but i’m getting very weird results.


 
 [IConfig,3.0]
 [VarDef, a ]
 [VarDef, b ]
 [VarDef, angle]
 [RoutineDef, ZMarkingMenu,
 // Get X and Y for mouseDown position
 	[Loop, 999999,				  // loop until left mouse button is clicked
 		[If, ([MouseLButton ] == 1),
 			[VarSet, Cx1, INT([MouseHPos]+.5) ]
 			[VarSet, Cy1, INT([MouseVPos]+.5) ]
 			[LoopExit ]
 		]
 	]
 // Get X and Y for mouseUp position
 	[Loop,999999,												// loop until left mouse button is released
 		[If, ([MouseLButton ] == 0),
 			[VarSet, Cx2, INT([MouseHPos ]+.5) ]
 			[VarSet, Cy2, INT([MouseVPos ]+.5) ]
 			[LoopExit ]
 		]
 	]
 // Return comand 
 	[VarSet, a , Cx2 - Cx1 ]
 	[VarSet, b , Cy2 - Cy1 ]
 	[VarSet, angle , ATAN2(b/a) ]
 // Display result
 	[Note, [StrMerge, "
The angle is :",angle ] ]
 	,Cx1, Cy1, Cx2, Cy2 //, ButtonLink
 ]
 [ISubPalette,Zplugin:CTScripts] 
 //*------------------------------------------------------------------------------------------
 [IButton, "Zplugin:CTScripts:TEST ", "Test",
 		[Routinecall, ZMarkingMenu, x1, y1, x2, y2 ]// ,"ZSCRIPT:Select"
 ,,76,126,,]
 
 
 

ATAN2 should do it but it takes two arguments. Try putting


	[VarSet, a , (Cx2 - Cx1) ]
 	[VarSet, b , NEG(Cy2 - Cy1) ]
 	[VarSet, angle , ATAN2(b,a) ]

in your code. NEG the y coordinates will correct the angle, assuming an anticlockwise rotation.

thanks marcus,

i forgot to change after i tried with ATAN. i still don’t understand why should i negate the y.

The origin (0,0) for the ZBrush screen is the top left corner. That means that as you move the mouse down Y increases, whereas with Cartesian coordinates Y increases as you move upwards. X is OK as both increase to the right.

now i understand. thanks for the explanation and for the help.