How to place flat subject in space... This lesson is for the people, who know geometry and Flash enough.

In the lesson How to skew... we described, how to skew the movie clip.
In this lesson we shall use this method.
Let's place the flat object on the sphere.
Changing the radius of sphere and the placement of object on it,
we can cover all the points of space and all locations.
We shall begin from geometry.
Assume, that we want to place the square on the sphere.
We pick the square because the calculations with it more easier than with other geometrical figure,
and any flat geometrical figure can be covered by squares.
See pic.1.

Pic.1

Co-ordinates in space (X_{v}, Y_{v}, Z_{v}) is drawen so,
that axis X_{v} points to us.
Co-ordinates on plane (X, Y) is picked so, that axis X coincides with axis Y_{v}, and Y - with axis Z_{v}.
Let's name co-ordinates of the point M in space (x_{v}, y_{v}, z_{v}),
and co-ordinates of it on plane (x, y). Then:

x = y_{v}

(1)

y = z_{v}

Assume, we want to place the yellow square with size 1*1 by the sphere with the centre in the
point (0, 0, 0) and radius R, this square looks as parallelogram on the picture.
Let's create the rules of portrayal of the square in space:
upper and lower sides are horizontal (despite of it contradicts to perspective rules)
(if it does not spinning around its own centre), and left and right sides will be tilted by the rule,
that we shall create now. The algorithm is simple: we shall change
horizontal and vertical the sizes of our square, rotate it,
press it from up to down and turn back.
Let's figure out what the degree of squeezing the horizontal and vertical the sizes of the square.

Pic.2

Pic.3

From pic.2:

l = cos α,

because the size of the square side equals to 1, and α we can find next way:

x

cos α =

------,

R_{xy}

where:

R_{xy} =

√

x^{2} + y^{2}

From pic.3:

h = cos β,

x

cos β =

------,

R_{xz}

where:

R_{xz} =

√

x^{2} + z^{2}

Pic.4

On the pic.4 we can see the parallelogram in one of the points of the spere.
Sizes of the squares on any of the pictures do not equal to its size on the other pictures but
it does not matter for us. Let's name the left lower angle of the parallelogram by γ. Then:

h

cos β =

------,

sin γ

and γ we can find from this: tg γ is derivative of red ellipse on pic.1 in the point named by M.
Formula of this ellipse is:

x^{2}

y^{2}

------

+

------

= 1,

a^{2}

R^{2}

where R is the radius of the sphere. To find a, substitute co-ordinates of point M on plane for x and y in this formula
(let's name them (x_{m}, y_{m}),
we know them from (1)). So:

x_{m}^{2}

y_{m}^{2}

------

+

------

= 1,

a^{2}

R^{2}

and here is:

x_{m}^{2}R^{2}

a^{2} =

------------,

R^{2} - y_{m}^{2}

Assuming that we know a (actually, it is enough to know a^{2}):

/

x^{2}

y =

R√

1 -

----,

a^{2}

R x

tg γ = y' = -

---------------------

.

/

x^{2}

y =

a^{2√}

1 -

----

a^{2}

Now the last thing that we have to do. See pic.5.

Pic.5

The yellow parallelogram is the parallelogram that we want to have.
To make it from the square, we have to decrease horizontal and vertical sizes
of initial square to p and q correspondingly (we shall

m

find them), rotate on φ, squeeze

------

times (φ, m and n we have to find, too) and rotate

n

back on σ (it is marked on pic.5 by dotted arc, we shall determine it, too).
Let's calculate p and q. From similarity of the triangles ACD and CDK ([DK] is perpendicular dropped from the point named by D on the diagonal d):

d

q

------

=

------,

q

g

where g is the length of the segment [KC]. Hence:

q =

√

d g

and g we can find from the triangle ACD_{1}:

g = cos τ.

Here is:

d^{2} = l^{2} + w^{2} - 2 l w cos γ,

where d is the biggest diagonal of the parallelogram, l and w are lengths of its sides,
and cos γ is the angle between w and l. Let's calculate smaller diagonal f of the parallelogram:

f^{2} = l^{2} + w^{2} - 2 l w cos (180° - γ) = l^{2} + w^{2} + 2 l w cos γ,

and here is from the triangle-quater of the parallelogram:

a^{2}

d^{2}

------

=

------

+ w^{2} - d w cos τ,

4

4

and here is from this:

d^{2}

w^{2}

------

+ w^{2} -

------

4

4

cos τ =

---------------------------.

d w

So, τ we already have found. Let's find the angle named by φ:

g

sin φ =

------,

q

The coefficient of squeezing δ is:

m

δ =

------,

k

k =

√

q^{2} - g^{2},

m =

√

m^{2} - g^{2}.

The "back" rotation angle is:

σ = 180° - γ - τ.

All the calculations are done now. Now we are turning to Flash.
Let's create a Symbol named by FlatT. It the FlatT create a Symbol named by FlatT_, in FlatT_ - Symbol named by FlatT__,
and at last in it draw such chipped square:

. Give the names to the created objects.
FlatT__ inside FlatT_ name by mvFlatT__, FlatT_ inside FlatT name by mvFlatT_,
and FlatT on the scene name by mvFlatT. We shall use FlatT and FlatT_ for deformation
of the flat object, FlatT__ - to rotate the flat object in its own plane around its centre.
ActionScript will be inside FlatT only.
Imitation of the object named by mvFlatT in space will be made by the function
placeOnSphere(xc,yc,vn,amn,nclF,nclB,vl), where xc, yc are co-ordinates of the sphere centre,
vn - object with three fields vn.x_, vn.y_ and vn.z_ - co-ordinates of the object centre,
that we want to look like moving in space,
amn - rotation angle of the flat object in its own plane around its centre,
nclF - the color of the forward side of the flat object, nclB - the color of the back side,
and vl - the object like vn but for light source.
Variable names are very close to the names that we used in the geometrical part of this lesson.
The code of script can be optimized but after this it will not like geometrical part.
Here is the code of this function:

Internal variables of this function:
rad - sphere radius.
l_,h_,w_ - l, h, w from the geometrical part of this lesson.
vf - the object with the co-cordinates vf.x_ and vf.y_ on the plane (x and y).
tan_gamma - tg γ.
q_ - something close to q - fraction of the initial length (vertical size) of the flat object.
oe - object with the fields p_, g_, delta, fi, sigma - p, g, δ,
φ and σ correspondingly.
The field p_, like the field q_ is also fraction of the initial length (horizontal size) of the flat object.
Lines 12 - 17 are for checking of co-ordinates if they are too small, it is better to assign them to zero
to avoid inaccurate calculations.
In the line 18 we assign global variables for external using.
In the line 19 we calculate radius of the sphere on which we want to stick mvFlat.
In the lines 21 and 22 we create the object vf (co-ordinates on plane).
In the line 24 we call the function placeXYZ(xc,yc,vf), that places the mvFlat in the specific point of the screen.
In the line 26 the function mirrorM(vn) converts the mvFlat, if it is on the back side of the sphere.
In the line 28 the function def_tan_gamma returns tg γ,
if it exists, or 'i' otherwise.
The lines 29 and 30 calculate l_ and h_, the lines 31 - 42, to our mind, do not need comments.
In the line 43 the function defQ_(l_,w_,gamma,oe) returns q_,
and assigns all the fields of object oe.
Further (the lines 44 - 48) we change length and width of the mvFlatT_, and rotate it.
In the line 49 we squeeze the mvFlatT from up to down, and in the lines 50 - 52 rutate back.
Pay attention that the first time we rotate the mvFlatT_, but backwards we rotate the mvFlatT.
In the line 54 we rotate the object around its centre on the angle amn, and in 57th - light up if vl is not null.
Here is other method of the FlatT:

function attachSymbol(ssn)
{
mvFlatT_.mvFlatT__._visible=0;
mvFlatT_.attachMovie(ssn,'mvFlatTAt__',1);
}

It allows us to replace the mvFlatT__ on any object we have.
Other function we shall not describe because you can find them in
FLA.
If you have questions, do not hesitate to ask us,
we shall answer them.
How can we use it?..
Example. Flat Object On the SphereDownload
Other Example. Octahedron Download Source
Other Example.

web stte ts truly useful t ilso enjoy the look, tt's tncredtble!. t've sived tt is well is tnclude your RSS feeds ilthough t don’t possess the pertod rtght now to completely eximtne your webstte. t'll be tn two or eich diy. thinks to getttng i wonderful webstte