Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CGAffineTransform はどう動いてるのか?〜Swift エンジニアのための線形代数〜 / How does CGAffineTransform work? ~A linearity lesson for Swift engineers~

Elvis Shi
September 21, 2020

CGAffineTransform はどう動いてるのか?〜Swift エンジニアのための線形代数〜 / How does CGAffineTransform work? ~A linearity lesson for Swift engineers~

Elvis Shi

September 21, 2020
Tweet

More Decks by Elvis Shi

Other Decks in Programming

Transcript

  1. $("GpOF5SBOTGPSN͸Ͳ͏ಇ͍ͯΔͷ͔ʁ
    ʙ4XJGUΤϯδχΞͷͨΊͷઢܗ୅਺ʙ
    f o r J 0 4 % $ +BQ B O

    View full-size slide

  2. $("GpOF5SBOTGPSN͸Ͳ͏ಇ͍ͯΔͷ͔ʁ
    ʙ4XJGUΤϯδχΞͷͨΊͷઢܗ୅਺ʙ
    f o r J 0 4 % $ +BQ B O
    嬭⓸

    View full-size slide

  3. ઢܗ୅਺
    ߦྻ
    ߦྻࣜ ݻ༗ۭؒ
    ઢܕ
    ํఔࣜ
    FUD
    ࠓ೔औΓ্͛Δൣғ

    View full-size slide

  4. }
    var employedBy = "YUMEMI Inc."
    var job = "iOS Tech Lead"
    var favoriteLanguage = "Swift"
    var twitter = "@lovee"
    var qiita = "lovee"
    var github = "el-hoshino"
    var additionalInfo = """
    ͸΍͘ίϩφऩଋͯ͠ग़ࣾۈ຿͍ͨ͠…
    """
    final class Me: Developable, Talkable {

    View full-size slide

  5. ͦ΋ͦ΋
    CGAffineTransformͬͯʁ

    View full-size slide

  6. Ҡಈ
    5SBOTMBUJPO
    ֦ॖ 4DBMJOH
    ճస
    3PUBUJPO

    View full-size slide

  7. "GpOF5SBOTGPSN
    ΞϑΟϯม׵

    View full-size slide

  8. O
    ΦϒδΣΫτݻ༗࠲ඪ ΞϑΟϯม׵ ΦϒδΣΫτදࣔ࠲ඪ
    O

    View full-size slide

  9. ΞϑΟϯม׵͸࠲ඪม׵ͷҰछ

    View full-size slide

  10. IUUQTTQFBLFSEFDLDPNMPWFFDHBGpOFUSBOTGPSNTIJKJBOSVNFO

    View full-size slide

  11. IUUQTTQFBLFSEFDLDPNMPWFFDHBGpOFUSBOTGPSNTIJKJBOSVNFO

    View full-size slide

  12. IUUQTTQFBLFSEFDLDPNMPWFFDHBGpOFUSBOTGPSNTIJKJBOSVNFO

    View full-size slide

  13. CGAffineTransform͸
    ΞϑΟϯม׵Λදݱ͢ΔͨΊʹ
    $PSF(SBQIJDT্ͷσʔλߏ଄

    View full-size slide

  14. ΞϑΟϯࣸ૾
    ΞϑΟϯม׵
    O O
    x ax + by + t
    x
    x′
    y cx + dy + t
    y
    y′
    P(x, y)
    P′ (x′ , y′ )

    View full-size slide

  15. O O
    a = 1.5
    c = 0.8
    tx = 13
    ty = 2
    b = -0.1
    d = 0.9
    x = 10
    y = 10
    x' = 27
    y' = 19
    x ax + by + t
    x
    x′
    y cx + dy + t
    y
    y′
    P(10, 10)
    P′ (27, 19)

    View full-size slide

  16. O O
    a = 1.5
    c = 0.8
    tx = 13
    ty = 2
    b = -0.1
    d = 0.9
    x = 10
    y = 10
    x' = 27
    y' = 19
    x = 0
    y = 0
    x' = 13
    y' = 2
    x ax + by + t
    x
    x′
    y cx + dy + t
    y
    y′
    O(0, 0)
    O′ (13, 2)

    View full-size slide

  17. O
    O(0, 0)
    O′ (13, 2)
    O
    a = 1.5
    c = 0.8
    tx = 13
    ty = 2
    b = -0.1
    d = 0.9
    x = 10
    y = 10
    x' = 27
    y' = 19
    x = 0
    y = 0
    x' = 13
    y' = 2
    x ax + by + t
    x
    x′
    y cx + dy + t
    y
    y′
    CGAffineTransformͷ
    a b c d tx
    ty
    Ͱ͢

    View full-size slide

  18. ΞϑΟϯม׵͸
    ࠲ඪม׵ͷϝιουͰ͋Γ
    ௚઀తʹҠಈ΍֦ॖΛѻΘͳ͍

    View full-size slide

  19. Ҡಈ
    5SBOTMBUJPO
    ֦ॖ 4DBMJOH
    ճస
    3PUBUJPO

    View full-size slide

  20. a = 1
    c = 0
    tx = 0
    ty = 0
    b = 0
    d = 1
    x = 10
    y = 10
    x' = 10
    y' = 10
    ม׵ޙɺݻ༗࠲ඪͱશ͘ಉ͡දࣔ࠲ඪ
    P(x, y)
    x ax + by + t
    x
    x′
    y cx + dy + t
    y
    y′

    View full-size slide

  21. Ҡಈ
    5SBOTMBUJPO
    a = 1
    c = 0
    tx = tx
    ty = ty
    b = 0
    d = 1
    x = 10
    y = 10
    x' = 10 + tx
    y' = 10 + ty
    ม׵ޙɺݻ༗࠲ඪΑΓ
    Y͕࣠UYɺZ͕࣠UZҠಈͨ͠࠲ඪ
    P(x, y) P′ (x′ , y′ )
    x ax + by + t
    x
    x′
    y cx + dy + t
    y
    y′

    View full-size slide

  22. ֦ॖ
    4DBMJOH
    a = a
    c = 0
    tx = 0
    ty = 0
    b = 0
    d = d
    x = 10
    y = 10
    x' = 10a
    y' = 10d
    ม׵ޙɺݻ༗࠲ඪΑΓ
    Y͕࣠BഒɺZ͕࣠Eഒ֦େͨ͠࠲ඪ
    P(x, y)
    P′ (x′ , y′ )
    x ax + by + t
    x
    x′
    y cx + dy + t
    y
    y′

    View full-size slide

  23. ճస
    3PUBUJPO
    a = cos(θ)
    c = sin(θ)
    tx = 0
    ty = 0
    b = -sin(θ)
    d = cos(θ)
    x = 10
    y = 10
    x' = 10a + 10b
    y' = 10c + 10d
    ม׵ޙɺݻ༗࠲ඪΑΓ
    В˃ճసͨ͠࠲ඪ
    P(x, y)
    P′ (x′ , y′ )
    x ax + by + t
    x
    x′
    y cx + dy + t
    y
    y′

    View full-size slide

  24. IUUQTTQFBLFSEFDLDPNMPWFFDHBGpOFUSBOTGPSNTIJKJBOSVNFO

    View full-size slide

  25. ࿩͕͍ͩͿ௕͔ͬͨɻ
    ͱ͜ΖͰɺߦྻͬͯʁ

    View full-size slide

  26. O O
    x ax + by + t
    x
    x′
    y cx + dy + t
    y
    y′
    P(x, y)
    P′ (x′ , y′ )

    View full-size slide

  27. O O
    ߦྻ
    (
    a b
    c d)
    ×
    (
    x
    y)
    +
    (
    t
    x
    t
    y)
    =
    (
    x′
    y′ )
    P(x, y)
    P′ (x′ , y′ )

    View full-size slide

  28. ߦྻɿͦΕ͸ఆ·ͬͨߦͱྻʹΑΔ
    ɹɹɹ਺ࣈͷ૊Έ߹Θͤ
    (
    1 2
    3 4)
    458 488
    718 911
    595 124
    (
    79.9 56 86
    89 61 88)

    View full-size slide

  29. A =
    a
    11
    a
    12
    … a
    1n
    a
    21
    a
    22
    … a
    2n
    ⋮ ⋮ ⋱ ⋮
    a
    m1
    a
    m2
    … a
    mn
    NߦOྻ
    w ߦ ྻͷߦྻΛ ܕߦྻͱݴ͏
    w ߦ໨ ྻ໨ͷ਺ Λ ͷ ੒෼ͱݴ͏
    m n (m, n)
    i j a
    ij
    A (i, j)

    View full-size slide

  30. ༷ʑͳߦྻʢʣɿྵߦྻ
    O =
    0 0 … 0
    0 0 … 0
    ⋮ ⋮ ⋱ ⋮
    0 0 … 0
    ྵߦྻ͸ ͱ΋දه͞ΕΔ
    O
    શͯͷ੒෼͕ ͷߦྻΛྵߦྻͱݺͿ
    0

    View full-size slide

  31. ༷ʑͳߦྻʢʣɿਖ਼ํߦྻ
    A =
    a
    11
    a
    12
    … a
    1n
    a
    21
    a
    22
    … a
    2n
    ⋮ ⋮ ⋱ ⋮
    a
    n1
    a
    n2
    … a
    nn
    ܕਖ਼ํߦྻ ࣍ਖ਼ํߦྻͱݺͿ
    (n, n) n
    ߦ਺ͱྻ਺͕౳͍͠ߦྻΛਖ਼ํߦྻͱݺͿ

    View full-size slide

  32. ༷ʑͳߦྻʢʣɿ୯Ґߦྻ
    E
    n
    =
    1 0 … 0
    0 1 … 0
    ⋮ ⋮ ⋱ ⋮
    0 0 … 1
    ࣍ਖ਼ํߦྻͰ΋ɺ ੒෼͕ ɺͦΕҎ֎ͷ੒෼͕ ͷ
    ߦྻΛ୯ҐߦྻͱݺͿ
    n a
    ii
    1 0
    ࣍୯Ґߦྻ͸ ͱ΋දه͞ΕΔ
    n E
    n

    View full-size slide

  33. ߦྻͷܭࢉʢʣɿ૬౳
    A =
    a
    11
    a
    12
    … a
    1n
    a
    21
    a
    22
    … a
    2n
    ⋮ ⋮ ⋱ ⋮
    a
    m1
    a
    m2
    … a
    mn
    B =
    b
    11
    b
    12
    … b
    1n
    b
    21
    b
    22
    … b
    2n
    ⋮ ⋮ ⋱ ⋮
    b
    m1
    b
    m2
    … b
    mn
    શͯͷ ɺ ʹର͠ɺ ͳ
    Βɺߦྻ ͱߦྻ ͕૬౳ʢٯ΋વΓʣ
    i j (1 ≤ i ≤ m, 1 ≤ j ≤ n) a
    ij
    = b
    ij
    A B
    ೋͭͷಉܕʢ ܕʣߦྻ ɺ ʹ͍ͭͯɿ
    (m, n) A B

    View full-size slide

  34. ߦྻͷܭࢉʢʣɿ࿨ͱࠩ
    A =
    a
    11
    a
    12
    … a
    1n
    a
    21
    a
    22
    … a
    2n
    ⋮ ⋮ ⋱ ⋮
    a
    m1
    a
    m2
    … a
    mn
    B =
    b
    11
    b
    12
    … b
    1n
    b
    21
    b
    22
    … b
    2n
    ⋮ ⋮ ⋱ ⋮
    b
    m1
    b
    m2
    … b
    mn
    A ± B =
    a
    11
    ± b
    11
    a
    12
    ± b
    12
    … a
    1n
    ± b
    1n
    a
    21
    ± b
    21
    a
    22
    ± b
    22
    … a
    2n
    ± b
    2n
    ⋮ ⋮ ⋱ ⋮
    a
    m1
    ± b
    m1
    a
    m2
    ± b
    m2
    … a
    mn
    ± b
    mn
    ೋͭͷಉܕʢ ܕʣߦྻ ɺ ʹ͍ͭͯɿ
    (m, n) A B

    View full-size slide

  35. ߦྻͷܭࢉʢʣɿ࣮਺ഒ
    A =
    a
    11
    a
    12
    … a
    1n
    a
    21
    a
    22
    … a
    2n
    ⋮ ⋮ ⋱ ⋮
    a
    m1
    a
    m2
    … a
    mn
    λ × A =
    λ × a
    11
    λ × a
    12
    … λ × a
    1n
    λ × a
    21
    λ × a
    22
    … λ × a
    2n
    ⋮ ⋮ ⋱ ⋮
    λ × a
    m1
    λ × a
    m2
    … λ × a
    mn
    ࣮਺ ͱߦྻ ʹ͍ͭͯɿ
    λ A

    View full-size slide

  36. ߦྻͷܭࢉʢʣɿੵ
    A =
    a
    11
    a
    12
    … a
    1n
    a
    21
    a
    22
    … a
    2n
    ⋮ ⋮ ⋱ ⋮
    a
    m1
    a
    m2
    … a
    mn
    B =
    b
    11
    b
    12
    … b
    1l
    b
    21
    b
    22
    … b
    2l
    ⋮ ⋮ ⋱ ⋮
    b
    n1
    b
    n2
    … b
    nl

    ˞
    A × B =
    ∑n
    k=1
    a
    1k
    × b
    k1
    ∑n
    k=1
    a
    1k
    × b
    k2
    … ∑n
    k=1
    a
    1k
    × b
    kl
    ∑n
    k=1
    a
    2k
    × b
    k1
    ∑n
    k=1
    a
    2k
    × b
    k2
    … ∑n
    k=1
    a
    2k
    × b
    kl
    ⋮ ⋮ ⋱ ⋮
    ∑n
    k=1
    a
    mk
    × b
    k1
    ∑n
    k=1
    a
    mk
    × b
    k2
    … ∑n
    k=1
    a
    mk
    × b
    kl
    n

    k=1
    a
    1k
    × b
    k1
    = a
    11
    × b
    11
    + a
    12
    × b
    21
    + … + a
    1n
    × b
    n1
    ܕߦྻ ͱɺ ܕߦྻ ʹ͍ͭͯɿ
    (m, n) A (n, l) B

    View full-size slide

  37. ߦྻͷܭࢉʢʣɿੵ
    A =
    a
    11
    a
    12
    … a
    1n
    a
    21
    a
    22
    … a
    2n
    ⋮ ⋮ ⋱ ⋮
    a
    m1
    a
    m2
    … a
    mn
    B =
    b
    11
    b
    12
    … b
    1l
    b
    21
    b
    22
    … b
    2l
    ⋮ ⋮ ⋱ ⋮
    b
    n1
    b
    n2
    … b
    nl

    ˞
    A × B =
    ∑n
    k=1
    a
    1k
    × b
    k1
    ∑n
    k=1
    a
    1k
    × b
    k2
    … ∑n
    k=1
    a
    1k
    × b
    kl
    ∑n
    k=1
    a
    2k
    × b
    k1
    ∑n
    k=1
    a
    2k
    × b
    k2
    … ∑n
    k=1
    a
    2k
    × b
    kl
    ⋮ ⋮ ⋱ ⋮
    ∑n
    k=1
    a
    mk
    × b
    k1
    ∑n
    k=1
    a
    mk
    × b
    k2
    … ∑n
    k=1
    a
    mk
    × b
    kl
    n

    k=1
    a
    1k
    × b
    k1
    = a
    11
    × b
    11
    + a
    12
    × b
    21
    + … + a
    1n
    × b
    n1
    ܕߦྻ ͱɺ ܕߦྻ ʹ͍ͭͯɿ
    (m, n) A (n, l) B

    View full-size slide

  38. ߦྻͷܭࢉʢʣɿੵ
    A =
    a
    11
    a
    12
    … a
    1n
    a
    21
    a
    22
    … a
    2n
    ⋮ ⋮ ⋱ ⋮
    a
    m1
    a
    m2
    … a
    mn
    B =
    b
    11
    b
    12
    … b
    1l
    b
    21
    b
    22
    … b
    2l
    ⋮ ⋮ ⋱ ⋮
    b
    n1
    b
    n2
    … b
    nl

    ˞
    A × B =
    ∑n
    k=1
    a
    1k
    × b
    k1
    ∑n
    k=1
    a
    1k
    × b
    k2
    … ∑n
    k=1
    a
    1k
    × b
    kl
    ∑n
    k=1
    a
    2k
    × b
    k1
    ∑n
    k=1
    a
    2k
    × b
    k2
    … ∑n
    k=1
    a
    2k
    × b
    kl
    ⋮ ⋮ ⋱ ⋮
    ∑n
    k=1
    a
    mk
    × b
    k1
    ∑n
    k=1
    a
    mk
    × b
    k2
    … ∑n
    k=1
    a
    mk
    × b
    kl
    n

    k=1
    a
    1k
    × b
    k1
    = a
    11
    × b
    11
    + a
    12
    × b
    21
    + … + a
    1n
    × b
    n1
    ܕߦྻ ͱɺ ܕߦྻ ʹ͍ͭͯɿ
    (m, n) A (n, l) B

    View full-size slide

  39. ߦྻͷܭࢉʢʣɿੵ
    A =
    a
    11
    a
    12
    … a
    1n
    a
    21
    a
    22
    … a
    2n
    ⋮ ⋮ ⋱ ⋮
    a
    m1
    a
    m2
    … a
    mn
    B =
    b
    11
    b
    12
    … b
    1l
    b
    21
    b
    22
    … b
    2l
    ⋮ ⋮ ⋱ ⋮
    b
    n1
    b
    n2
    … b
    nl

    ˞
    A × B =
    ∑n
    k=1
    a
    1k
    × b
    k1
    ∑n
    k=1
    a
    1k
    × b
    k2
    … ∑n
    k=1
    a
    1k
    × b
    kl
    ∑n
    k=1
    a
    2k
    × b
    k1
    ∑n
    k=1
    a
    2k
    × b
    k2
    … ∑n
    k=1
    a
    2k
    × b
    kl
    ⋮ ⋮ ⋱ ⋮
    ∑n
    k=1
    a
    mk
    × b
    k1
    ∑n
    k=1
    a
    mk
    × b
    k2
    … ∑n
    k=1
    a
    mk
    × b
    kl
    n

    k=1
    a
    1k
    × b
    k1
    = a
    11
    × b
    11
    + a
    12
    × b
    21
    + … + a
    1n
    × b
    n1
    ܕߦྻ ͱɺ ܕߦྻ ʹ͍ͭͯɿ
    (m, n) A (n, l) B

    View full-size slide

  40. ߦྻͷܭࢉʢʣɿੵ
    A =
    a
    11
    a
    12
    … a
    1n
    a
    21
    a
    22
    … a
    2n
    ⋮ ⋮ ⋱ ⋮
    a
    m1
    a
    m2
    … a
    mn
    B =
    b
    11
    b
    12
    … b
    1l
    b
    21
    b
    22
    … b
    2l
    ⋮ ⋮ ⋱ ⋮
    b
    n1
    b
    n2
    … b
    nl

    ˞
    A × B =
    ∑n
    k=1
    a
    1k
    × b
    k1
    ∑n
    k=1
    a
    1k
    × b
    k2
    … ∑n
    k=1
    a
    1k
    × b
    kl
    ∑n
    k=1
    a
    2k
    × b
    k1
    ∑n
    k=1
    a
    2k
    × b
    k2
    … ∑n
    k=1
    a
    2k
    × b
    kl
    ⋮ ⋮ ⋱ ⋮
    ∑n
    k=1
    a
    mk
    × b
    k1
    ∑n
    k=1
    a
    mk
    × b
    k2
    … ∑n
    k=1
    a
    mk
    × b
    kl
    n

    k=1
    a
    1k
    × b
    k1
    = a
    11
    × b
    11
    + a
    12
    × b
    21
    + … + a
    1n
    × b
    n1
    ܕߦྻ ͱɺ ܕߦྻ ʹ͍ͭͯɿ
    (m, n) A (n, l) B

    View full-size slide

  41. ߦྻͷܭࢉʢʣɿੵ
    A =
    a
    11
    a
    12
    … a
    1n
    a
    21
    a
    22
    … a
    2n
    ⋮ ⋮ ⋱ ⋮
    a
    m1
    a
    m2
    … a
    mn
    B =
    b
    11
    b
    12
    … b
    1l
    b
    21
    b
    22
    … b
    2l
    ⋮ ⋮ ⋱ ⋮
    b
    n1
    b
    n2
    … b
    nl

    ˞
    A × B =
    ∑n
    k=1
    a
    1k
    × b
    k1
    ∑n
    k=1
    a
    1k
    × b
    k2
    … ∑n
    k=1
    a
    1k
    × b
    kl
    ∑n
    k=1
    a
    2k
    × b
    k1
    ∑n
    k=1
    a
    2k
    × b
    k2
    … ∑n
    k=1
    a
    2k
    × b
    kl
    ⋮ ⋮ ⋱ ⋮
    ∑n
    k=1
    a
    mk
    × b
    k1
    ∑n
    k=1
    a
    mk
    × b
    k2
    … ∑n
    k=1
    a
    mk
    × b
    kl
    n

    k=1
    a
    1k
    × b
    k1
    = a
    11
    × b
    11
    + a
    12
    × b
    21
    + … + a
    1n
    × b
    n1
    ܕߦྻ ͱɺ ܕߦྻ ʹ͍ͭͯɿ
    (m, n) A (n, l) B

    View full-size slide

  42. ߦྻͷܭࢉʢʣɿੵ
    A =
    a
    11
    a
    12
    … a
    1n
    a
    21
    a
    22
    … a
    2n
    ⋮ ⋮ ⋱ ⋮
    a
    m1
    a
    m2
    … a
    mn
    B =
    b
    11
    b
    12
    … b
    1l
    b
    21
    b
    22
    … b
    2l
    ⋮ ⋮ ⋱ ⋮
    b
    n1
    b
    n2
    … b
    nl

    ˞
    A × B =
    ∑n
    k=1
    a
    1k
    × b
    k1
    ∑n
    k=1
    a
    1k
    × b
    k2
    … ∑n
    k=1
    a
    1k
    × b
    kl
    ∑n
    k=1
    a
    2k
    × b
    k1
    ∑n
    k=1
    a
    2k
    × b
    k2
    … ∑n
    k=1
    a
    2k
    × b
    kl
    ⋮ ⋮ ⋱ ⋮
    ∑n
    k=1
    a
    mk
    × b
    k1
    ∑n
    k=1
    a
    mk
    × b
    k2
    … ∑n
    k=1
    a
    mk
    × b
    kl
    n

    k=1
    a
    1k
    × b
    k1
    = a
    11
    × b
    11
    + a
    12
    × b
    21
    + … + a
    1n
    × b
    n1
    ܕߦྻ ͱɺ ܕߦྻ ʹ͍ͭͯɿ
    (m, n) A (n, l) B

    View full-size slide

  43. ߦྻͷܭࢉʢʣɿੵ
    A =
    a
    11
    a
    12
    … a
    1n
    a
    21
    a
    22
    … a
    2n
    ⋮ ⋮ ⋱ ⋮
    a
    m1
    a
    m2
    … a
    mn
    B =
    b
    11
    b
    12
    … b
    1l
    b
    21
    b
    22
    … b
    2l
    ⋮ ⋮ ⋱ ⋮
    b
    n1
    b
    n2
    … b
    nl

    ˞
    A × B =
    ∑n
    k=1
    a
    1k
    × b
    k1
    ∑n
    k=1
    a
    1k
    × b
    k2
    … ∑n
    k=1
    a
    1k
    × b
    kl
    ∑n
    k=1
    a
    2k
    × b
    k1
    ∑n
    k=1
    a
    2k
    × b
    k2
    … ∑n
    k=1
    a
    2k
    × b
    kl
    ⋮ ⋮ ⋱ ⋮
    ∑n
    k=1
    a
    mk
    × b
    k1
    ∑n
    k=1
    a
    mk
    × b
    k2
    … ∑n
    k=1
    a
    mk
    × b
    kl
    n

    k=1
    a
    1k
    × b
    k1
    = a
    11
    × b
    11
    + a
    12
    × b
    21
    + … + a
    1n
    × b
    n1
    ܕߦྻ ͱɺ ܕߦྻ ʹ͍ͭͯɿ
    (m, n) A (n, l) B

    View full-size slide

  44. ߦྻͷܭࢉʢʣɿੵ
    A =
    a
    11
    a
    12
    … a
    1n
    a
    21
    a
    22
    … a
    2n
    ⋮ ⋮ ⋱ ⋮
    a
    m1
    a
    m2
    … a
    mn
    B =
    b
    11
    b
    12
    … b
    1l
    b
    21
    b
    22
    … b
    2l
    ⋮ ⋮ ⋱ ⋮
    b
    n1
    b
    n2
    … b
    nl

    ˞
    A × B =
    ∑n
    k=1
    a
    1k
    × b
    k1
    ∑n
    k=1
    a
    1k
    × b
    k2
    … ∑n
    k=1
    a
    1k
    × b
    kl
    ∑n
    k=1
    a
    2k
    × b
    k1
    ∑n
    k=1
    a
    2k
    × b
    k2
    … ∑n
    k=1
    a
    2k
    × b
    kl
    ⋮ ⋮ ⋱ ⋮
    ∑n
    k=1
    a
    mk
    × b
    k1
    ∑n
    k=1
    a
    mk
    × b
    k2
    … ∑n
    k=1
    a
    mk
    × b
    kl
    n

    k=1
    a
    1k
    × b
    k1
    = a
    11
    × b
    11
    + a
    12
    × b
    21
    + … + a
    1n
    × b
    n1
    ܕߦྻ ͱɺ ܕߦྻ ʹ͍ͭͯɿ
    (m, n) A (n, l) B

    View full-size slide

  45. ߦྻͷܭࢉʢʣɿੵ
    A =
    a
    11
    a
    12
    … a
    1n
    a
    21
    a
    22
    … a
    2n
    ⋮ ⋮ ⋱ ⋮
    a
    m1
    a
    m2
    … a
    mn
    B =
    b
    11
    b
    12
    … b
    1l
    b
    21
    b
    22
    … b
    2l
    ⋮ ⋮ ⋱ ⋮
    b
    n1
    b
    n2
    … b
    nl

    ˞
    A × B =
    ∑n
    k=1
    a
    1k
    × b
    k1
    ∑n
    k=1
    a
    1k
    × b
    k2
    … ∑n
    k=1
    a
    1k
    × b
    kl
    ∑n
    k=1
    a
    2k
    × b
    k1
    ∑n
    k=1
    a
    2k
    × b
    k2
    … ∑n
    k=1
    a
    2k
    × b
    kl
    ⋮ ⋮ ⋱ ⋮
    ∑n
    k=1
    a
    mk
    × b
    k1
    ∑n
    k=1
    a
    mk
    × b
    k2
    … ∑n
    k=1
    a
    mk
    × b
    kl
    n

    k=1
    a
    1k
    × b
    k1
    = a
    11
    × b
    11
    + a
    12
    × b
    21
    + … + a
    1n
    × b
    n1
    ܕߦྻ ͱɺ ܕߦྻ ʹ͍ͭͯɿ
    (m, n) A (n, l) B

    View full-size slide

  46. ߦྻͷܭࢉʢʣɿੵ
    A =
    a
    11
    a
    12
    … a
    1n
    a
    21
    a
    22
    … a
    2n
    ⋮ ⋮ ⋱ ⋮
    a
    m1
    a
    m2
    … a
    mn
    B =
    b
    11
    b
    12
    … b
    1l
    b
    21
    b
    22
    … b
    2l
    ⋮ ⋮ ⋱ ⋮
    b
    n1
    b
    n2
    … b
    nl
    ͷ݁Ռ͸ ܕߦྻʹͳΔ
    A × B (m, l)
    ܕߦྻ ͱɺ ܕߦྻ ʹ͍ͭͯɿ
    (m, n) A (n, l) B

    View full-size slide

  47. ߦྻͷܭࢉʢʣɿެࣜ
    w
    w
    w
    w
    w
    w
    A + B = B + A, A + O = O + A = A
    (A + B) + C = A + (B + C)
    A × E = E × A = A
    (A × B) × C = A × (B × C)
    (α + β)A = αA + βA, α(A + B) = αA + αBʢЋ Ќ͸࣮਺ʣ
    (A + B) × C = A × C + B × C

    View full-size slide

  48. O O
    (
    a b
    c d)
    ×
    (
    x
    y)
    +
    (
    t
    x
    t
    y)
    =
    (
    x′
    y′ )
    (
    ax + by
    cx + dy)
    +
    (
    t
    x
    t
    y)
    =
    (
    x′
    y′ )
    (
    ax + by + t
    x
    cx + dy + t
    y)
    =
    (
    x′
    y′ )
    P(x, y)
    P′ (x′ , y′ )

    View full-size slide

  49. O O
    a b t
    x
    c d t
    y
    0 0 1
    ×
    (
    x
    y
    1)
    =
    x′
    y′
    1
    ax + by + t
    x
    cx + dy + t
    y
    0x + 0y + 1
    =
    x′
    y′
    1
    P(x, y)
    P′ (x′ , y′ )

    View full-size slide

  50. ͳͥ࣍ਖ਼ํߦྻͰΞϑΟϯม׵Λදݱ͢Δʁ
    w ෳ਺ճͷΞϑΟϯม׵Λѻ͏ͨΊʹਖ਼ํߦྻͷํָ͕



    (
    x′
    y′ )
    =
    (
    a b
    c d)
    ×
    (
    x
    y)
    +
    (
    t
    x
    t
    y)
    ,
    (
    x′ ′
    y′ ′ )
    =
    (
    a′ b′
    c′ d′ )
    ×
    (
    x′
    y′ )
    +
    (
    t′
    x
    t′
    y)
    (
    x′ ′
    y′ ′ )
    =
    (
    a′ b′
    c′ d′ )
    ×
    ((
    a b
    c d)
    ×
    (
    x
    y)
    +
    (
    t
    x
    t
    y))
    +
    (
    t′
    x
    t′
    y)
    x′ ′
    y′ ′
    1
    =
    a′ b′ t′
    x
    c′ d′ t′
    y
    0 0 1
    ×
    a b t
    x
    c d t
    y
    0 0 1
    ×
    (
    x
    y
    1)
    x′ ′
    y′ ′
    1
    =
    a′ b′ t′
    x
    c′ d′ t′
    y
    0 0 1
    ×
    a b t
    x
    c d t
    y
    0 0 1
    ×
    (
    x
    y
    1)
    =
    a′ ′ b′ ′ t′ ′
    x
    c′ ′ d′ ′ t′ ′
    y
    0 0 1
    ×
    (
    x
    y
    1)

    View full-size slide

  51. ͳͥ࣍ਖ਼ํߦྻͰΞϑΟϯม׵Λදݱ͢Δʁ
    w ෳ਺ճͷΞϑΟϯม׵Λѻ͏ͨΊʹਖ਼ํߦྻͷํָ͕



    (
    x′
    y′ )
    =
    (
    a b
    c d)
    ×
    (
    x
    y)
    +
    (
    t
    x
    t
    y)
    ,
    (
    x′ ′
    y′ ′ )
    =
    (
    a′ b′
    c′ d′ )
    ×
    (
    x′
    y′ )
    +
    (
    t′
    x
    t′
    y)
    (
    x′ ′
    y′ ′ )
    =
    (
    a′ b′
    c′ d′ )
    ×
    ((
    a b
    c d)
    ×
    (
    x
    y)
    +
    (
    t
    x
    t
    y))
    +
    (
    t′
    x
    t′
    y)
    x′ ′
    y′ ′
    1
    =
    a′ b′ t′
    x
    c′ d′ t′
    y
    0 0 1
    ×
    a b t
    x
    c d t
    y
    0 0 1
    ×
    (
    x
    y
    1)
    x′ ′
    y′ ′
    1
    =
    a′ b′ t′
    x
    c′ d′ t′
    y
    0 0 1
    ×
    a b t
    x
    c d t
    y
    0 0 1
    ×
    (
    x
    y
    1)
    =
    a′ ′ b′ ′ t′ ′
    x
    c′ ′ d′ ′ t′ ′
    y
    0 0 1
    ×
    (
    x
    y
    1)
    CGAffineTransform
    ެࣜɿ(A × B) × C = A × (B × C)

    View full-size slide


  52. (A × B) × C = A × (B × C)
    A × B = B × A
    Ұൠతʹɺߦྻͷֻ͚ࢉʹަ׵๏ଇ͸੒ཱ͠ͳ͍ɻ

    View full-size slide

  53. A =
    a
    11
    a
    12
    … a
    1n
    a
    21
    a
    22
    … a
    2n
    ⋮ ⋮ ⋱ ⋮
    a
    n1
    a
    n2
    … a
    nn
    B =
    b
    11
    b
    12
    … b
    1n
    b
    21
    b
    22
    … b
    2n
    ⋮ ⋮ ⋱ ⋮
    b
    n1
    b
    n2
    … b
    nn

    ˞
    A × B =
    ∑n
    k=1
    a
    1k
    × b
    k1
    ∑n
    k=1
    a
    1k
    × b
    k2
    … ∑n
    k=1
    a
    1k
    × b
    kn
    ∑n
    k=1
    a
    2k
    × b
    k1
    ∑n
    k=1
    a
    2k
    × b
    k2
    … ∑n
    k=1
    a
    2k
    × b
    kn
    ⋮ ⋮ ⋱ ⋮
    ∑n
    k=1
    a
    nk
    × b
    k1
    ∑n
    k=1
    a
    nk
    × b
    k2
    … ∑n
    k=1
    a
    nk
    × b
    kn
    n

    k=1
    a
    1k
    × b
    k1
    = a
    11
    × b
    11
    + a
    12
    × b
    21
    + … + a
    1n
    × b
    n1
    ೋͭͷ ࣍ਖ਼ํߦྻ ɺ ʹ͍ͭͯɿ
    n A B

    View full-size slide

  54. A =
    a
    11
    a
    12
    … a
    1n
    a
    21
    a
    22
    … a
    2n
    ⋮ ⋮ ⋱ ⋮
    a
    n1
    a
    n2
    … a
    nn
    B =
    b
    11
    b
    12
    … b
    1n
    b
    21
    b
    22
    … b
    2n
    ⋮ ⋮ ⋱ ⋮
    b
    n1
    b
    n2
    … b
    nn

    ˞
    B × A =
    ∑n
    k=1
    b
    1k
    × a
    k1
    ∑n
    k=1
    b
    1k
    × a
    k2
    … ∑n
    k=1
    b
    1k
    × a
    kn
    ∑n
    k=1
    b
    2k
    × a
    k1
    ∑n
    k=1
    b
    2k
    × a
    k2
    … ∑n
    k=1
    b
    2k
    × a
    kn
    ⋮ ⋮ ⋱ ⋮
    ∑n
    k=1
    b
    nk
    × a
    k1
    ∑n
    k=1
    b
    nk
    × a
    k2
    … ∑n
    k=1
    b
    nk
    × a
    kn
    n

    k=1
    b
    1k
    × a
    k1
    = b
    11
    × a
    11
    + b
    12
    × a
    21
    + … + b
    1n
    × a
    n1
    ೋͭͷ ࣍ߦྻ ɺ ʹ͍ͭͯɿ
    n A B

    View full-size slide

  55. O
    3PUBUJPO4DBMF

    View full-size slide

  56. O
    3PUBUJPO4DBMF
    O

    View full-size slide

  57. O
    3PUBUJPO4DBMF
    O
    4DBMF

    View full-size slide

  58. O
    3PUBUJPO4DBMF
    O
    4DBMF3PUBUJPO
    w ߦྻͷֻ͚ࢉ͸ॱ൪ʹΑͬͯ݁Ռ͕ҧ͏
    w ΞϑΟϯม׵͸ॱ൪ʹΑͬͯ݁Ռ͕ҧ͏

    View full-size slide

  59. ૢ࡞ ༧૝ ࣮ࡍ
    transform
    .identity
    transform
    .identity
    .scaled
    transform
    .identity
    .scaled
    .rotated
    !

    View full-size slide

  60. ͳͥॻ͖ॱ௨Γͷม׵ʹͳ͍ͬͯͳ͍ͷʁ

    (
    x′
    y′ )
    =
    (
    a b
    c d)
    ×
    (
    x
    y)
    +
    (
    t
    x
    t
    y)
    ,
    (
    x′ ′
    y′ ′ )
    =
    (
    a′ b′
    c′ d′ )
    ×
    (
    x′
    y′ )
    +
    (
    t′
    x
    t′
    y)
    x′ ′
    y′ ′
    1
    =
    a′ b′ t′
    x
    c′ d′ t′
    y
    0 0 1
    ×
    a b t
    x
    c d t
    y
    0 0 1
    ×
    (
    x
    y
    1)
    ֻ͚ࢉͷॱ൪͸ɺ߹੒ॱͷٯʹ
    ͳΔඞཁ͕͋Δ͕ɺ΋͔ͯ͠͠
    $PSF(SBQIJDT͕͜͜Ͱ߹੒ॱ
    ௨ΓͰֻ͚ࢉͪ͠Όͬͨʂʁ

    View full-size slide

  61. ͳͥॻ͖ॱ௨Γͷม׵ʹͳ͍ͬͯͳ͍ͷʁ
    ಉ͡

    View full-size slide

  62. ͳͥॻ͖ॱ௨Γͷม׵ʹͳ͍ͬͯͳ͍ͷʁ
    ಉ͡
    ֻ͚ࢉͷॱ൪͸
    ߹ͬͯΔͬΆ͍"
    ͭ·Γඳը࣌ͷܭࢉ͕ؒҧͬͯ
    bͱcͷࢀর͕ٯͩͬͨʂʁ

    View full-size slide

  63. IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPODPSFHSBQIJDTDHBGpOFUSBOTGPSN

    View full-size slide

  64. ͳͥॻ͖ॱ௨Γͷม׵ʹͳ͍ͬͯͳ͍ͷʁ
    ͦ΋ͦ΋͜Ε·Ͱͷલఏࣗମ͕ؒҧͬͯͨ#

    x′ ′
    y′ ′
    1
    =
    a′ b′ t′
    x
    c′ d′ t′
    y
    0 0 1
    ×
    a b t
    x
    c d t
    y
    0 0 1
    ×
    (
    x
    y
    1)
    (x′ ′ y′ ′ 1) = (x y 1) ×
    a b 0
    c d 0
    t
    x
    t
    y
    1
    ×
    a′ b′ 0
    c′ d′ 0
    t′
    x
    t′
    y
    1
    ී௨ͷΞϑΟϯม׵ղઆͰ
    Α͘࢖ΘΕΔܭࢉࣜ
    ࣮ࡍͷ$PSF(SBQIJDTͰ
    ࢖ΘΕͯΔܭࢉࣜ

    View full-size slide

  65. ͳͥॻ͖ॱ௨Γͷม׵ʹͳ͍ͬͯͳ͍ͷʁ
    ͭ·Γ͜Ε͸࢓༷Ͱ͢ɻ

    View full-size slide

  66. ͳͥॻ͖ॱ௨Γͷม׵ʹͳ͍ͬͯͳ͍ͷʁ
    ͭ·Γ͜Ε͸࢓༷Ͱ͢ɻ
    ԾઆͰ͕͢ɺӳޠͷදݱͱͯ͠ɺ"FE#FEͷ઀ଓ͸ɺ
    ײ֮ͱͯ͠͸ʮઌʹ#͞Ε͔ͯΒ"͞Εͨʯ͔ͩΒɺ
    CGAffineTransformͷxxedܥϝιου͸׶͑ͯ
    ͜Μͳ෩ʹ࡞ΒΕ͍ͯΔͷͰ͸ͳ͍͔ͱߟ͍͑ͯ·͢ɻ

    View full-size slide

  67. ૢ࡞ ༧૝ ࣮ࡍ
    transform
    .identity
    transform
    .identity
    .scaled
    transform
    .identity
    .scaled
    .rotated
    !
    ͦ΋ͦ΋ӳޠͰ͸͜Ε͸
    ઌʹSPUBUFE͞Ε͔ͯΒ
    TDBMFE͞ΕΔײ͔֮ͩΒ
    ݁Ռ͸ݴޠײ֮ʹ߹க

    View full-size slide

  68. ͡Ό͋ॻ͖ॱ௨Γʹม׵͔ͨͬͨ͠Βʁ
    DPODBUFOBUJOHϝιουΛ࢖͑͹
    ͪΌΜͱ"ʷ#ͷॱ൪Ͱܭࢉͯ͠
    ͘ΕΔ$

    View full-size slide

  69. ͡Ό͋ॻ͖ॱ௨Γʹม׵͔ͨͬͨ͠Βʁ
    %

    View full-size slide

  70. ·ͱΊ
    w ΞϑΟϯม׵͸࠲ඪม׵ͷҰछ
    w ΞϑΟϯม׵ͷܭࢉ͸ߦྻͷԋࢉ
    w ߦྻͷԋࢉʢಛʹֻ͚ࢉʣ͸໘౗Ͱ͕͢೉͘͠͸ͳ͍
    w ߦྻͷֻ͚ࢉ͸ॱ൪ΛؾΛ͚ͭΔ΂͠
    w CGAffineTransformͷxxed"1*͕ॻ͖ॱͱٯͷ
    ॱ൪Ͱඳը͞ΕΔͷ͸࢓༷
    w ॻ͖ॱ௨Γͷඳը͕ཉ͔ͬͨ͠Βconcatenating
    Λ࢖͑͹͍͍

    View full-size slide

  71. ॓୊
    w CGAffineTransform.identityͱ͸ͲΜͳߦྻ͔ɺ
    ߟ͑ͯΈΑ͏ɻ
    w ͦͯ͠ɺԿނ
    ͷܭࢉࣜͩͱɺࠓͷಈ͖ʢbͱcͷ໾ׂ͕ٯͩͬͨΓɺ
    ߦྻͷֻ͚ࢉॱ൪͕߹੒ॱ൪ͱಉ͡ॱ൪ʹͳͬͨΓʣʹ
    ͳΔͷ͔ɺߟ͑ͯΈΑ͏ɻ
    (x′ ′ y′ ′ 1) = (x y 1) ×
    a b 0
    c d 0
    t
    x
    t
    y
    1
    ×
    a′ b′ 0
    c′ d′ 0
    t′
    x
    t′
    y
    1

    View full-size slide

  72. ࢀߟࢿྉ
    w ྫ୊ͱԋशͰϚελʔ͢Δઢܗ୅਺ɿ
    IUUQTXXXBNB[PODPKQEQ
    w $("⒏OF5SBOTGPSN࣮ફೖ໳ൃදεϥΠυɿ
    IUUQTTQFBLFSEFDLDPNMPWFFDHB⒏OFUSBOTGPSNTIJKJBOSVNFO
    w ߴ౳ֶߍ਺ֶ$ߦྻɿ
    IUUQTKBXJLJCPPLTPSHXJLJߴ౳ֶߍ਺ֶ$ߦྻ
    w ׬શʹཧղ͢ΔΞϑΟϯม׵ɿ
    IUUQTRJJUBDPNLPTIJBOJUFNTDFFDCCG
    w $("⒏OF5SBOTGPSNެࣜυΩϡϝϯτɿ
    IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPODPSFHSBQIJDT
    DHB⒏OFUSBOTGPSN

    View full-size slide