473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Matrix translation

I have a 512x512 matrix.
I need a rutine that give me a transformed matrix from the curent one, with
a given point in the middle of the matrix, I mean 256x256.

Any thoughts?

Crirus
Nov 20 '05 #1
10 2219
"Crirus" <Cr****@datagroup.ro> scripsit:
I have a 512x512 matrix.
I need a rutine that give me a transformed matrix from the curent one, with
a given point in the middle of the matrix, I mean 256x256.


Do you use the 'System.Drawing.Drawing2D.Matrix' class?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
Nope, I mean a 256 x 256 array of values..not a matrix like that
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bl************@ID-208219.news.uni-berlin.de...
"Crirus" <Cr****@datagroup.ro> scripsit:
I have a 512x512 matrix.
I need a rutine that give me a transformed matrix from the curent one, with a given point in the middle of the matrix, I mean 256x256.


Do you use the 'System.Drawing.Drawing2D.Matrix' class?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Nov 20 '05 #3
OK, let me understand you correctly please.

You start with

Dim yourArray( 512,512) as Point

'and end up with

Dim transformedArray( 256,256) as Point

And you say that you want a point at the centre ?

My Questions

1.) What transformation is taking/supposed to place? and are you asking how
to acheive this ?

2.) With an even numbered x,y lengths you cannot acheive true centre, you
would need 257 or 255 ( with a centre of 229 or 228 ).

Please clarify
OHM


Crirus wrote:
Nope, I mean a 256 x 256 array of values..not a matrix like that
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bl************@ID-208219.news.uni-berlin.de...
"Crirus" <Cr****@datagroup.ro> scripsit:
I have a 512x512 matrix.
I need a rutine that give me a transformed matrix from the curent
one, with a given point in the middle of the matrix, I mean 256x256.


Do you use the 'System.Drawing.Drawing2D.Matrix' class?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Nov 20 '05 #4
Ok, few mistakes...
The array is one and only 512 x512 starting from 0 so tere are 513 elements
on each dimension
I need another 512x512 array with a specified element in the 128x128
position

like this:

suppose (x,y) is the element at x,y position in the array

First 5x5 array()

(0,0)(1,0)(2,0)(3,0)(4,0)
(0,1)(1,1)(2,1)(3,1)(4,1)
(0,2)(1,2)(2,2)(3,2)(4,2)
(0,3)(1,3)(2,3)(3,3)(4,3)
(0,4)(1,4)(2,4)(3,4)(4,4)

Let say I need (1,3) element at the center

so the new array will be:
(4,1)(0,1)(1,1)(2,1)(3,1)
(4,2)(0,2)(1,2)(2,2)(3,2)
(4,3)(0,3)(1,3)(2,3)(3,3)
(4,4)(0,4)(1,4)(2,4)(3,4)
(4,0)(0,0)(1,0)(2,0)(3,0)
that transformation is what I need...
"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@sparta.btinternet.com...
OK, let me understand you correctly please.

You start with

Dim yourArray( 512,512) as Point

'and end up with

Dim transformedArray( 256,256) as Point

And you say that you want a point at the centre ?

My Questions

1.) What transformation is taking/supposed to place? and are you asking how to acheive this ?

2.) With an even numbered x,y lengths you cannot acheive true centre, you
would need 257 or 255 ( with a centre of 229 or 228 ).

Please clarify
OHM


Crirus wrote:
Nope, I mean a 256 x 256 array of values..not a matrix like that
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bl************@ID-208219.news.uni-berlin.de...
"Crirus" <Cr****@datagroup.ro> scripsit:
I have a 512x512 matrix.
I need a rutine that give me a transformed matrix from the curent
one, with a given point in the middle of the matrix, I mean 256x256.

Do you use the 'System.Drawing.Drawing2D.Matrix' class?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>


Nov 20 '05 #5
I did it!
Thanks for help intention:

This is the ideea:

For i As Integer = 0 To Width - 1
For j As Integer = 0 To Height - 1
x = i + (((Width - 1) / 2) - thisPoint.X)
y = j + (((Height - 1) / 2) - thisPoint.Y)
If x < 0 Then x = Width + x
If y < 0 Then y = Height + y
If x >= Width Then x = x - Width
If y >= Height Then y = y - Height
oldArray(x, y)=NewArray(i, j)
Next
Next

"Crirus" <Cr****@datagroup.ro> wrote in message
news:OI**************@TK2MSFTNGP12.phx.gbl...
I have a 512x512 matrix.
I need a rutine that give me a transformed matrix from the curent one, with a given point in the middle of the matrix, I mean 256x256.

Any thoughts?

Crirus

Nov 20 '05 #6
you could try something like this (code not tested) but look out for index
out of bound errors

dim x2,y2 as integer
for x as int = p1 -128 to p1 +128
for y as int = p2 -128 to p2 + 128
arr2(x2,y2) = arr1(x,y)
y2+=1
loop
x2 +=1
loop

"Crirus" <Cr****@datagroup.ro> wrote in message
news:uq**************@TK2MSFTNGP10.phx.gbl...
Ok, few mistakes...
The array is one and only 512 x512 starting from 0 so tere are 513 elements on each dimension
I need another 512x512 array with a specified element in the 128x128
position

like this:

suppose (x,y) is the element at x,y position in the array

First 5x5 array()

(0,0)(1,0)(2,0)(3,0)(4,0)
(0,1)(1,1)(2,1)(3,1)(4,1)
(0,2)(1,2)(2,2)(3,2)(4,2)
(0,3)(1,3)(2,3)(3,3)(4,3)
(0,4)(1,4)(2,4)(3,4)(4,4)

Let say I need (1,3) element at the center

so the new array will be:
(4,1)(0,1)(1,1)(2,1)(3,1)
(4,2)(0,2)(1,2)(2,2)(3,2)
(4,3)(0,3)(1,3)(2,3)(3,3)
(4,4)(0,4)(1,4)(2,4)(3,4)
(4,0)(0,0)(1,0)(2,0)(3,0)
that transformation is what I need...
"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@sparta.btinternet.com...
OK, let me understand you correctly please.

You start with

Dim yourArray( 512,512) as Point

'and end up with

Dim transformedArray( 256,256) as Point

And you say that you want a point at the centre ?

My Questions

1.) What transformation is taking/supposed to place? and are you asking

how
to acheive this ?

2.) With an even numbered x,y lengths you cannot acheive true centre, you would need 257 or 255 ( with a centre of 229 or 228 ).

Please clarify
OHM


Crirus wrote:
Nope, I mean a 256 x 256 array of values..not a matrix like that
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bl************@ID-208219.news.uni-berlin.de...
> "Crirus" <Cr****@datagroup.ro> scripsit:
>> I have a 512x512 matrix.
>> I need a rutine that give me a transformed matrix from the curent
>> one, with a given point in the middle of the matrix, I mean 256x256.
>
> Do you use the 'System.Drawing.Drawing2D.Matrix' class?
>
> --
> Herfried K. Wagner
> MVP · VB Classic, VB.NET
> <http://www.mvps.org/dotnet>



Nov 20 '05 #7
Hi Crirus,

There is unlikely to be anything in the Framework.

Can you give us any more information about what kind of transform you are
talking about - out of a universe of possibilities? The more you can specify,
the more likely someone will understand the requirement.

Regards,
Fergus
Nov 20 '05 #8
Hi,

This seems to be simple as long as allocating yet another couple of
megabytes shouldn't be an issue. So, allocate a destination array of the
same size. Then, start looping over rows and columns of the source array
(i.e. outer and inner loops). Within the inner loop body,
assuming that loop indexes were named row and col:

Dim newRow As Integer = (row + 128) Mod 512
Dim newCol As Integer = (col + 128) Mod 512

NewArray(newRow, newCol) = OldArray(row, col)

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
"Crirus" <Cr****@datagroup.ro> wrote in message
news:uq**************@TK2MSFTNGP10.phx.gbl...
Ok, few mistakes...
The array is one and only 512 x512 starting from 0 so tere are 513 elements on each dimension
I need another 512x512 array with a specified element in the 128x128
position

like this:

suppose (x,y) is the element at x,y position in the array

First 5x5 array()

(0,0)(1,0)(2,0)(3,0)(4,0)
(0,1)(1,1)(2,1)(3,1)(4,1)
(0,2)(1,2)(2,2)(3,2)(4,2)
(0,3)(1,3)(2,3)(3,3)(4,3)
(0,4)(1,4)(2,4)(3,4)(4,4)

Let say I need (1,3) element at the center

so the new array will be:
(4,1)(0,1)(1,1)(2,1)(3,1)
(4,2)(0,2)(1,2)(2,2)(3,2)
(4,3)(0,3)(1,3)(2,3)(3,3)
(4,4)(0,4)(1,4)(2,4)(3,4)
(4,0)(0,0)(1,0)(2,0)(3,0)
that transformation is what I need...
"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@sparta.btinternet.com...
OK, let me understand you correctly please.

