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.
Co-ordinates in space (Xv, Yv, Zv) is drawen so,
that axis Xv points to us.
Co-ordinates on plane (X, Y) is picked so, that axis X coincides with axis Yv, and Y - with axis Zv.
Let's name co-ordinates of the point M in space (xv, yv, zv),
and co-ordinates of it on plane (x, y). Then:
x = yv
y = zv
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.
l = cos α,
because the size of the square side equals to 1, and α we can find next way:
cos α =
x2 + y2
h = cos β,
cos β =
x2 + z2
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:
cos β =
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:
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 (xm, ym),
we know them from (1)). So:
and here is:
R2 - ym2
Assuming that we know a (actually, it is enough to know a2):
tg γ = y' = -
Now the last thing that we have to do. See 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
find them), rotate on φ, squeeze
times (φ, m and n we have to find, too) and rotate
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):
where g is the length of the segment [KC]. Hence:
and g we can find from the triangle ACD1:
g = cos τ.
d2 = l2 + w2 - 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:
f2 = l2 + w2 - 2 l w cos (180° - γ) = l2 + w2 + 2 l w cos γ,
and here is from the triangle-quater of the parallelogram:
+ w2 - d w cos τ,
and here is from this:
+ w2 -
cos τ =
So, τ we already have found. Let's find the angle named by φ:
sin φ =
The coefficient of squeezing δ is:
q2 - g2,
m2 - g2.
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:
It allows us to replace the mvFlatT__ on any object we have.
Other function we shall not describe because you can find them in
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
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