Mathematic experts?

Ok, this is a tricky one -especially for me that only have lower high school mathematic knowledge.

Problem: I am having a sprite that rotates. I have to get the exact position of one corner when the object rotates. For example my object could look like this - imagine a grid where X is the position I want to keep track of when it rotates.

Object:


-------X-


What I know:

I am having the x and y position of the object. I do also have the angle of the object.

So, how do I calculate the exact position of X when my object is rotating?

Regards, Joakim [import]uid: 81188 topic_id: 19251 reply_id: 319251[/import]

simple rotation doesnt move your object, so its x stays the same

or am i missing something? [import]uid: 16142 topic_id: 19251 reply_id: 74274[/import]

You might put your object into a group, place another alpha 0 object on the position you want to track, and track the alpha 0 object using localToContent as the group rotates. [import]uid: 96383 topic_id: 19251 reply_id: 74281[/import]

Find the local coordinates of the spot, then just use localToContent.

[code]
–Create a display group, this could have been your sprite
local myObject = display.newGroup();
myObject.x,myObject.y = display.contentWidth/2 , display.contentHeight/2
myObject.bg = display.newRect(myObject,0,0,100,100);
myObject.spot = display.newRect(myObject,0,0,20,20);
myObject.spot:setFillColor(255,0,0);

myObject.spot.x, myObject.spot.y =20,40;
local globalSpotLocation = {}
–calculate global position
globalSpotLocation.x, globalSpotLocation.y = myObject:localToContent(myObject.spot.x,myObject.spot.y);
print("local spot.x before rotation = ",myObject.spot.x)
print("local spot.y before rotation = ",myObject.spot.y)
print("Global spot.x before rotation = ",globalSpotLocation.x)
print("Global spot.y before rotation = ",globalSpotLocation.y)

–rotate the object
myObject.rotation = 45;
–calculate global position
globalSpotLocation.x, globalSpotLocation.y = myObject:localToContent(myObject.spot.x,myObject.spot.y);
print("local spot.x after rotation = ",myObject.spot.x)
print("local spot.y after rotation = ",myObject.spot.y)
print("Global spot.x after rotation = ",globalSpotLocation.x)
print("Global spot.y after rotation = ",globalSpotLocation.y)
[/code] [import]uid: 33608 topic_id: 19251 reply_id: 74303[/import]

Perfect amirfl7, thats just what I was looking for. Now i can keep track of my orbiting objects :slight_smile:

Joakim [import]uid: 81188 topic_id: 19251 reply_id: 74356[/import]