A Flash Developer Resource Site

# Thread: Basic Trigonometry: flipping an image around a Y-axis. ??

1. ## Basic Trigonometry: flipping an image around a Y-axis. ??

Hi,

I have this code that rotates an object (a square) around a y axis.
Code:
speed = 5;
xcenter = 275;
zcenter = 100;
angle = 0;
fl = 100;
}
onClipEvent (enterFrame) {
scale = fl/(fl+z);
_xscale = _yscale = scale*100;
angle += speed;
}
The problem is that I want the object to flip around as it goes around the radius (so that the user will see the reverse side of the square). I've tried using -Math.sin() on the _xscale but it's not perfect.

2. Code:
_yscale = 100*scale;
_xscale = 100*scale*Math.sin(angle*Math.PI/180);
this will scale it so it flips around, so that when it is "furthest" away, you see the reverse of the mc. But i looks a bit "off" because it remains a rectangle always, but it would have some perspective really. See what i mean? At least it's a start though.

No idea how to do the perspective, other than what ericlin said about masks on the other recent thread on this board.

Oh, and that code could be optimised a bit. But i guess the standard practice is too concentrate on that when it's all working properly!

3. ## Rotating around y axis

This is my second attempt to respond....

There are two effects. Your code accounts for the scaling down due to the object being farther away. The other effect, which works only on the x axis, is due to viewing the object (which I'm assuming is 2-dimensional) at an angle. You need to multiply _xscale ALSO by cos(angle).

There are other interesting issues here. You seem to have the viewer positioned pretty close to the path of the object. The code you've got (with the correction I've suggested) is really for a viewer very far away. You nearby observer will, for instance see the object move across the field of view faster from L to R than vice versa. And the angle between the object and the line of sight is not really "angle".

Try it anyway, you'll probably be happy with it. If you want to account for some subtleties, try something like this: (my f is your fl)

onClipEvent (enterFrame) {
scale = f/d;

// Tangent of the angle displaced left or right

// Angle at which object is viewed is angle + alpha. We compute its cosine.
foreshortening = (Math.cos(angle*Math.PI/180) - tanalpha * Math.sin(angle*Math.PI/180)) /Math.sqrt(1 + tanalpha*tanalpha);

// A constant related to the distance from eye to screen. See what looks good.
screenfactor = 2.3
_x = screenfactor* f * tanalpha + xcenter;
_yscale = scale*100;
_xscale = -_yscale * foreshortening;

angle += speed;
}

4. Thanks for all your help guys.

mkantor, thanks for trying to help - although your explaination is great - it's a little over my head. I've pretty much got the globe to rotate along the y-axis.

Cheers

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap