How to smoothly align rotated bitmaps side by side without jerkiness?
Asked Answered
D

5

5

My current program draw a rotated bitmap (64x64) and tile it on the screen by drawing it again but adding an offset based on the computed position of the bitmap top right corner (after rotation), it works fine but i experience some jerkiness of the grid in motion.

The jerkiness doesn't appear if i do the same thing with canvas transforms.

Here is an example which compare both : https://editor.p5js.org/onirom/sketches/A5D-0nxBp

Move mouse to the left part of the canvas for the custom rotation algorithm and to the right part for the canvas one.

It seems that some tile are misplaced by a single pixel which result in the grid jerkiness.

custom rotation algorithm grid jerkiness vs canvas rotation

Is there a way to remove the grid jerkiness without doing it as a single pass and keeping the same interpolation scheme ?

Is it a sub pixels correctness issue ?

Here is some code :

let tileImage = null
function preload() {
  tileImage = loadImage('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAMeHpUWHRSYXcgcHJvZmlsZSB0eXBlIGV4aWYAAHjarZhpktw6DoT/8xRzBO7LcbhGzA3m+PMBlKq77eeIN0tXuKSiKBIEkImEzf7XP4/5B38hhmhiKjW3nC1/scXmOzfV3r+h385G/da/+Dzi949x83ngGQpcw/3Z/DO+GefePb/bs4l7578LvTeuc5e+HvT+jI+f4+NZ0NdfF3osCO7ubNfzwrNQ8I9Fj+nzsSi3Wn4cbc1n5/gM1a9/MRSfU3Yl8h29LSU37qu3seDPJYaGottb8+70Dry/36kem/wOLli+Q3isDPLPh864fNtQjUxkQpcQ8p2CU8dbQokJLNzuwqfbjzO/++bLR3/4+zvHsmxy9s0J8+vKv+bN5879YfxJg0/Uan4ehJ9htflz/ctxl96F3gfhs4//vnOdn51/jK/y5L19ffQt3OesevTQnKLHjC/yc6j3KHrHvCFe1Lcyn2KzIWsrN/JpfKrtdpICy052HNw354n9cdEt191xW6/TTUyMfvvC1ftpfNDBSpCan2SE00SI7vgSWlihkh5TcygG/7HF6bZNt5uu2mXsckz1jsWcJtl/+TF/d+I5giXnbP34Cru8oAErrCP8cmEaEXHncWpSB7+fX/8kroEIJnVz5YDdDn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AgeG1wOkNyZWF0b3JUb29sPSJHSU1QIDIuMTAiPgogICA8eG1wTU06SGlzdG9yeT4KICAgIDxyZGY6U2VxPgogICAgIDxyZGY6bGkKICAgICAgc3RFdnQ6YWN0aW9uPSJzYXZlZCIKICAgICAgc3RFdnQ6Y2hhbmdlZD0iLyIKICAgICAgc3RFdnQ6aW5zdGFuY2VJRD0ieG1wLmlpZDplMGQ2NWZlOS1lMDQ1LTRhOGItYWZmZS0xZGRjMWI0M2Q3MTciCiAgICAgIHN0RXZ0OnNvZnR3YXJlQWdlbnQ9IkdpbXAgMi4xMCAoTGludXgpIgogICAgICBzdEV2dDp3aGVuPSIyMDIyLTEyLTA4VDIzOjQ0OjUxKzAxOjAwIi8+CiAgICA8L3JkZjpTZXE+CiAgIDwveG1wTU06SGlzdG9yeT4KICA8L3JkZjpEZXNjcmlwdGlvbj4KIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAKPD94cGFja2V0IGVuZD0idyI/PnF4ZZ8AAAAGYktHRAD/AP8A/6C9p5MAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfmDAgWLDOSx0KrAAAAGXRFWHRDb21tZW50AENyZWF0ZWQgd2l0aCBHSU1QV4EOFwAABDVJREFUeNrtmzFrFVEQhSeSwiIEIhJFEUUMQVERBFNYCGKhiJWllVjbCPojLGysLS2tREghgoVFBEFEEIkERRQNYiCksNPGr3jHPW/uJi8iZqZZdt/eve/tnDlzZu59YzevXvgZHbay+iNabGpye0RE7J2eiIiIew9fDXx++/qZiIh48vzjup6vdvTQzs55rl06HhERn5bXho5n3oU3nyMiYltscRs7dmS2EwFzh/cMHfjh62pERHz5PvyN794xMXC+f9fkwHjOQRIe4lzt5eJy07ytVghwCNgsU0T0tVF5vhDw28bxCG+W2NcYdRygsZ3dxzwOCfocxl88fbDzflifLOSygOOOQoDLs8rCsDOfc3Q2e2Cq8/qd+y8GPHF+btCzeBIjX6un3f1nT+3rnJfrb9+vDOiIQoDmfY0hz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)
  
  tileImage.loadPixels()
}

function computeRotatedPoint(c, s, x, y) {
  return { x: x * c - y * s, y: x * s + y * c }
}

currentTileWidth = 0
currentTileHeight = 0

// draw a rotated bitmap at screen position ox, oy
function drawRotatedBitmap(c, s, ox, oy) {
  let dcu = s
  let dcv = c
  let dru = dcv
  let drv = -dcu
  let su = (tileImage.width / 2.0) - (currentTileWidth_d2 * dcv + currentTileHeight_d2 * dcu)
  let sv = (tileImage.height / 2.0) - (currentTileWidth_d2 * drv + currentTileHeight_d2 * dru)
  let ru = su
  let rv = sv

  for (let y = 0; y < currentTileHeight; y += 1) {
    let u = ru
    let v = rv
    for (let x = 0; x < currentTileWidth; x += 1) {
      let ui = u
      let vi = v
      
      if (ui >= 0 && ui < tileImage.width) {
        let index1 = (floor(ui) + floor(vi) * tileImage.width) * 4
        let index2 = (x + ox + (y + oy) * width) * 4
        pixels[index2 + 0] = tileImage.pixels[index1 + 0]
        pixels[index2 + 1] = tileImage.pixels[index1 + 1]
        pixels[index2 + 2] = tileImage.pixels[index1 + 2]
      }
      
      u += dru
      v += drv
    }
    ru += dcu
    rv += dcv
  }
}

let angle = 0

function draw() {
  background(0)

  const s = sin(angle / 256 * PI * 2)
  const c = cos(angle / 256 * PI * 2)

  // compute rotated tile width / height
  let tw = tileImage.width
  let th = tileImage.height
  if (angle % 128 < 64) {
    currentTileWidth = abs(tw * c + th * s)
    currentTileHeight = abs(tw * s + th * c)
  } else {
    currentTileWidth = abs(tw * c - th * s)
    currentTileHeight = abs(tw * s - th * c)
  }

  currentTileWidth_d2 = (currentTileWidth / 2.0)
  currentTileHeight_d2 = (currentTileHeight / 2.0)
  
  // compute rotated point
  const rp = computeRotatedPoint(c, s, tw, 0)

  // draw tiles
  loadPixels()
  for (let i = -3; i <= 3; i += 1) {
    // compute center
    const cx = width / 2 - currentTileWidth_d2
    const cy = height / 2 - currentTileHeight_d2
    // compute tile position
    const ox = rp.x * i
    const oy = rp.y * i
    drawRotatedBitmap(c, s, round(cx + ox), round(cy + oy))
  }
  updatePixels()
  
  angle += 0.5
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.5.0/p5.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.5.0/addons/p5.sound.min.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">
    <meta charset="utf-8" />
  </head>
  <body>
    <main>
    </main>
  </body>
</html>
Djokjakarta answered 11/12, 2022 at 23:45 Comment(4)
we can only guess without seeing MCVE code ... my guess is that you accoumulate rounding errors along the way (up to one pixel per tile and axis) what you should do is to have the coordinates as floating point variable, compute all tiles rotated positions and only then round to integer coordinates. beware that could cause some minor artifacts on the tile edges (should be not visible unless you look for it)...Semifluid
i have added some code, tried to compute tiles rotated positions and then round but it is still jerky, it is either the whole grid (grid position) which is jerky or the tiles, this depend on how i do the rounding.Djokjakarta
I do not code in JS so I am not sure how the return is jandled but from mine C/C++ point of view this return { x: x * c - y * s, y: x * s + y * c } might be a problem so in case the x:,y: is conflicting the x,y you should use temp variable for the x if not then its OK as is. I would also try change this (floor(ui) + floor(vi) * tileImage.width) * 4 into (floor(ui+0.5) + floor(vi+0.5) * tileImage.width) * 4 or even better (round(ui) + round(vi) * tileImage.width) * 4 if it makes any difference other than these I do not see any obvious problemSemifluid
Try to cross compare with this Rotating a square TBitmap on its center which is the usual code for rotation of images I use (on pixel level)...Semifluid
D
4

I have found a solution which does not use the same algorithm but use the same interpolation scheme.

Solution with a three-shear method

This solution use a three-pass shear method and the solution to fix the tiles jerkiness is to add the tile offset before the rotation and then round coordinates once everything is ready to be drawn :

smooth three-shear rotation tiling

/**
 * Bitmap rotation + stable tiling with 3-shearing method
 * The 3-shearing method is stable between -PI / 2 and PI / 2 only, that is why a flip is needed for a full rotation
 *
 * https://www.ocf.berkeley.edu/~fricke/projects/israel/paeth/rotation_by_shearing.html
 */
let tex = null
let tile = []
function preload() {
  tile = loadImage('data:image/png;base64,iVBORw0KGgoA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CiAgIDwveG1wTU06SGlzdG9yeT4KICA8L3JkZjpEZXNjcmlwdGlvbj4KIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA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W1flZTLeyfbbi5DihEKA9N2Lb6QHNCjqeul5Z3/X2Rm0OMaUDNtoP+Fds1H2J4gB9o8qi2tPD3CqsVnPUENoL5DpZhBUfTKvKP5Vo914jOEznhbt0nkKA++DGlZOdnuNNav5Xw3Pc56pKkIRnFIHaxdWdHtzv1iKZj6OOLwQQO7wRF/PZvoGs7ueco8aqruyoQnV7fPT7qgLlHKShVGuHCAjgDbdWU+oJ2DpbhVWk4BnXaXI1hH5PN2/WX6gsAAJgZ1iY/OqMmOM+5wHtEjtEaJbRvK77F521erwQoAhQdndVmyo/p/R4HrEKZ7idpGSFTNu7DhRsrr1H17fQjlNVg1oNZtnA7eXN6m+39vi3q7/igKwabN2bM6q6Xp+70f8TuPHVEXIIoOpz9XxmsL7T6tr3Vx2QrT26bKP/GtNaQles1G7dfVoIiIgYd3W9ru+rh/AE+oCjruBo/gYBenRdaIcE17niedqHqCzQtyOkHnHr+lpvOzbXzk4rtzhE6P8PtSZRhPG9VdEWAvr+h1fvdxodJKgn3W7y7HsoAlSBuue68YWAjAP6GiytypI3rzHZ17SnqL29iOkmTlH9sOUR8AvuXvZlpzhIWwAAAABJRU5ErkJggg==')

}

function setup() {
  createCanvas(512, 512)
  
  frameRate(12)
}

function computeRotatedPoint(c, s, x, y) {
  return { x: x * c - y * s, y: x * s + y * c }
}

function _shearX(t, x, y) {
  return x - y * t
}

function _shearY(s, x, y) {
  return x * s + y
}

currentTileWidth = 0
currentTileHeight = 0

currentTileLookupFunction = tileLookup1

// regular lookup
function tileLookup1(x, y) {
  return (x + y * tile.width) * 4
}

// flipped lookup
function tileLookup2(x, y) {
  return ((tile.width - 1 - x) + (tile.height - 1 - y) * tile.width) * 4
}

// draw a rotated bitmap at offset ox,oy with cx,cy as center of rotation offset
function drawRotatedBitmap(c, s, t, ox, oy, cx, cy) {
  for (let ty = 0; ty < tile.height; ty += 1) {
    for (let tx = 0; tx < tile.width; tx += 1) {
      // center of rotation
      let scx = tile.width - tx - tile.width / 2
      let scy = tile.height - ty - tile.height / 2
      
      // this is key to a stable rotation without any jerkiness
      scx += cx
      scy += cy
      
      // shear
      let ux = round(_shearX(t, scx, scy))
      let uy = round(_shearY(s, ux, scy))
      ux = round(_shearX(t, ux, uy))
      
      // translate again
      ux = currentTileWidth_d2 - ux
      uy = currentTileHeight_d2 - uy

      // plot with offset
      let index1 = currentTileLookupFunction(tx, ty)
      let index2 = (ox + ux + (oy + uy) * width) * 4

      pixels[index2 + 0] = tile.pixels[index1 + 0]
      pixels[index2 + 1] = tile.pixels[index1 + 1]
      pixels[index2 + 2] = tile.pixels[index1 + 2]
    }
  }
}

let angle = -3.141592653 / 2
function draw() {
  const s = sin(angle)
  const c = cos(angle)
  const t = tan(angle / 2)

  tile.loadPixels()

  background(0)

  // compute rotated tile width / height
  let tw = tile.width
  let th = tile.height

  currentTileWidth = abs(tw * c + th * s)
  currentTileHeight = abs(tw * s + th * c)

  currentTileWidth_d2 = round(currentTileWidth / 2.0)
  currentTileHeight_d2 = round(currentTileHeight / 2.0)

  // draw tiles
  loadPixels()
  for (let j = -2; j <= 2; j += 1) {
    for (let i = -2; i <= 2; i += 1) {
      let ox = round(width / 2 - currentTileWidth_d2)
      let oy = round(height / 2 - currentTileHeight_d2)
      drawRotatedBitmap(c, s, t, ox, oy, i * tw, j * tw)
    }
  }
  updatePixels()
  
  angle += 0.025
  if (angle >= PI / 2) {
    angle -= PI
    
    if (currentTileLookupFunction === tileLookup2) {
      currentTileLookupFunction = tileLookup1
    } else {
      currentTileLookupFunction = tileLookup2
    }
  }
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.5.0/p5.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.5.0/addons/p5.sound.min.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">
    <meta charset="utf-8" />
  </head>
  <body>
    <main>
    </main>
  </body>
</html>

I cannot say technically why it works but it is probably related to an error accumulation issue / rounding since i can reproduce the question issue completely with the three-shear method if i add the tile offset after rotation and round the offset and shear pass independently such as :

function drawRotatedBitmap(c, s, t, ox, oy, cx, cy) {
  cx = round(_shearX(t, cx, cy))
  cy = round(_shearY(s, cx, cy))
  cx = round(_shearX(t, cx, cy))
  for (let ty = 0; ty < tex.height; ty += 1) {
    ...
    let ux = round(_shearX(t, scx, scy))
    let uy = round(_shearY(s, ux, scy))
    ux = round(_shearX(t, ux, uy))
    ...
    let index2 = (cx + ux + ox + (cy + uy + oy) * width) * 4
    ...
  }
}

three-shear rotation tiling with tiles jerkiness


The issue become clearly visible if i round the offset and the shearing result at the same time which result in missing pixels in the final image such as :

function drawRotatedBitmap(c, s, t, ox, oy, cx, cy) {
  cx = _shearX(t, cx, cy)
  cy = _shearY(s, cx, cy)
  cx = _shearX(t, cx, cy)
  for (let ty = 0; ty < tex.height; ty += 1) {
    ...
    let ux = _shearX(t, scx, scy)
    let uy = _shearY(s, ux, scy)
    ux = _shearX(t, ux, uy)
    ...
    let index2 = (round(cx + ux) + ox + (round(cy + uy) + oy) * width) * 4
    ...
  }
}

three-shear rotation tiling with holes


I would still like a detailed explanation of the jerkiness behavior and to know if there is a smooth solution by adding the tile offset after the rotation, it seems that the jiggling is due to the center of rotation being off one or two pixels depending on the angle.

Djokjakarta answered 19/12, 2022 at 22:7 Comment(0)
E
3

This is definitely a pixelization problem. Analytically (vectorial) one can't explain the jiggling. It can be minimized, e.g. by rotating around the center of the whole image the successive pixels of a line and so forth line-by-line of the whole image, but the jiggling cannot be cancelled. Ultimately, this corresponds to creating an image object and rotating it around its center!

Ernie answered 20/12, 2022 at 10:40 Comment(7)
thanks, it makes sense that it is due to the center of rotation ending up between two coordinates, should i detect whether width/height is even before applying the fix ?Djokjakarta
With the algorithm of the first post this doesn't work. I have found an article which explain the issue and has some hints as to how to fix it (it seems related to your second solution) but it is still somewhat confusing to me, i still don't get what do they means by "rearranging the tiles so that the reference point is not off center"Djokjakarta
I'm confused too! Have you coded off-center rotations or not? I always thought they were rotations around the center of the tiles.Ernie
Yes off-center rotation is exactly how I tile the plane right now in all examples, i also tried computing every times the tile anchor by calling computeRotatedPoint function but this also produce wobbly tiles on motion.Djokjakarta
The problem resides in the fact that there is only one constraint between neighboring tiles, i.e. the distance between the top left corners is the only constant. Since we rotate and translate the tiles individually we can't avoid having overlaps and dislocations (shearings). This is obvious if you compare the canvas animation with any of the other animations. In these latter the jiggling exists for all the pixels including the inside ones, while the canvas animation is smooth. For information, the smooth rendering resides in OpenGL or WebGL.Ernie
Continued. How can we tied the tiles? I suggested to create an object , that's what @George Profenza implicitly suggested too, but apparently you're looking for a custom algorithm. Let's go for the challenge!Ernie
Here's a possible explanation to the jiggling effect. Normally with the loadPixels() and updatePixels() instructions no jerking should be apparent as long as the frame refresh period is greater than the draw function execution time. If one set the frameRate to 1 or 2, no jiggling is noticeable. The higher the frameRate, the more the jiggling. That means the draw function run-time is too high and that function is interrupted by the frame refresh thread. So the draw function must be optimized (time-wise) to the maximum extent.Ernie
R
1

Is there a way to remove the grid jerkiness without doing it as a single pass and keeping the same interpolation scheme ?

No

Is it a sub pixels correctness issue ?

No, it is an interpolation issue

Rew answered 18/12, 2022 at 8:11 Comment(1)
Could you provide more details about the interpolation issue ?Djokjakarta
E
1

The frameCount is a function of the frameRate (which is not a constant contrary to what we think even if we set it), the execution time of the cycling draw function and the runtime environment (canvas or the gif one). It seems that for the gif the frameCount is reset to zero after a certain cumulated count, which corresponds to a reset to the vertical position of the image.
I tried to reproduce the "jerking effect" by changing the 64 parameter in the following instruction and the frameRate, without success.

if (frameCount % 128 < 64) {

I suggest to make the rotation speed independent of the frameCount.

Ernie answered 19/12, 2022 at 17:29 Comment(1)
The gif doesn't loop entirely, that is why it reset. I have edited the code to use an arbitrary angle increment instead of relying on frameCount. The jerkiness can be seen on tiles of the grid which are jiggling back and forth at one or two pixel offset depending on the angle.Djokjakarta
R
1

FWIW the WEBGL canvas will be a bit faster in getting a result your code already hints at using image() and because you're using power of 2 dimensions you could also make use of textureWrap():

// this variable will hold our shader object
let bricks;

function preload() {
  bricks = loadImage(
    "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAMeHpUWHRSYXcgcHJvZmlsZSB0eXBlIGV4aWYAAHjarZhpktw6DoT/8xRzBO7LcbhGzA3m+PMBlKq77eeIN0tXuKSiKBIEkImEzf7XP4/5B38hhmhiKjW3nC1/scXmOzfV3r+h385G/da/+Dzi949x83ngGQpcw/3Z/DO+GefePb/bs4l7578LvTeuc5e+HvT+jI+f4+NZ0NdfF3osCO7ubNfzwrNQ8I9Fj+nzsSi3Wn4cbc1n5/gM1a9/MRSfU3Yl8h29LSU37qu3seDPJYaGottb8+70Dry/36kem/wOLli+Q3isDPLPh864fNtQjUxkQpcQ8p2CU8dbQokJLNzuwqfbjzO/++bLR3/4+zvHsmxy9s0J8+vKv+bN5879YfxJg0/Uan4ehJ9htflz/ctxl96F3gfhs4//vnOdn51/jK/y5L19ffQt3OesevTQnKLHjC/yc6j3KHrHvCFe1Lcyn2KzIWsrN/JpfKrtdpICy052HNw354n9cdEt191xW6/TTUyMfvvC1ftpfNDBSpCan2SE00SI7vgSWlihkh5TcygG/7HF6bZNt5uu2mXsckz1jsWcJtl/+TF/d+I5giXnbP34Cru8oAErrCP8cmEaEXHncWpSB7+fX/8kroEIJnVz5YDdDnOXGMl9JVfQQAcmJq4Xe66sZwFcxNYJY1wgAja7kFzGouJ9cQ5HVgLUMd2H6AcRcCn5hZE+hpAJDuhgb94pTqf65O8wrArVAtMcCrFpoROsGBP5U2Ilh3oKKaaUciqpppZ6DlmQl3PJQs+9hBJLKrmUUk1ppddQY00111JrbbU33wL0nRo4bbW11jubdlbuvN2Z0PvwI4w40sijjDqaGX2SPjPONPMss842+/IrLAC+8iqrrrb6dptU2nGnnXfZdbfdD6l2woknnXyKOfW00z9Re8L62+c/iJp7ouY1UjKxfKLGaCnvEk7oJEnMiJiPjoAXokbESGyJma0uRi+Rk5hRj0BF8hiZJ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3aGVuPSIyMDIyLTEyLTA4VDIzOjQ0OjUxKzAxOjAwIi8+CiAgICA8L3JkZjpTZXE+CiAgIDwveG1wTU06SGlzdG9yeT4KICA8L3JkZjpEZXNjcmlwdGlvbj4KIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAKPD94cGFja2V0IGVuZD0idyI/PnF4ZZ8AAAAGYktHRAD/AP8A/6C9p5MAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfmDAgWLDOSx0KrAAAAGXRFWHRDb21tZW50AENyZWF0ZWQgd2l0aCBHSU1QV4EOFwAABDVJREFUeNrtmzFrFVEQhSeSwiIEIhJFEUUMQVERBFNYCGKhiJWllVjbCPojLGysLS2tREghgoVFBEFEEIkERRQNYiCksNPGr3jHPW/uJi8iZqZZdt/eve/tnDlzZu59YzevXvgZHbay+iNabGpye0RE7J2eiIiIew9fDXx++/qZiIh48vzjup6vdvTQzs55rl06HhERn5bXho5n3oU3nyMiYltscRs7dmS2EwFzh/cMHfjh62pERHz5PvyN794xMXC+f9fkwHjOQRIe4lzt5eJy07ytVghwCNgsU0T0tVF5vhDw28bxCG+W2NcYdRygsZ3dxzwOCfocxl88fbDzflifLOSygOOOQoDLs8rCsDOfc3Q2e2Cq8/qd+y8GPHF+btCzeBIjX6un3f1nT+3rnJfrb9+vDOiIQoDmfY0hzcuv330bmqcx7sMun5uJiIgTM9MRETG/sNb5fOZXpTi/sNSJGMcJTk+ABDioEOA0vfO044ZMyRF7LsadlgeZ3AcSVKm2KkkMJBYCsiqv1dPu3LF1Vq05HaHX0Q2uusyuFwLIxyurkwOeUmWVxVhrDDp90LfK5HNVlhki4KLqBygH8EbUk6r4WmMZ7Q3bqgfUHj1b2lC1p+O0puB3qD6pfkBrP0Crxv/FigNcp0bZta/nWzs/60XUqBBZCKC6gt2zPK324PHiQBbR5/XVAZotYG2eXxywWRyA4tNqLEMGdT4eylZ8XJWZKUytCltjP+OKQkCm3UGEeo5xIEC1PJ7CAyhC7TtoreFMkTaqLFEI0BjkDbu1QVcjZHmeHqAa84AAagjV9HSTN6o7CgEOAcq2rabr/qzgaHfW1flZTLeyfbbi5DihEKA9N2Lb6QHNCjqeul5Z3/X2Rm0OMaUDNtoP+Fds1H2J4gB9o8qi2tPD3CqsVnPUENoL5DpZhBUfTKvKP5Vo914jOEznhbt0nkKA++DGlZOdnuNNav5Xw3Pc56pKkIRnFIHaxdWdHtzv1iKZj6OOLwQQO7wRF/PZvoGs7ueco8aqruyoQnV7fPT7qgLlHKShVGuHCAjgDbdWU+oJ2DpbhVWk4BnXaXI1hH5PN2/WX6gsAAJgZ1iY/OqMmOM+5wHtEjtEaJbRvK77F521erwQoAhQdndVmyo/p/R4HrEKZ7idpGSFTNu7DhRsrr1H17fQjlNVg1oNZtnA7eXN6m+39vi3q7/igKwabN2bM6q6Xp+70f8TuPHVEXIIoOpz9XxmsL7T6tr3Vx2QrT26bKP/GtNaQles1G7dfVoIiIgYd3W9ru+rh/AE+oCjruBo/gYBenRdaIcE17niedqHqCzQtyOkHnHr+lpvOzbXzk4rtzhE6P8PtSZRhPG9VdEWAvr+h1fvdxodJKgn3W7y7HsoAlSBuue68YWAjAP6GiytypI3rzHZ17SnqL29iOkmTlH9sOUR8AvuXvZlpzhIWwAAAABJRU5ErkJggg=="
  );
}

function setup() {
  // use WEBGL renderer, 
  createCanvas(512, 512, WEBGL);
  // if helps the sketch dimensions are a power of 2 so textureWrap() can be used
  textureWrap(REPEAT);
  
  noStroke();
  
}

function draw() {
  background(0);
  
  // full 7 block width and height
  const w = 64 * 7;
  const h = 64;
  // half the dimensions to rotate from center
  const hw = int(w / 2);
  const hh = int(h / 2);
  
  rotate(frameCount * 0.03);
  
  texture(bricks);
  // vertex( x, y, u, v ) (by default u,v are in pixel coordinates)
  // otherwise use textMode(NORMAL); in setup()
  beginShape();
  vertex(-hw, -hh, -hw, -hh); //TL
  vertex(+hw, -hh, +hw, -hh); //TR
  vertex(+hw, +hh, +hw, +hh); //BR
  vertex(-hw, +hh, -hw, +hh); //BL
  endShape();   
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.5.0/p5.min.js"></script>

An overcomplicated version of the above is to use a shader for rotation which can produce interesting results: shader rotating a 64x64 texture individually, rendered as a 7x1 rectangle with repeating tiles, each tile with individual rotation. When the buffer isn't cleared rendering a radiadial symmetry pattern as each tile rotates.

It seems you're more interested in working out a custom rotation algorithms that produces less artefacts.

If so, you might also want to look at a RotSprite. Doing a quick search I see implementations such as this shader one or this js one.

Roxannaroxanne answered 23/12, 2022 at 21:13 Comment(4)
I am more interested in a custom rotation algorithm which can be used to tile the plane the same way as the question example, ideally by tiling after rotation, for performance reasons on special hardware.Djokjakarta
I had a hunch it's the custom rotation algorithm you're after. Out of curiosity, what special hardware do you plan on using this ? (I'm guessing p5 is used then just to prototype / easily share running snippets, but the final impementation might be ported to something else?). The Pixel Art scaling algorithms article has a few more algoriths listed and although slightly different from your rotation I found these SEGA workarounds fascinating. HTHRoxannaroxanne
@ВадимКузьмин I don't know the answer. Having a quick look at the Tab source code and ControllerGroup I don't see any option to supply PImage instances. Feel free to check out the controlp5 source code/documentation yourself as well. It might be that a tab with image doesn't exist and you'd need to either extend Tab or make your own image based tab without controlP5. That's your decisionRoxannaroxanne
Great youtube channel although it is not much related to the issue, target hardware is ones with fast memory copy eg. old ARM with blocks copy instructions. My current method that alleviate the jiggling issue of the thread algorithm is to adjust tiles offset manually on a per angle basis via a table of x,y offset.Djokjakarta

© 2022 - 2024 — McMap. All rights reserved.