Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to change origin
- griefercube
-
Scratcher
500+ posts
How to change origin
I have this project and I’m trying to change the origin of the yellow balls rotation.
I used
I used
(((x) * ([cos v] of (direction)))-((y)*([sin v] of (direction)))For the x, is there any way to change the origin of the rotation?
- Wei-ern_520
-
Scratcher
500+ posts
How to change origin
Make a variable called direction? I might be misunderstanding.
- Wei-ern_520
-
Scratcher
500+ posts
How to change origin
Is there a way to change the direction variable? Also, I do not understand what the project is supposed to do.
- griefercube
-
Scratcher
500+ posts
How to change origin
Yes, there’s a block there )the variable is deerection)
The project has the origin of the spinning yellow circles (you can click and place it) of 0, 0 and I need to move the origin and now I ended up moving everything else.
The project has the origin of the spinning yellow circles (you can click and place it) of 0, 0 and I need to move the origin and now I ended up moving everything else.
- deck26
-
Scratcher
1000+ posts
How to change origin
Again, please don't bump after less than 24 hours.
https://scratch.mit.edu/projects/73409464/ may help - the background sprite rotates around Scratch cat even when that is not the centre of the sprite.
https://scratch.mit.edu/projects/73409464/ may help - the background sprite rotates around Scratch cat even when that is not the centre of the sprite.
- griefercube
-
Scratcher
500+ posts
How to change origin
Yep, that definitely helped.
But now remains one question. Could this be replicated with only ONE block? (like, everything nested in one operator block)
But now remains one question. Could this be replicated with only ONE block? (like, everything nested in one operator block)
- deck26
-
Scratcher
1000+ posts
How to change origin
Yep, that definitely helped.Almost certainly but it would be rather complex and unreadable.
But now remains one question. Could this be replicated with only ONE block? (like, everything nested in one operator block)
If you want to try to work it out I'd start with a few simple examples to work things out.
For example, if the centre of rotation is P pixels right of the true costume centre work out where the true centre needs to move when rotated 90, 180, 270 degrees.
Do the same exercise for when the centre of roation is P pixels left, above or below the true centre.
What about the centre of rotation being P pixels at 45 degrees to the true centre? What about rotating other angles?
If I have time I'll think about it but no promises.
- deck26
-
Scratcher
1000+ posts
How to change origin
First thoughts. All needs checking!
Assume you have a sprite with costume centre at X1, Y1 and the sprite is pointing in direction 90. If you want the rotation point to be at Rx, Ry we know that the offset within the sprite is Rx - X1, Ry - Y1 - lets call them Ox and Oy. So we can work out the distance between the two centres as sqrt (Ox * Ox + Oy * Oy) - we'll call that D. And the angle between the two centres is arctan Ox/Oy - we'll call that A.
So for rotation around the true centre we get
Rx = X1 + D sin A
Ry = Y1 + D cos A
But we want Rx and Ry to stay fixed so we need to reverse these to get new X and Y positions in terms of Rx and Ry. And these values are for when the sprite is pointing in direction 90 so
X1 = Rx - D sin (direction + A - 90)
Y1 = Ry - D cos (direction + A - 90)
See https://scratch.mit.edu/projects/576086785/ - seems to work
Assume you have a sprite with costume centre at X1, Y1 and the sprite is pointing in direction 90. If you want the rotation point to be at Rx, Ry we know that the offset within the sprite is Rx - X1, Ry - Y1 - lets call them Ox and Oy. So we can work out the distance between the two centres as sqrt (Ox * Ox + Oy * Oy) - we'll call that D. And the angle between the two centres is arctan Ox/Oy - we'll call that A.
So for rotation around the true centre we get
Rx = X1 + D sin A
Ry = Y1 + D cos A
But we want Rx and Ry to stay fixed so we need to reverse these to get new X and Y positions in terms of Rx and Ry. And these values are for when the sprite is pointing in direction 90 so
X1 = Rx - D sin (direction + A - 90)
Y1 = Ry - D cos (direction + A - 90)
See https://scratch.mit.edu/projects/576086785/ - seems to work
- griefercube
-
Scratcher
500+ posts
How to change origin
Leta say that we only need the x and y, not the direction (s) as I am making some dots
- griefercube
-
Scratcher
500+ posts
How to change origin
After some thinking, I came out with an idea:
First calculate the offset of the pivot and do the math with it
Then add the x and y back
At last turn the whole thing
First calculate the offset of the pivot and do the math with it
Then add the x and y back
At last turn the whole thing
- griefercube
-
Scratcher
500+ posts
How to change origin
Translate to origin + offset -> rotate -> ???
What’s the last step?
What’s the last step?
- deck26
-
Scratcher
1000+ posts
How to change origin
Translate to origin + offset -> rotate -> ???No idea what you mean by each of those really so you'll have to answer your own question. What's wrong with the project I did though?
What’s the last step?
- griefercube
-
Scratcher
500+ posts
How to change origin
Problem solved.
Small print: this script ONLY WORKS when d = 0, so set the xy if you want to rotate when it’s being rotated.
Small print: this script ONLY WORKS when d = 0, so set the xy if you want to rotate when it’s being rotated.
set x to: (((((x) - (pivot x)) * ([cos v] of (d))) + (pivot x)) + (((y) - (pivot y)) * ([sin v] of (d))))
set y to: (((((y) - (pivot y)) * ([cos v] of (d))) + (pivot y)) - (((x) - (pivot x)) * ([sin v] of (d))))
- Discussion Forums
- » Help with Scripts
-
» How to change origin