Re: Matrix Multiplication bug and workaround

2017-07-30 Thread Mark Wieder via use-livecode

On 07/30/2017 04:42 PM, hh via use-livecode wrote:


Let me explain that a bit simpler for readers who don't know or forgot
linear/matrix algebra.


Thanks. That does make sense, and I did indeed need a refresher course.

--
 Mark Wieder
 ahsoftw...@gmail.com



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Matrix Multiplication bug and workaround

2017-07-30 Thread Alejandro Tejada via use-livecode
I noticed the announcement of your conference
in Livecode website:
https://livecode.com/global/hermann-hoch/

Have you checked Jim Hurley stacks?
http://jamesphurley.com/Revolution.html

Al

> These were the first two minutes of my talk
> at LC Global in Nov 2017.Now I can start after that,
> describing how to find that single set, without
> matrix algebra
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Matrix Multiplication bug and workaround

2017-07-30 Thread hh via use-livecode
Hi Al.

Yes. I saw this mistake several times. The misleading thing is, TMHO,
the name "transformation matrix" for [a,b,c,d,e,f] (because the listing
is pairwise for columns, as you now describe, and not for rows).

Let me explain that a bit simpler for readers who don't know or forgot
linear/matrix algebra.

It would be better to name it, what it is, a "transformation list".
[a,b,c,d,e,f] lists the factors [a,b,c,d] and the summands [e,f] that
define the "affine transformation" of a point (x_old,y_old) to a point
(x_new,y_new):

x_new = a*x_old + c*y_old + e
y_new = b*x_old + d*y_old + f

[a,d] are the scaling factors for (x_old,y_old),
[b,c] are the shearing factors for (x_old,y_old),
[e,f] are the translation summands for (x_old,y_old).
So [1,0,0,1,0,0] defines the identity: x_new = x_old and y_new = y_old.

Every scaling, shearing, translation or rotation of a point (x_old,y_old)
can be built by ONE single set of such a list [a,b,c,d,e,f].

Hermann

p.s. These were the first two minutes of my talk at LC Global in Nov 2017.
Now I can start after that, describing how to find that single set, without
matrix algebra ;-)


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Matrix Multiplication bug and workaround

2017-07-30 Thread Alejandro Tejada via use-livecode
Hi Hermann,

Hermann wrote:
> This is not a bug, your script is wrong.
> If TM is a,b,c,d,e,f then you have to d
>   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]

Now I understand:

This transformation matrix:
1,0.6,-1.2,1,40,10
should be stored like this:

[0,0]  [0,1]  [0,2]
  a   c   e
  1-1.2 40

[1,0]  [1,1]  [1,2]
  b   d   f
 0.6 1  10

[2,0]  [2,1]  [2,2]
  0   0   1

I will delete my bug report.
Thanks again Hermann for
taking a close look at this.

Have a nice week!

Al
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Matrix Multiplication bug and workaround

2017-07-30 Thread hh via use-livecode
Al, your script is wrong. You are building the matrix in a wrong way.
It is no bug! With your 'workaround' you point yourself to the lines
where you did make the mistake.

http://lists.runrev.com/pipermail/use-livecode/2017-July/240074.html

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Matrix Multiplication bug and workaround

2017-07-30 Thread Alejandro Tejada via use-livecode
After searching the Mail List archives, the Forum
and LiveCode Quality Center for another report
about this bug, I found nothing and have just send
a new bug report:

http://quality.livecode.com/show_bug.cgi?id=20208

Al
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Matrix Multiplication bug and workaround

2017-07-30 Thread hh 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
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Matrix Multiplication bug and workaround

2017-07-30 Thread Alejandro Tejada 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
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode