- Home /
How can I rotate an elliptical cloud of points?
I have a function that draws on a texture in an airbrush style by picking a point using Random.insideUnitCircle, multiplying by the desired radius, and drawing the pixel. This runs several times in a loop.
If I want to distort this circle of points into an ellipse, I can multiply the x and y by different amounts.
Now, is there an easy way to rotate this ellipse of potential points forty-five degrees?
Pretty sure there is a quick solution to this; maybe some sort of matrix manipulation?
Fattie, you've jumped to the wrong conclusion... And with an extra note of condescension that makes your comment irritating, as well as useless.
Try re-reading it again, man.
I am generating random Vector2's, that if plotted on a texture, describe an ellipse.
These are not objects, nor are they part of another object, its just a bunch of number pairs...
I'm looking for a mathematical operation that I can apply to such a group of points.
Well, I'm sorry you are so angry. In fact, it's a shame because you can do it exactly as I describe. Often you use empty game objects (think of it as a "calculation area") in exactly this way
Just do this..
make an empty object...
add each new point as a empty object at that point...
you're done, now rotate the object as you like. by any degrees. you can even skew it, etc. read off the points. it's no different from putting them in an array, and multiplying by sin
:O
Sorry you are so sore.
I think it might have been the part where you felt you needed to explain what 'easy as pie' meant... If you didn't mean to be snarky, I apologize.
not at all ! I was just talking to someone else on this list who was asking about bizarre English phrases and so I explained it. "She'll be right mate!:" :)
Answer by MadDave · Sep 10, 2012 at 05:07 PM
http://en.wikipedia.org/wiki/Rotation_matrix
Unity has just a Matrix4x4 but you can easily extend your Vectors to four dimensions.
Yes, I think I just figured out how to do it more simply, yet more complicated...
Basically, what I need to do is create a 2x2 matrix in this manner:
cos(angle) -sin(angle)
sin(angle) cos(angle)
Then, you plug in the X and Y into this formula (breakdown of the product of a 2x2 and a 1x2 matrix):
For X: (cos(angle)*x) + (-sin(angle)*y)
For Y: (sin(angle)*x) + (cos(angle)*y)
For my rotation -45 degrees, the matrix looks like this:
0.707 0.707
-0.707 0.707
And my equations actually become:
For X: (0.707*x) + (0.707*y)
For Y: (-0.707*x) + (0.707*y)
This seems to work, plugging in 0,1 ends up with 0.707, 0.707, and plugging in 1,1 ends up with 1.414, 0...
And please allow me to add: I wish I had paid more attention in math class! I should have known this; and probably did, years ago. :)
This whole thing about matrices seems almost like magic... I think anyone who is program$$anonymous$$g should be aware of this, and how useful it can be!
Don't let the whole 4x4 matrix deal blow your $$anonymous$$d; it did to me at first, too. Start with trying to get the gist with a smaller matrix, like the basic 2D transforms (such as the rotation I describe above), and it will begin to crystallize... ;)
Answer by Eric5h5 · Sep 10, 2012 at 10:29 PM
Personally I'm fond of using a transform to make Unity do all the math stuff:
var points = [Vector2(0, 10), Vector2(5, 5)];
transform.position = Vector3.zero;
transform.eulerAngles = Vector3.forward * -45;
var matrix = transform.localToWorldMatrix;
for (point in points) point = matrix.MultiplyPoint3x4(point);
Your answer
Follow this Question
Related Questions
Camera rotation around player while following. 6 Answers
rotate smooth toward vector defined by controls 1 Answer
How do I animate a texture to rotate and loop around an imported object? 1 Answer
How can i rotate the aircraft elevator around the yellow axis up and down ?? as shown in the pic 0 Answers
camera rotate with limitation around x and y axis by using touch 0 Answers