rotating a 100*100 grid/array/matrix

Anyone have an idea how to do this?

Have a 100*100 grid where the user can draw in an image of black pixels (so can be 1s or 0s). Was going to feed this into an array

I have to then rotate this around (the info in the array), but with many degrees of freedom not just 90 deg shifts



anyone have an idea??

Comments

  • : Anyone have an idea how to do this?
    :
    : Have a 100*100 grid where the user can draw in an image of black
    : pixels (so can be 1s or 0s). Was going to feed this into an array
    :
    : I have to then rotate this around (the info in the array), but with
    : many degrees of freedom not just 90 deg shifts
    :
    :
    :
    : anyone have an idea??
    :

    The biggest problem with rotation around a point (x,y) with an angle t is that you are working with pixels rather than a continuum. It's easy to calculate where in the continuum a pixel would end up, but it's not possible to put a pixel in a pixel. You'll need to 'smear' each pixel out over multiple destination pixels (atleast, that's one approach).
    Basically, what you do is consider the pixel as a square in the continuum, then rotate it around (x,y) with angle t. It'll come out the same pixel only then itself also turned over the angle t. Then, you'll need to 'pixelize' the angled square. For instance, you could say the turned pixel affects the destination pixels equal to the amount of how much of the turned pixel is contained within the destination pixel.
    I've created a MS Paint illustrative picture, and attached it to this post.
    The left side shows what happens to a pixel when it is rotated in the continuum (actually I drew it wrong, but you get the idea: the square itself rotates). The left shows what I mean by 'smearing' each rotated pixel over the destination pixels. The grid shows the destination pixels and the red shows how the converted pixel would look when it is rotated in the continuum (actually, here too I drew it wrong, and also the red pixel is way too big, because it should actually be the same size as the raster, but the point, I hope, is clear). The numbers there are the percentages at which the rotated pixel affects the final color of the destination pixel. It's equal to the percentage of overlap. So in the centers, we get a 100% influence, but at the edges only around 10%.
    The idea is to do this for each pixel and remember the influences. Then, when all these influences are calculated, each destination pixel will have a collection of influences. Then you arithmatically balance these influences to determine the final color:
    If 70% influence from a red pixel, and also 15% from a blue, the final pixel should be such that the red pixel has more effect on the color, thus more red than blue. More exactly: 70/85 part red, 15/85 part blue. Then you turn this into an RGB color for the pixel (this is all pretty sketchy still; if you want I could help you with how to precisely implement this).
    Note that it's also possible that a pixel has no influences, which means the rotation 'frees up' the pixel (or: when rotating, this pixel is placed somewhere else but no other pixel comes on this spot). You'll need to give these pixels the standard background color.

    Also, when using a 100*100 pixel picture, the rotated picture can take up as much as 100 * Sqrt(2) ( = Sqrt(100
  • : : Anyone have an idea how to do this?
    : :
    : : Have a 100*100 grid where the user can draw in an image of black
    : : pixels (so can be 1s or 0s). Was going to feed this into an array
    : :
    : : I have to then rotate this around (the info in the array), but with
    : : many degrees of freedom not just 90 deg shifts
    : :
    : :
    : :
    : : anyone have an idea??
    : :
    :
    : The biggest problem with rotation around a point (x,y) with an angle
    : t is that you are working with pixels rather than a continuum. It's
    : easy to calculate where in the continuum a pixel would end up, but
    : it's not possible to put a pixel in a pixel. You'll need to 'smear'
    : each pixel out over multiple destination pixels (atleast, that's one
    : approach).
    : Basically, what you do is consider the pixel as a square in the
    : continuum, then rotate it around (x,y) with angle t. It'll come out
    : the same pixel only then itself also turned over the angle t. Then,
    : you'll need to 'pixelize' the angled square. For instance, you could
    : say the turned pixel affects the destination pixels equal to the
    : amount of how much of the turned pixel is contained within the
    : destination pixel.
    : I've created a MS Paint illustrative picture, and attached it to
    : this post.
    : The left side shows what happens to a pixel when it is rotated in
    : the continuum (actually I drew it wrong, but you get the idea: the
    : square itself rotates). The left shows what I mean by 'smearing'
    : each rotated pixel over the destination pixels. The grid shows the
    : destination pixels and the red shows how the converted pixel would
    : look when it is rotated in the continuum (actually, here too I drew
    : it wrong, and also the red pixel is way too big, because it should
    : actually be the same size as the raster, but the point, I hope, is
    : clear). The numbers there are the percentages at which the rotated
    : pixel affects the final color of the destination pixel. It's equal
    : to the percentage of overlap. So in the centers, we get a 100%
    : influence, but at the edges only around 10%.
    : The idea is to do this for each pixel and remember the influences.
    : Then, when all these influences are calculated, each destination
    : pixel will have a collection of influences. Then you arithmatically
    : balance these influences to determine the final color:
    : If 70% influence from a red pixel, and also 15% from a blue, the
    : final pixel should be such that the red pixel has more effect on the
    : color, thus more red than blue. More exactly: 70/85 part red, 15/85
    : part blue. Then you turn this into an RGB color for the pixel (this
    : is all pretty sketchy still; if you want I could help you with how
    : to precisely implement this).
    : Note that it's also possible that a pixel has no influences, which
    : means the rotation 'frees up' the pixel (or: when rotating, this
    : pixel is placed somewhere else but no other pixel comes on this
    : spot). You'll need to give these pixels the standard background
    : color.
    :
    : Also, when using a 100*100 pixel picture, the rotated picture can
    : take up as much as 100 * Sqrt(2) ( = Sqrt(100
  • : : : Anyone have an idea how to do this?
    : : :
    : : : Have a 100*100 grid where the user can draw in an image of black
    : : : pixels (so can be 1s or 0s). Was going to feed this into an array
    : : :
    : : : I have to then rotate this around (the info in the array), but with
    : : : many degrees of freedom not just 90 deg shifts
    : : :
    : : :
    : : :
    : : : anyone have an idea??
    : : :
    : :
    : : The biggest problem with rotation around a point (x,y) with an angle
    : : t is that you are working with pixels rather than a continuum. It's
    : : easy to calculate where in the continuum a pixel would end up, but
    : : it's not possible to put a pixel in a pixel. You'll need to 'smear'
    : : each pixel out over multiple destination pixels (atleast, that's one
    : : approach).
    : : Basically, what you do is consider the pixel as a square in the
    : : continuum, then rotate it around (x,y) with angle t. It'll come out
    : : the same pixel only then itself also turned over the angle t. Then,
    : : you'll need to 'pixelize' the angled square. For instance, you could
    : : say the turned pixel affects the destination pixels equal to the
    : : amount of how much of the turned pixel is contained within the
    : : destination pixel.
    : : I've created a MS Paint illustrative picture, and attached it to
    : : this post.
    : : The left side shows what happens to a pixel when it is rotated in
    : : the continuum (actually I drew it wrong, but you get the idea: the
    : : square itself rotates). The left shows what I mean by 'smearing'
    : : each rotated pixel over the destination pixels. The grid shows the
    : : destination pixels and the red shows how the converted pixel would
    : : look when it is rotated in the continuum (actually, here too I drew
    : : it wrong, and also the red pixel is way too big, because it should
    : : actually be the same size as the raster, but the point, I hope, is
    : : clear). The numbers there are the percentages at which the rotated
    : : pixel affects the final color of the destination pixel. It's equal
    : : to the percentage of overlap. So in the centers, we get a 100%
    : : influence, but at the edges only around 10%.
    : : The idea is to do this for each pixel and remember the influences.
    : : Then, when all these influences are calculated, each destination
    : : pixel will have a collection of influences. Then you arithmatically
    : : balance these influences to determine the final color:
    : : If 70% influence from a red pixel, and also 15% from a blue, the
    : : final pixel should be such that the red pixel has more effect on the
    : : color, thus more red than blue. More exactly: 70/85 part red, 15/85
    : : part blue. Then you turn this into an RGB color for the pixel (this
    : : is all pretty sketchy still; if you want I could help you with how
    : : to precisely implement this).
    : : Note that it's also possible that a pixel has no influences, which
    : : means the rotation 'frees up' the pixel (or: when rotating, this
    : : pixel is placed somewhere else but no other pixel comes on this
    : : spot). You'll need to give these pixels the standard background
    : : color.
    : :
    : : Also, when using a 100*100 pixel picture, the rotated picture can
    : : take up as much as 100 * Sqrt(2) ( = Sqrt(100
  • : That's also very possible, but I couldn't directly think of a way to
    : make sure every pixel has a place, and for small resolutions (like
    : 100*100 or less) every pixel lost matters.
    : But you could surely try it, and if it works out well enough then
    : you don't have to get it complicated.
    : In that case, I suggest you take the center, calculate it's new
    : position and check in which pixel it ends up.
    : The problem I had with this is that two different pixels could end
    : up at the same spot and overwrite eachother. An easier fix than the
    : long-story-idea would be to also here average the pixels.
    :
    : I guess it all depends on the precision you need from it. Neither
    : solution is perfect, and probably each solution has pictures that
    : work well on that one but not on the other, but also pictures that
    : work better on the other.
    :
    : Best Regards,
    : Richard
    :
    : The way I see it... Well, it's all pretty blurry


    I almost got something!!!

    I got the rotating experiment down, so i can now rotate it later on using the bit of script.. just that!! I dont know how to save the pixels into an array!!! Arg!!!!



    [color=Red][b]

    'A very simple sketchpad

    Private Sub Form_Load()
    'Redraws the image when the window is covered/uncovered
    picCanvas.AutoRedraw = True

    'The canvas look and drawing behaviour
    picCanvas.DrawWidth = 2 'Lines are 2 units thick
    picCanvas.ForeColor = vbBlue 'Lines are blue
    picCanvas.BackColor = vbWhite 'Background canvas is white
    Dim MatrixN(3000, 3000) As Integer

    End Sub

    Private Sub picCanvas_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
    picCanvas.PSet (X, Y)


    Dim A As Integer
    Dim B As Integer
    Dim C As Integer
    Dim D As Integer
    Let C = 180 / (180 / 3.14159)

    A = ((X - 1507) * Cos(C)) - ((Y - 1507) * Sin(C))
    B = ((X - 1507) * Sin(C)) + ((Y - 1507) * Cos(C))
    picCanvas.PSet (A + 1507, B + 1507)
    [color=Blue]
    I guess i want the array input here (like Let Matrix(X,Y)=1) while its in the mouse-held-down loop... But i cant keep the data or it wont even let me call the function!! *cry*[/color] Let D = D + 2
    End If
    Debug.Print D
    End Sub[/b][/color]


    sorry to just chuck a bunch of code in here

    I just realised the grid is waaaaaay too big. I need maybe 100*100 at most lol, i can rescale but then its impossible to draw xD any scaling routines so i can have a big pixellated area to input in the values for an array?
  • :
    : I almost got something!!!
    :
    : I got the rotating experiment down, so i can now rotate it later on
    : using the bit of script.. just that!! I dont know how to save the
    : pixels into an array!!! Arg!!!!
    :
    :
    :
    : [color=Red][b]
    :
    : 'A very simple sketchpad
    :
    : Private Sub Form_Load()
    : 'Redraws the image when the window is covered/uncovered
    : picCanvas.AutoRedraw = True
    :
    : 'The canvas look and drawing behaviour
    : picCanvas.DrawWidth = 2 'Lines are 2 units thick
    : picCanvas.ForeColor = vbBlue 'Lines are blue
    : picCanvas.BackColor = vbWhite 'Background canvas is white
    : Dim MatrixN(3000, 3000) As Integer
    :
    : End Sub
    :
    : Private Sub picCanvas_MouseMove(Button As Integer, Shift As Integer,
    : X As Single, Y As Single)
    : If Button = 1 Then
    : picCanvas.PSet (X, Y)
    :
    :
    : Dim A As Integer
    : Dim B As Integer
    : Dim C As Integer
    : Dim D As Integer
    : Let C = 180 / (180 / 3.14159)
    :
    : A = ((X - 1507) * Cos(C)) - ((Y - 1507) * Sin(C))
    : B = ((X - 1507) * Sin(C)) + ((Y - 1507) * Cos(C))
    : picCanvas.PSet (A + 1507, B + 1507)
    : [color=Blue]
    : I guess i want the array input here (like Let Matrix(X,Y)=1) while
    : its in the mouse-held-down loop... But i cant keep the data or it
    : wont even let me call the function!! *cry*[/color] Let D = D +
    : 2
    : End If
    : Debug.Print D
    : End Sub[/b][/color]
    :
    :
    : sorry to just chuck a bunch of code in here
    :
    : I just realised the grid is waaaaaay too big. I need maybe 100*100
    : at most lol, i can rescale but then its impossible to draw xD any
    : scaling routines so i can have a big pixellated area to input in the
    : values for an array?


    What you need to do is declare the variable outside the functions to make it a member variable of the form. That way, you can call it from any function and it's value will be preserved between function calls.
    Also, for testing purposes, you might want to put the rotation code under a button rather than a mouse move. This will make it easier to test.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories