|
-
Jun 15th, 2008, 12:37 PM
#1
Thread Starter
PowerPoster
[RESOLVED] rotate a point in math, in circule
can anyone tell me how rotate on point in circule?
i have some information, but don't give me the right resolts.
please i don't know use Matriz, is more advanced and i never work with it.
thanks
-
Jun 15th, 2008, 02:26 PM
#2
Re: rotate a point in math, in circule
Your question is really unclear... What do you mean?
You want to rotate a point on a circle? How do you mean rotate?
You use the word 'Matriz', do you mean matrix? Do you perhaps want a linear transformation that transforms a point (x,y) to another point that lies on a circle?
-
Jun 15th, 2008, 02:33 PM
#3
Thread Starter
PowerPoster
Re: rotate a point in math, in circule
"You want to rotate a point on a circle?"
yes
"You use the word 'Matriz', do you mean matrix?"
yes
"Do you perhaps want a linear transformation that transforms a point (x,y) to another point that lies on a circle?"
i don't know what is lies(in these case), but yes... i want to know rotate a point (X,Y) in a circule(depending in angle).
thanks
-
Jun 15th, 2008, 03:08 PM
#4
Re: rotate a point in math, in circule
Alright.
Consider the following figure:

Suppose you have the point (x,y) and you want to rotate it to the point (u,v).
The two blue arrows are called 'vectors', they point from the origin to a point.
Since both points are on the circle, the length of these vectors is r (the radius of the circle).
The angle b is the angle that the vector to (x,y) makes with the positive x-axis.
The angle a is the angle that the vector to (u,v) makes with the vector to (x,y).
From basic trigonometry you can see that:
x = r cos(b)
y = r sin(b)
And:
u = r cos(a + b)
v = r sin(a + b)
Now, you might know the following trigonometric identities:
cos(a + b) = cos(a) cos(b) - sin(a) sin(b)
sin(a + b) = sin(a) cos(b) + cos(a) sin(b)
Substituting these in the expressions for u and v we can find:
u = r cos(a) cos(b) - r sin(a) sin(b)
v = r sin(a) cos(b) + r cos(a) sin(b)
Now you can rearrange this to:
u = [ r cos(b) ] cos(a) - [ r sin(b) ] sin(a)
v = [ r cos(b) ] sin(a) + [ r sin(b) ] cos(a)
Remember the equations for x and y and we get:
u = x cos(a) - y sin(a)
v = x sin(a) + y cos(a)
This is the pair of equations you need to rotate a point (x,y) over an angle a to the point (u,v).
You can also write this in matrix form:
-
Jun 15th, 2008, 03:25 PM
#5
Thread Starter
PowerPoster
Re: rotate a point in math, in circule
thanks for everything... thank you
-
Jun 20th, 2008, 03:22 PM
#6
Thread Starter
PowerPoster
Re: rotate a point in math, in circule
i'm sorry but your functions/formulas are working in degrees or radians?
and the r in (x,y) is the same in (u,v)?
thanks
Last edited by joaquim; Jun 20th, 2008 at 03:28 PM.
-
Jun 20th, 2008, 03:52 PM
#7
Re: rotate a point in math, in circule
They work in both degrees and radians ofcourse. If you take the (co)sine of an angle it does not matter wether you do it in radians or degrees.
Yes, the r is the same for the point (x,y) and the point (u,v) since both points are on the circle with radius r.
-
Jun 20th, 2008, 03:57 PM
#8
Thread Starter
PowerPoster
Re: rotate a point in math, in circule
thanks...
know a need to know 1 thing: how calculate the b, since i will know the a?
-
Jun 20th, 2008, 04:08 PM
#9
Re: rotate a point in math, in circule
You don't need it! Look at the last equation again:
u = x cos(a) - y sin(a)
v = x sin(a) + y cos(a)
There's no b in there...!
However, you CAN calculate it!
Look at the point (x,y) in the image again, and also at the blue vector pointing at it.
Can you imagine a line 'falling down' from the point (x,y) to the x-axis?
This will make a right-triangle (a triangle with one angle of 90 degrees).
If you know your basic trigonometry you can see that the tangens (tan) of the angle b is exactly the length y divided by the length x.
So:
tan(b) = y/x
b = arctan(y/x) (or tan-1(y/x))
There's your b!
-
Jun 20th, 2008, 04:23 PM
#10
Thread Starter
PowerPoster
Re: rotate a point in math, in circule
heres the code for rotate one image, but there is some errors. please tell me what isn't right. thanks
Code:
Public Sub RotateImage(PicDestiny As PictureBox, PicSource As PictureBox, Angle As Long)
Dim X1 As Long
Dim Y1 As Long
Dim X2 As Long
Dim Y2 As Long
Dim X As Long
Dim Y As Long
Dim ActualAngle As Long
Dim Hipotenuse As Long
Dim Radians As Long
Dim NewAngule As Long
PicDestiny.Cls
'Change the picdestiny size
For X1 = 1 To PicSource.Width
For Y1 = 1 To PicSource.Height
If GetPixel(PicSource.hdc, X1, Y1) <> &HFFFF Then
'Calculate the position in a circule by using the center X, Y
Y = Y1 - (PicDestiny.Height / 2)
X = X1 - (PicDestiny.Width / 2)
'Calculate the actual Hipotenuse
Hipotenuse = Math.Sqr(X * X + Y * Y)
'Calculate the ActualAngule(the b in your image)
ActualAngle = ArcTangent(X, Y)
'Calculate the new angule(the a in your image)
NewAngule = ActualAngle - Angle
'Calculate the new position
Y2 = (Hipotenuse * Sin(NewAngule)) + PicDestiny.Height / 2
X2 = (Hipotenuse * Cos(NewAngule)) + PicDestiny.Width / 2
'Then change put the pixel in new position in picDestiny
SetPixel PicDestiny.hdc, Y2, X2, GetPixel(PicSource.hdc, X1, Y1)
End If
Next Y1
Next X1
'PicDestiny.Refresh
End Sub
Public Function ArcTangent(ByVal op As Double, ByVal ad As Double) As Double
Dim at As Double
If ad = 0 Then
If op > 0 Then
ArcTangent = PI / 2#
Else
ArcTangent = PI * 1.5
End If
Else
at = Atn(op / ad)
If ad < 0 Then
ArcTangent = PI + at
ElseIf op# < 0 Then
ArcTangent = PI + PI + at
Else
ArcTangent = at
End If
End If
End Function
i'm sorry and thanks
is the 1st time that i'm doing these...
-
Jun 20th, 2008, 04:35 PM
#11
Re: rotate a point in math, in circule
I'm not sure I understand what you're doing exactly. Are you taking an image, and rotating each pixel (point) separately over the same angle?
I think you're using far to much math. You are calculating things you don't need, for example the hypotenuse (that's r, right?) and b. You don't need them!
Is X2 and Y2 the new position for your pixel, after rotating? Then you are not calculating them correctly. You're not using the formula I gave you!
Here's something I would try (not all in VB code but just 'pseudo-code', translate it into VB code like you have, with the correct error checking etc..)
Code:
Dim x As Double, y As Double, u As Double, v As Double
'x and y is the starting point
'u and v is the point after rotating
Dim a As Double
'a is the angle to rotate over
'Loop through each pixel
For each p As pixel In YourImage
'Set starting point
x = p.x
y = p.y
'Calc ending point
u = x * cos(a) - y * sin(a)
v = x * sin(a) + y * cos(a)
'Set ending point
p.x = u
p.y = v
Next
EDIT
Ok that might not work entirely, it depends on how the pixels coordinates 'p.x' and 'p.y' are given. These are probably given relative to one of the corners of the image (so for example the lower-left corner is 0,0). This is not right in my calculation.
What you need to do then is add the position of the image itself, relative to where the origin is chosen.
Am I right in saying that you are rotating the image over a circle, so instead of only rotating in it's place it will also move (like a ball you throw into the air at an angle for example)...? Then you need some way to define the origin of the rotation.
If you are only rotating the image through a fixed point then the origin of your rotation is the center of the image, and my formula will still work (as long as you give x and y appropriately).
Last edited by NickThissen; Jun 20th, 2008 at 04:40 PM.
-
Jun 20th, 2008, 04:47 PM
#12
Thread Starter
PowerPoster
Re: rotate a point in math, in circule
know i can see something, but i continue with some errors...
i'm realy sorry but help me again... thanks
Code:
Public Sub RotateImage(PicDestiny As PictureBox, PicSource As PictureBox, Angle As Long)
Dim X1 As Long
Dim Y1 As Long
Dim X2 As Long
Dim Y2 As Long
Dim X As Long
Dim Y As Long
'Clear the picture destiny
PicDestiny.Cls
For X1 = 0 To PicSource.Width
For Y1 = 0 To PicSource.Height
If GetPixel(PicSource.hdc, X1, Y1) <> &HFFFF Then
'Calculate the position in a circule by using the center X, Y
Y = Y1 - (PicDestiny.Height / 2)
X = X1 - (PicDestiny.Width / 2)
'Calculate the new position
X2 = X * Sin(Angle) - Y * Sin(Angle) + PicDestiny.Height / 2
Y2 = X * Cos(Angle) + Y * Sin(Angle) + PicDestiny.Width / 2
'Then change put the pixel in new position in picDestiny
SetPixel PicDestiny.hdc, Y2, X2, GetPixel(PicSource.hdc, X1, Y1)
End If
Next Y1
Next X1
'PicDestiny.Refresh
End Sub
-
Jun 20th, 2008, 04:54 PM
#13
Re: rotate a point in math, in circule
Alright, another image then ^^

Is this what you want to do?
In this example the X1 and Y1 (which I assume are the coordinates of the pixel) are relative to the origin at the lower-left corner of the image (where the blue arrow is pointing at).
So what you have called X1 and Y1 is in the image x and y (small letters). The red dot in the image represents a single pixel.
The capital (big letter) X in the image is the distance (x-component) of the origin of rotation (over which point the image is rotating) to the origin of the picture. The capital Y (not drawn) in the picture is the height of the picture (in the image, 0).
Now in order for my formula to work what you should use is:
u = (x + X) cos(a) - (y + Y) sin(a)
v = (x + X) sin(a) + (y + Y) cos(a)
Now I don't know what X and Y are and how you are trying to figure them out...
-
Jun 20th, 2008, 04:59 PM
#14
Thread Starter
PowerPoster
Re: rotate a point in math, in circule
i'm sorry but you have right...
x1 and y1 are the coordenates of image in rectangule;
x and y are the coordenates of image in cartegian circule;
x2 and y2 are the coordenates of image in cartegian circule, but in new angule. but then translated to rectangule coordenates.
thanks
-
Jun 20th, 2008, 05:04 PM
#15
Thread Starter
PowerPoster
Re: rotate a point in math, in circule
look these example:
i have 1 point 10,20;
now i need rotate it with 45 degrees.
thanks
-
Jun 21st, 2008, 02:10 AM
#16
Thread Starter
PowerPoster
Re: rotate a point in math, in circule
i found 2 errors, but i continue with problems.
Code:
Public Sub RotateImage(PicDestiny As PictureBox, PicSource As PictureBox, Angle As Long, Optional PosX As Long = 0, Optional PosY As Long = 0)
Dim X1 As Long
Dim Y1 As Long
Dim X2 As Long
Dim Y2 As Long
Dim X As Long
Dim Y As Long
Dim result As Long
'Clear the picture destiny
PicDestiny.Cls
For X1 = 0 To PicSource.Width
For Y1 = 0 To PicSource.Height
result = GetPixel(PicSource.hdc, X1, Y1)
If result <> -1 Then
'Calculate the position in a circule by using the center X, Y
X = X1 - (PicSource.Width / 2)
Y = Y1 - (PicSource.Height / 2)
'Calculate the new position
X2 = (X * Sin(Angle) - Y * Sin(Angle)) + (PicSource.Height / 2)
Y2 = (X * Cos(Angle) + Y * Sin(Angle)) + (PicSource.Width / 2)
'After changed, put the pixel in new position in picDestiny
SetPixel PicDestiny.hdc, X2, Y2, GetPixel(PicSource.hdc, X1, Y1)
End If
Next Y1
Next X1
End Sub
i can see the image with 2 problems:
1-i can see black(nothing) pixels between pixels;
2-the rotation isn't correct.
-
Jun 21st, 2008, 03:48 AM
#17
Re: rotate a point in math, in circule
Ok let me explain and ask a few questions again:
1) You have an image.
2) You can get each pixel seperately using the GetPixel(source, X1, Y1) command?
3) The X1 and Y1 commands are relative to which point in the image?
In other words, where is the pixel (0,0) ? (left-bottom, right-bottom, left-top, center, etc?)
4) You want to rotate the image (each pixel) over a fixed rotation axis and this rotation axis is NOT the center of the image?
5) How do you determine the rotation axis? Or, around which point is the image rotated?
Now suppose you have an image where the pixels you get from GetPixel() are relative to the lower-left corner. So the 'first' pixel in the lower-left corner has the value (x,y) = (0,0).
This is the origin of the image, and NOT the origin of your cartesian coordinate system.
The image is placed somewhere in your cartesian coordinate system, at an X and Y value (X,Y). This value is calculated from the origin of your coordinate system to the origin of the image (see the picture above where the blue arrow points from the origin of the coord. system to the origin of the image).
To rotate a pixel over an angle a, you use the following formula:
u = (x + X) cos(a) - (y + Y) sin(a)
v = (x + X) sin(a) + (y + Y) cos(a)
Now, (u,v) is the NEW point of the pixel after rotation.
On a different note, I believe you can never get the picture to rotate 100% perfectly. This is because the actual pixels in your monitor cannot actually rotate. What you are doing is essentially moving the pixels so it looks as though the image has rotated.
The only way to make the image look as good as possible afaik is to use some sort of extrapolation algorithm, which takes each 'empty space' (black pixel) and looks at the pixels around it, then colors it accordingly.
If you have some graphic program like Photoshop you can see this happen, take an image and rotate it, if you look closely you can see that it is not perfect anymore but slightly blurred. You can see this best if you rotate just a line for example or a rectangle.
Afaik there is no way to avoid this.
-
Jun 21st, 2008, 11:06 AM
#18
Thread Starter
PowerPoster
Re: rotate a point in math, in circule
"1) You have an image."
yes
"2) You can get each pixel seperately using the GetPixel(source, X1, Y1) command?"
yes
"3) The X1 and Y1 commands are relative to which point in the image?
In other words, where is the pixel (0,0) ? (left-bottom, right-bottom, left-top, center, etc?)"
the pixel(0,0) is the middle of source(ImageWidth/2,ImageHeight/2).
"4) You want to rotate the image (each pixel) over a fixed rotation axis and this rotation axis is NOT the center of the image?"
yes it is. the the center of image will be converted to (0,0).
"5) How do you determine the rotation axis? Or, around which point is the image rotated?"
i don't hunderstand the question.
"Now suppose you have an image where the pixels you get from GetPixel() are relative to the lower-left corner. So the 'first' pixel in the lower-left corner has the value (x,y) = (0,0).
This is the origin of the image, and NOT the origin of your cartesian coordinate system."
yes
"The image is placed somewhere in your cartesian coordinate system, at an X and Y value (X,Y). This value is calculated from the origin of your coordinate system to the origin of the image (see the picture above where the blue arrow points from the origin of the coord. system to the origin of the image)."
"To rotate a pixel over an angle a, you use the following formula:
u = (x + X) cos(a) - (y + Y) sin(a)
v = (x + X) sin(a) + (y + Y) cos(a)"
what is x and X? is X and X1?
"The only way to make the image look as good as possible afaik is to use some sort of extrapolation algorithm, which takes each 'empty space' (black pixel) and looks at the pixels around it, then colors it accordingly."
but the problem is that i don't know when they are visible.
thanks
-
Jun 21st, 2008, 05:23 PM
#19
Re: rotate a point in math, in circule
I still don't understand what you're actually trying to achieve, and I find it difficult to bring it into words lol...
Are you trying to rotate an image, over a circle, over a fixed rotation axis that is not in the image? (Like in the last picture I made?)
Or are you trying to rotate an image at a fixed position?
-
Jun 22nd, 2008, 03:58 AM
#20
Thread Starter
PowerPoster
Re: rotate a point in math, in circule
 Originally Posted by NickThissen
I still don't understand what you're actually trying to achieve, and I find it difficult to bring it into words lol...
Are you trying to rotate an image, over a circle, over a fixed rotation axis that is not in the image? (Like in the last picture I made?)
Or are you trying to rotate an image at a fixed position?
i'm trying rotate the image in fixed position.
thanks
-
Jun 22nd, 2008, 08:04 AM
#21
Re: rotate a point in math, in circule
Alright that makes it a tad easier.
So the pixel's (x,y) coordinates are relative to the center of the image. That means that the (x,y) coordinates can be negative, right?
Can you verify that the x-coordinate of each pixel is negative if it is to the LEFT of the center? (And positive to the right)
Can you verify that the y-coordinate of each pixel is negative if it is BENEATH (under) the center of the image? (And positive above)
If that is indeed the case then the code I already posted should work! I tried to rewrite it a bit for your case:
Code:
Dim X1 As Double, Y1 as Double, X2 As Double, Y2 As Double
Dim a As Double
Dim result As Integer
'Loop
For X1 = -1 * PicSource.Width / 2 To PicSource.Width / 2
For Y1 = -1 * PicSource.Height To PicSource.Heigth / 2
'Get X1 and Y1
result = GetPixel(PicSource.hdc, X1, Y1)
If result <> -1 Then
'Calculate new position X2, Y2
X2 = X1 * cos(a) - Y1 * sin(a)
Y2 = X1 * sin(a) + Y2 * cos(a)
SetPixel PicDestiny.hdc, X2, Y2, GetPixel(PicSource.hdc, X1, Y1)
End if
Next Y1
Next X1
-
Jun 22nd, 2008, 10:31 AM
#22
Thread Starter
PowerPoster
Re: rotate a point in math, in circule
"Alright that makes it a tad easier.
So the pixel's (x,y) coordinates are relative to the center of the image. That means that the (x,y) coordinates can be negative, right?"
yes
"Can you verify that the x-coordinate of each pixel is negative if it is to the LEFT of the center? (And positive to the right)"
i think so...
"Can you verify that the y-coordinate of each pixel is negative if it is BENEATH (under) the center of the image? (And positive above)"
i think so...
i'm sorry but the code continue with errors...
i'm realy sorry for everything and thanks
-
Jun 22nd, 2008, 11:28 AM
#23
Re: rotate a point in math, in circule
What errors, what is happening then?
Can you show me the entire code, not just this bit but also how the GetPixel function works etc..? Maybe I can try it myself... Is this VB6 or .NET?
-
Jun 22nd, 2008, 11:46 AM
#24
Thread Starter
PowerPoster
Re: rotate a point in math, in circule
is visual basic 6. you don't see the image in project mode, because can give you an error. the image is puted when you execute the program.
the error isn't the a message, but what you see.
i'm realy sorry bored you...
thank you very much
Last edited by joaquim; Jul 24th, 2008 at 07:59 PM.
-
Jun 22nd, 2008, 12:08 PM
#25
Re: rotate a point in math, in circule
I don't have VB6 so I can't test it.
I did try to get the same thing to work in VB.NET though but it did not do anything, probably because I didn't use the GetPixel and SetPixel functions properly...
I did notice that in VB.NET there is a simple function that rotates the image in a picturebox. Are you sure this function is not available in VB6?
Why do you want to rotate the image this way? Are you sure there are not easier methods?
-
Jun 22nd, 2008, 12:14 PM
#26
Thread Starter
PowerPoster
Re: rotate a point in math, in circule
 Originally Posted by NickThissen
I don't have VB6 so I can't test it.
I did try to get the same thing to work in VB.NET though but it did not do anything, probably because I didn't use the GetPixel and SetPixel functions properly...
I did notice that in VB.NET there is a simple function that rotates the image in a picturebox. Are you sure this function is not available in VB6?
Why do you want to rotate the image this way? Are you sure there are not easier methods?
i think yes. but the problem is that i don't know use directx and other things.
did you know use VB.net? can you do a dll for rotate an image?
the function must have more or less these header:
RotateImage(Picture as Image, Angle as integer) as image
can you give me(when you have time)?
thanks
-
Jun 22nd, 2008, 12:19 PM
#27
Re: rotate a point in math, in circule
No I don't think I can, never done that before... You're going to have to ask someone else sorry! Also I couldn't get the rotate function in .NET to work either ^^
I still think there are much easier ways to do this... Try this for example:
http://www.aurigma.com/Support/DocVi...mages.htm.aspx
-
Jun 22nd, 2008, 12:26 PM
#28
Thread Starter
PowerPoster
Re: rotate a point in math, in circule
 Originally Posted by NickThissen
No I don't think I can, never done that before... You're going to have to ask someone else sorry! Also I couldn't get the rotate function in .NET to work either ^^
I still think there are much easier ways to do this... Try this for example:
http://www.aurigma.com/Support/DocVi...mages.htm.aspx
the problem of these site is that i don't know how catch the functions, they only speak how use it and no how catch it.
the problem is that there is another way, in vb.net, how to call and use that functions.
i'm realy sorry and thanks
-
Jun 22nd, 2008, 09:25 PM
#29
Re: rotate a point in math, in circule
hi, Joaquin.
It is possible to use .net GDI+ in VB6, and it does have a rotate function. I've not used it myself directly but a bit of GoogleFu should get you there. It's not particularly fast, but it's a load faster than any code using Get/Setpixel.
-
Jun 27th, 2008, 04:20 PM
#30
Thread Starter
PowerPoster
Re: rotate a point in math, in circule
 Originally Posted by Milk
hi, Joaquin.
It is possible to use .net GDI+ in VB6, and it does have a rotate function. I've not used it myself directly but a bit of GoogleFu should get you there. It's not particularly fast, but it's a load faster than any code using Get/Setpixel.
hi milk. how are you?
i'm sorry but how can i use it?
thanks
-
Jun 28th, 2008, 05:03 AM
#31
Re: rotate a point in math, in circule
-
Aug 5th, 2008, 03:34 PM
#32
Thread Starter
PowerPoster
Re: rotate a point in math, in circule
thanks to everyone...
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|