You start with

Dim yourArray( 512,512) as Point

'and end up with

Dim transformedArray( 256,256) as Point

And you say that you want a point at the centre ?

My Questions

1.) What transformation is taking/supposed to place? and are you asking

how
to acheive this ?

2.) With an even numbered x,y lengths you cannot acheive true centre, you would need 257 or 255 ( with a centre of 229 or 228 ).

Please clarify
OHM


Crirus wrote:
Nope, I mean a 256 x 256 array of values..not a matrix like that
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bl************@ID-208219.news.uni-berlin.de...
> "Crirus" <Cr****@datagroup.ro> scripsit:
>> I have a 512x512 matrix.
>> I need a rutine that give me a transformed matrix from the curent
>> one, with a given point in the middle of the matrix, I mean 256x256.
>
> Do you use the 'System.Drawing.Drawing2D.Matrix' class?
>
> --
> Herfried K. Wagner
> MVP · VB Classic, VB.NET
> <http://www.mvps.org/dotnet>




Nov 20 '05 #9
Hi Crirus,

Here's a version using Modulo arithmetic rather than Ifs to do the
wraparound. I've done two flavours - one if you prefer rows and columns, the
other if you prefer Xs and Ys. ;-)

Regards,
Fergus

<code info="Row, Col version>
Public Sub MoveToCentre (ByRef aVals(,) As Object, _
CentreRow As Integer, CentreCol As Integer)
Dim Width As Integer = aVals.GetUpperBound(0)
Dim Height As Integer = aVals.GetUpperBound(1)

Dim RowMod As Integer = Width + 1
Dim ColMod As Integer = Height + 1

Dim RowOffset As Integer = Width \ 2 + CentreRow + 1
Dim ColOffset As Integer = Height \ 2 + CentreCol + 1

Dim aNewVals (Width, Height) As Object
Dim Row As Integer
Dim Col As Integer
For Row = 0 To Height
For Col = 0 To Width
Dim SrcRow As Integer = (Row + RowOffset) Mod RowMod
Dim SrcCol As Integer = (Col + ColOffset) Mod ColMod
aNewVals (Row, Col) = aVals (SrcRow, SrcCol)
Next
Next
aVals = aNewVals
End Sub
</code>

<code info="X, Y version>
Public Sub MoveToCentre (ByRef aVals(,) As Object, _
CentreX As Integer, CentreY As Integer)
Dim W As Integer = aVals.GetUpperBound(0)
Dim H As Integer = aVals.GetUpperBound(1)

Dim XMod As Integer = W + 1
Dim YMod As Integer = H + 1

Dim dX As Integer = W \ 2 + CentreX + 1
Dim dY As Integer = H \ 2 + CentreY + 1

Dim aNewVals (W, H) As Object
Dim I As Integer
Dim J As Integer
For I = 0 To W
For J = 0 To H
aNewVals (I, J) _
= aVals ((I + dX) Mod XMod, (J + dY) Mod YMod)
Next
Next
aVals = aNewVals
End Sub

</code>
Nov 20 '05 #10
Hi Me,

Damn server - several hours behind!! :-((

Regards,
Myself
Nov 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ben Ingram | last post by:
Hi all, I am writing a template matrix class in which the template parameters are the number of rows and number of columns. There are a number of reasons why this is an appropriate tradeoff for...
5
by: Jason | last post by:
Hello. I am trying to learn how operator overloading works so I wrote a simple class to help me practice. I understand the basic opertoar overload like + - / *, but when I try to overload more...
2
by: Peter Proost | last post by:
Hi group, I got the following piece of code which draws a square with stars round it, now I want the stars to rotate round the square, I can do this with the mx.rotate and a timer and an...
20
by: Frank-O | last post by:
Hi , Recently I have been commited to the task of "translating" some complex statistical algorithms from Matlab to C++. The goal is to be three times as fast as matlab ( the latest) . I've...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
2
by: DarrenWeber | last post by:
Below is a module (matrix.py) with a class to implement some basic matrix operations on a 2D list. Some things puzzle me about the best way to do this (please don't refer to scipy, numpy and...
0
by: DarrenWeber | last post by:
# Copyright (C) 2007 Darren Lee Weber # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free...
1
by: PhilC | last post by:
''' ################################################ Task:- to apply a translation array to an array of 3D vertex coordinates to produce the resulting location of each vertices. Translation...
2
by: rijaalu | last post by:
I am designing a matrix class that performs addition, multicpication, substraction and division. When ever i complie the code it shows an error. include <iostream> using namespace std; class...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.