Matrix Multiplication bug and workaround

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Matrix Multiplication bug and workaround

** Clarence P Martin ** via use-livecode
Using LC 8.1.3, I just found a bug in the Matrix Multiply function.

Could you check if this bug was fixed in more
recent versions of LC?

Follow this recipe to reproduce this bug:

1) Create a new stack with a button, a text field
and a check box named "showbug"

2) paste these two lines into the text field:

TM 1,0.6,-1.2,1,40,10
CO 0,30

You could find this and other examples in this webpage:

https://stackoverflow.com/documentation/svg/3249/transformation#t=20170730054300495488

3) paste this script into the button:

----------------------------------------------------------------

local tMatrix1
local tMatrix2

on mouseUp
   put empty into tMatrix1
   put empty into tMatrix2
   put empty into tNewMatrix
   put empty into tNewCoordinatePoint

   put fld 1 into tMatrixList

   repeat for each line tMX in tMatrixList

      switch word 1 of tMX
         case TM
            TransformTMatrix(word 2 of tMX)
            break
         case CO
            CoordinatePointMatrix(word 2 of tMX)
            break
      end switch

   end repeat

   put matrixMultiply(tMatrix1, tMatrix2) into tNewMatrix
      combine tNewMatrix with comma
      answer item 1 to 2 of tNewMatrix

end mouseUp

on TransformTMatrix pArgs
   local tA
   local tB
   local tC
   local tD
   local tE
   local tF

   local tMatrix

if the hilite of btn "showbug" then
   put item 1 of pArgs into tA
   put item 2 of pArgs into tB
   put item 3 of pArgs into tC
   put item 4 of pArgs into tD
else -- use a workaround
   put item 1 of pArgs into tA
   put item 2 of pArgs into tC -- change position
   put item 3 of pArgs into tB -- change position
   put item 4 of pArgs into tD
end if

   put tA into tMatrix[0,0]
   put tB into tMatrix[0,1]
   put tC into tMatrix[1,0]
   put tD into tMatrix[1,1]

   if (the number of items in pArgs) is 6 then
      put item 5 of pArgs into tE
      put item 6 of pArgs into tF
   else
      put 0 into tE
      put 0 into tF
   end if

   put tE into tMatrix[0,2]
   put tF into tMatrix[1,2]

   put 0 into tMatrix[2,0]
   put 0 into tMatrix[2,1]
   put 1 into tMatrix[2,2]

   if tMatrix1 is empty
   then
      put tMatrix into tMatrix1
      return empty
   end if

end TransformTMatrix

on CoordinatePointMatrix tArgs
   put item 1 of tArgs into tG
   put item 2 of tArgs into tH

   put tG into tCoordinatePoint[0,0]
   put tH into tCoordinatePoint[1,0]
   put 1 into tCoordinatePoint[2,0]

   if tMatrix1 is empty
   then
      put tCoordinatePoint into tMatrix1
      return empty
   end if

   if tMatrix2 is empty
   then
      put tCoordinatePoint into tMatrix2
      return empty
   end if

end CoordinatePointMatrix

----------------------------------------------------------------

4) Hilite the check box "showbug" and click
the button... the result is 58,40
This result is wrong.

5) Unhilite the check box "showbug" and click
the button... the result is 4,40
This result is correct.

If this bug is still present in more recent LC versions.
Could you report it to the Quality Center?

Thanks in advance!

Al
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Matrix Multiplication bug and workaround

** Clarence P Martin ** via use-livecode
Hi Al.

This is not a bug, your script is wrong.

If TM is a,b,c,d,e,f then you have to do

   put item 1 of pArgs into tMatrix[0,0]
   put item 2 of pArgs into tMatrix[1,0]
   put item 3 of pArgs into tMatrix[0,1]
   put item 4 of pArgs into tMatrix[1,1]

this yields correct results.

[In fact your 'workaround' corrects the wrong script part]

Hermann


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Loading...