-Sin(-angle) _ Does this work?

Started by stevmjon, July 17, 2022, 11:31:48 PM

Previous topic - Next topic

stevmjon

not sure about this. i have older programs where this calc works fine, then it doesn't work in my newer programs.

the 'z' value in the code should be the same???
rz1 & rz2 should give the same result...

PlayBASIC Code: [Select]
x# = 2  :  z# = 3
angle# = 10

; goal = rotate around y axis so camera looks down zero angle (calc must be reversed angle)

; x# = x# * cos(-angle#) + z# * sin(-angle#)
; z# = x# * -sin(-angle#) + z# * cos(-angle#)

rx# = x# * cos(-angle#) + z# * sin(-angle#)

rz1# = x# * -sin(-angle#) + z# * cos(-angle#) ; *** wrong value here ??? ***
rz2# = x# * sin(angle#) + z# * cos(-angle#) ; *** alter equation here _ remove minus sign before sin() and use same angle ***
; NOTE: both z values should be the same answer

print "rx = "+str$(rx#)
print ""
print "rz1 -sin(-a) = "+str$(rz1#)+" ?"
print "rz2 sin(a) = "+str$(rz2#)

sync : flushkeys : waitkey


It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

kevin

#1
 I don't know....  but will have a loook :)


So for future reference 1,64P4  returns



rx = 1.448671

rz1 -sin(-a) = 6.256143 ?
rz2 sin(a) = 3.30172





 Pb 1.65 returns


rx = 1.448671

rz1 -sin(-a) = 6.256143 ?
rz2 sin(a) = 3.30172



 You could swap the unary negation for a mult by *-1 as I've a feeling that'd be the issue.  


PlayBASIC Code: [Select]
rz1# = x# * (sin(angle#*-1)*-1) + z# * cos(-angle#)  ;  *** wrong value here Huh ***
rz2# = x# * sin(angle#) + z# * cos(-angle#) ; *** alter equation here _ remove minus sign before sin() and use same angle ***

 

  This seems to work, so my best guess would be the order of operations between the Mult and the negation of the SIN in the original expression.

  ie.  x# * -sin(-angle#)


kevin


  It's a result of some precedence in the compiler.   If you bracket the -sin(-angle#) it produces the same result..  Internally I think the wrapper inserts a mult by -1, but it's been a LONG time since i looked at that code.       


PlayBASIC Code: [Select]
x# = 2
z# = 3
angle# = 10

; goal = rotate ar

; x# = x# * cos(-angle#) + z# * sin(-angle#)
; z# = x# * -sin(-angle#) + z# * cos(-angle#)


Print angle#


rx# = x# * Cos(-angle#) + z# * Sin(-angle#)

rz1# = x# * (-Sin(-angle#)) + z# * Cos(-angle#) ; *** wrong value here Huh ***
rz2# = x# * Sin(angle#) + z# * Cos(-angle#) ; *** alter equation here _ remove minus sign before sin() and use same angle ***
; NOTE: both z values should be the same answer

Print "rx = "+Str$(rx#)
Print ""
Print "rz1 -sin(-a) = "+Str$(rz1#)+" ?"
Print "rz2 sin(a) = "+Str$(rz2#)



sync
waitkey