NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 70 71 72 73 74 … 93 Next »
who is good at maths?

 
  • 0 Vote(s) - 0 Average
who is good at maths?
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#1
2005-07-06, 03:28 PM
im having trouble with zooming in/out and the x,y why points in my pictures. everytime i do it, i get the formula wrong, and i got sick of trying. so whose good at maths? the variable i have to work with are
zoomfactor = how much the pic is zoomed in by
oldzoomfactor = the old zoom factor
oldX, oldY, oldWidth, oldHeight = old image dimensions.
newX, newY, newWidth, newHeight = new image dimensions.

to get the newwidth/height i just do oldWidth/oldzoomfactor * newzoomfactor. but how do i get the newx/y? i havent done any maths in years, and i looks like ive forgotten most things (im sure i could do this back in highschool). so anyway, anyone know the solution?

cheers,
reven.
betlit
Offline

Senior Member

Posts: 449
Threads: 17
Joined: Feb 2005
#2
2005-07-06, 04:03 PM
uhm... *thinking...* should the x position not be more on the right (when zooming in) using the same factor as the width grows?

newX= oldX * ( oldWidth/newWidth )

or...? :o
AMD 1600mHz, 512 M RAM, 20+160 GB drive, Hauppauge PVR-350 + PVR-150 + PVR-150MCE, Win XP Pro SP3, using software decoding.


There is a theory which states that if ever anyone discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.

There is another theory which states that this has already happened.

(The Restaurant at the End of the Universe)
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#3
2005-07-06, 04:57 PM
nah that doesnt work either, if there is only 1 pixel, and you zoom in by 300%, ie 1*3. you should get a 3x3 image, the middle pixel of that image should be at position 0,0. so the x, y pos should now be -1, -1. where that formula results in
0 = 0 *(1/3)
its tricker than you would think....
cheers for the effort thou Smile.
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#4
2005-07-06, 04:59 PM
the best results i have had is using
newX = (newwidth- oldwidth)/2
but theres something incorrect there, it does work exactly right.
LilY0da
Offline

Senior Member

Posts: 442
Threads: 25
Joined: Jul 2005
#5
2005-07-06, 05:06 PM
What are X and Y?
Is it the top left corner of the box you are selecting in your unzoomed image? something else?
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#6
2005-07-06, 05:10 PM
yeah x,y = top left hand corner of the image.
smeghead
Offline

Senior Member

Posts: 300
Threads: 23
Joined: Jan 2005
#7
2005-07-06, 06:18 PM (This post was last modified: 2005-07-06, 06:36 PM by smeghead.)
reven Wrote:the best results i have had is using
newX = (newwidth- oldwidth)/2
but theres something incorrect there, it does work exactly right.

I assume you mean doesn't work exactly right

What you've done is how I would calculate it. What do you mean by not right. Is it something to do with rounding errors if you're doing calcs as integers. Does the image appear to jump left/right up/down as you zoom. If so it could just be rounding errors.

Edit: Just to explain a little more. You want the centre of the image to stay where it is when you zoom in or out. i.e. the centre most pixel must not move.
When you zoom, you are altering the ratio of the old width to the new width (same for height). So the X and Y positions move half the difference of the widths. This keeps the centre point stationary whilst zooming (which is why this is the best result you've so far). The problem I think you are having is rounding errors so the X and Y are not precisely in the correct place for the centre of the image to stay in the centre. When you are zooming multiple times the centre "drifts". So if you zoom out several times and zoom back in you don't get to the same place and the image jumps around a bit, very disconcerting.

The only way to fix this is to do zooming based on an absolute reference insteady of relative. The way you do it is relative, as you take the previous values to calculate the new values.

I suggest you take the 100% zoom position (i.e. the normal position") as an absolute reference and calculate all other values from this.

You can discard the old values and not use them. Also, keep all values as doubles until you need integers.
Heyt
Offline

Member

Posts: 106
Threads: 9
Joined: Jan 2005
#8
2005-07-06, 06:34 PM
Hi reven,

i think your formula is in principle correct

Quote:newX = (newwidth- oldwidth)/2

but you just calculate the difference in width and then take the half of it. So far OK, but if you want the wright new position you have to change the old image position. So try these two formula and all should be correct not only for the first zoom but also for all other rezooms.

newX = oldX - ((newWidth - oldWidth) / 2)
newY = oldY - ((newHeight - oldHeight) / 2)

Or you could use always the original imagesize and position (0,0 as i asume)
Then it would be

zoomfactor = you have your way to find it
oldzoomfactor = not needed
Width, Height = Parameters of the not zoomed image (should be no problem for you)
newX, newY, newWidth, newHeight = new parameters

and for calculation you need these formula:

newWidth = Width * zoomfactor
newHeight = Height * zoomfactor
newX = (newWidth - Width) / 2
newY = (newHeight - Height) / 2

The second method would be also nicer because you would run in fewer problems about rounding
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#9
2005-07-06, 08:10 PM
Quote:I assume you mean doesn't work exactly right
yeah it was 5am when i wrote that Smile

Quote:What you've done is how I would calculate it. What do you mean by not right. Is it something to do with rounding errors if you're doing calcs as integers. Does the image appear to jump left/right up/down as you zoom. If so it could just be rounding errors.
it works fine if you keep it in the centre, but if you go off to one of the sides, it zooms in towards the centre of the entire image (not the centre of the current view). it doesnt jump to the centre of the image, but doesnt zoom into the exact middle of the current position... hard to explain (could be rounding errors, but i dont think it is).

Quote:You can discard the old values and not use them. Also, keep all values as doubles until you need integers.
yeah i think im already doing that, something ive been working to long on, so im obiviously overlooking the very basic... Smile

Quote:newX = oldX - ((newWidth - oldWidth) / 2)
newY = oldY - ((newHeight - oldHeight) / 2)
whooops, i forgot that part in my post, the current formula isR);
currentImageBounds.X -= (currentImageBounds.Width - oldWidth)/2;
currentImageBounds.Y -= (currentImageBounds.Height - oldHeight)/2;

Quote:newX = (newWidth - Width) / 2
newY = (newHeight - Height) / 2
wouldnt that just centre the image all the time, ie if you zoom in at the top left hand corner, you would be forced back to the centre of the image? or did you leave out the -= aswell? Smile

im redoing it now to safe guard from rounding errors.
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#10
2005-07-06, 08:31 PM
alas no joy still, using this
Code:
double oldWidth = current.Width;
            double oldHeight = current.Height;
            
            current.Width = current.OriginalWidth * current.Zoom;
            current.Height = current.OriginalHeight * current.Zoom;
            /*
            current.X = (current.Width - current.OriginalWidth) / 2;
            current.Y = (current.Height - current.OriginalHeight) / 2;
            */
            current.X -= ((current.Width - oldWidth) / 2);
            current.Y -= ((current.Height - oldHeight) / 2);
every variable are doubles, and are converted to ints at the very last step.
Code:
Graphics.FromImage(compositeScreenImage).DrawImage(currentImage,current.ImageBounds);
where current.ImageBounds, just returns
Code:
return new Rectangle((int)this.x,(int)this.y,(int)this.width,(int)this.height);
for you no programmers, that just creates a rectangle (dah) as converts all the doubles, ie 2.34324324324 to 2 (since pixels cant be dot something). so nope not a rounding issue. theres got to be a flaw in the logic somewhere....

oh and the stuff between the /*...*/ is commented out, ie ignored (i think i got that formula wrong it there).
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)

Pages (4): 1 2 3 4 Next »


Possibly Related Threads…
Thread Author Replies Views Last Post
  What's a good Open Source VB.net plugin that I could browse? zehd 0 1,208 2007-01-30, 02:00 AM
Last Post: zehd
  Anyone recommend a good C# book? bgowland 9 3,730 2005-01-03, 07:32 PM
Last Post: bgowland

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode