• Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

# Point relative to moving Origin

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

6 replies to this topic

### #1Luthur  Members   -  Reputation: 116

Like
0Likes
Like

Posted 16 January 2012 - 02:39 PM

Hey there. I'm currently working on something in c# XNA, and I have a problem I've been stuck on for ages. I have an object which can rotate 360 degrees and can move all over the screen (any x,y coordinates), in relation to an origin on the texture (the center of the texture) . The problem I have is that I need another few points which are 'stuck' to the texture, and will move only in relation to my main object. So if the texture rotates 90 degrees to the left, the other points will all rotate around the texture's origin to stay in the same relative place. I can explain better with a picture (attached). Any help here would be appreciated.

Thanks for reading, and thanks in advance.

### #2the_visualist  Members   -  Reputation: 152

Like
0Likes
Like

Posted 17 January 2012 - 10:03 AM

Its easier than you think. When you rotate the triangle you actually rotate three points around the origin. Its the same with your "Fixed Point", just rotate it around the origin. Google for transformations, to be exact for 2d rotation. Its a simple matrix multiplication with your "Fixed Point".

the_visualist
How to make a game - explained for 5 year olds.

### #3Luthur  Members   -  Reputation: 116

Like
0Likes
Like

Posted 17 January 2012 - 10:59 AM

I can't seem to get my head round this. If I have a vector with the coordinates of the origin of triangle, a vector with the coordinates for the fixed point which are, say, (triangleOrigin.X + 20, triangleOrigin.Y + 20), and the angle of the triangle, what am I applying the matrix rotation to?

### #4Net Gnome  Members   -  Reputation: 487

Like
0Likes
Like

Posted 17 January 2012 - 11:34 AM

you would need to apply it to the vector pointing to the point, so it is now pointing to the new spot.

### #5Luthur  Members   -  Reputation: 116

Like
0Likes
Like

Posted 17 January 2012 - 11:53 AM

Right so now I've got:

```point1 = Vector2.Transform(point1, Matrix.CreateRotationZ(angle));
point1 += origin;
```

Where point1 is the fixed point, and the origin is the well, origin. But this doesn't appear to do anything.

### #6the_visualist  Members   -  Reputation: 152

Like
1Likes
Like

Posted 17 January 2012 - 01:43 PM

Right so now I've got:

```point1 = Vector2.Transform(point1, Matrix.CreateRotationZ(angle));
point1 += origin;
```

Where point1 is the fixed point, and the origin is the well, origin. But this doesn't appear to do anything.

What you need to do is rotate something about the triangles origin. The something is your FixedPoint in relation to the triangles Origin, which means:
Vector something = FixedPoint - Origin; (this is called translation by the way)
Rotate(something, angle);

Afterwards you need to translate it back to where it was to get the correct coordinates:
Vector newFixedPoint = something + origin

Here is the matrix that you need for the rotation - to make sure that you are actually using the correct one:

the_visualist
How to make a game - explained for 5 year olds.

### #7compscialien  Members   -  Reputation: 104

Like
0Likes
Like

Posted 20 January 2012 - 06:50 AM

Don't forget to make sure that your angle is stored as the correct type (radians vs degrees). I know I've made many mistakes where I assumed a library uses one, but really uses the other. I believe C#'s Math.cos(double) and Math.sin(double) use radians. If so, you can use MathHelper.ToRadians(double) I believe is the name of the function.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS