# -

You are right, that is the way the formulas look normally.

I take it the tutorial you are refering to is: etc.cmu.edu/bvw/scripting/tutorial09.html

I think the key to answering your question lies in the words: “based on the way he is turned”.
That is, the Panda is probably created or placed facing a different way than forward.

So what I think they are doing is turning the Panda.
Try typing in your formulas and see if the panda is not moving sidewards.

To elaborate a bit on the math, it turns out that (in degrees):
-cos(angle) = sin(angle + 270) and
sin(angle = cos(angle +270)

so, your panda is probably turned 270 degrees.

Now, you may wanna try using your formulas with angle+270.

Dist is just an increment. You can think of it as a radius if you like.
The thing is that dx is a small increment in x, and dy is a small increment in y. Dist is the corresponding radius or hypothenuse depending on how you view it.

Which amounts to the same as
f(90-angle) = f(360-(90-angle)) = f(270+angle)
for f(x) = sin(x) or f(x) = cos(x) , where x is measured in degrees.

I’m sorry to resurect this old topic…but what does the formulas means?

Sine and cosine are trigonometric functions. They are related to each other in several ways; one of which (as described by the above formula) is that the sine of (pi/2 - angle) is the same value as the cosine of angle.

Sine and cosine are important in 3-D math, because they can be used to rotate objects around a point. Some of the other formulas quoted in this thread that involve sine and coside are the rotation formulas.

Answering the question “what does this mean” in detail requires directing you to a trigonometry course. You can start with resources such as http://mathforum.org/dr.math/faq/formulas/faq.trig.html.

For most applications, though, you don’t need to understand trigonometry in order to write code using Panda. Panda will do the necessary math for you when you do something like nodePath.setH(45).

David

Hi,

I have been reading up a bit but I am afraid to say I still don’t understand why the cosine is negative.

From what I learn from my Computer Graphics module, when you do 3d transformations along the Y-axis (assuming that the Y-axis points upwards), you inverse the signs of the sine terms in the transformation matrix so to perserve the positive right-hand rule. So shalln’t the sine term has its sign inverted instead?

Does the negative cosine has anything to do with how the axes are in Panda3D? But I have a feeling that I am wrong.

Edit: Or it only have to do with the way the model is rotated? So let say I am working on a generic function which moves a model in the direction it is heading. How shall I go about to ensure that I am calculate the moving vector correctly?

At the end of the day, it doesn’t really matter. If you negate sin instead of cos, then the actor will travel the other direction around the circle. If you negate neither one, then the actor will start at a different point, and travel around the circle. If you reverse the x and y meaning of sin and cos, then the actor will start from yet a different point, and travel around the circle.

This all works because a circle is symmetric about every axis. Negating x is the same thing as flipping the world around the x = 0 axis; negating y flips it about the y = 0 axis. Reversing x and y flips the thing about the diagonal axis x = y.

The bottom line is, you can use sin and cos together to describe a circle. If you don’t care which direction the circle travels in, or where it starts, then it doesn’t matter which function, if either, you negate, or which one you assign to x or y,

David

By the way, all this is largely academic, since Panda has functions to rotate an object without having to know about sin and cos.

For instance, you could achieve a similar effect with:

``````# self.tiny is an Actor
dist = 1.0
arm = render.attachNewNode('arm')
arm.setX(dist)
self.tiny.reparentTo(arm)
arm.setH(angle)``````

David

If you still wonder about those formulae, and have questions about trigonometry:
feel free to pm me, and I will try to explain Wow, looks like you have buried yourself too deep under misunderstanding. Don’t give me headache.

Here, it’s just this simple:

Most people will simply orient the triangle for calculation according to the model’s heading, the Y axis towards to the model’s heading and the X axis to the right side.
Don’t think that way, coz you’re now in the 3D world.
You must respect the world’s axes, so you must orient the Y & X axis of the triangle to world’s axes.
So, ‘dx’ means the increment in world’s X axis, NOT to the model’s left-or-right side.
Then you must remember, to which direction your model’s heading when you export it, X or Y axis?
Coz once it’s imported to the Panda world, the heading will be 0 degree.

e.g your model is headed to +X axis, then you export it and put it in the scene. You think that the heading is originally 90 degrees, aren’t you?
No, it is 0 degree.

But the thing is, IPKnightly was trying to understand a certain block of code from the BVW tutorial.

The task is to calculate the Actor named Tiny’s new (global) position, such that we can use SetPos.
For simplicity, let us just consider the x-coordinate here.

If Tiny moves dist=1.0 step foreward in his local system,
how much will that change his x-pos in the global system?

It depends on his heading (an angle).

Below is my attempt at drawing the upper right quarter of a circle.
(Plz use your imagination, I am no artist).

``````
y
^
|
|
|
* * *
*         *          A
*        o|    *
*       o |       *      n
*      o  |
*     o   |          *      g
*    o    |
*   o     |                   e
*  o      |             *
* o       |                    l
*o        |              *
o * * * * | * * * * * * * * ---->  x-axis

I --------I
dx

I-------------------------I
dist     ``````

The stars are the circle. We name the radius “dist”.

This circle is placed with the center at (0,0) in a coordinate system.
Here we also place Tiny.
Now he walks straight ahead along the oooooooo-line.
From the x-axis to the ooooooo-line we measure an angle we name “Angle”.
Tiny walks a distance of dist = 1.0 (to the circumference of the circle).
How much does that change his x position?