Notifications
Clear all

[Closed] Simple Trigonometry with MAXScript?

I’ve been having a lot of trouble with a project, so I am currently trying to break it down into as simple a form as possible.

www.versatileartist.com/temp/trig_test02.max
(this file requires MAX 9… if someone needs me to, I can replicate it in an earlier version)

GOAL:
In this file, I am trying to make a triangle out of 3 cylinders, such that i can move the corners around and have them remain a triangle.

(To make things easier, the triangle in question is a right triangle… once I get that working I can move on to more complicated stuff – joy! :P)

The pink cylinder (CA) uses a LookAt constraint to keep at the proper angle. I need to write a script for the X Rotation of the blue cylinder that will put it at the same angle (making the blue cylinder the third side of the triangle).

Max already reads the angle in radians, and I thought it would be AB/CA, possibly with a + or – degToRad(90) to compensate for the starting angle… it’s been years since I had a trig class, but from what I have found online that seems to be right. In case I mixed it up I tried all number of variations using various expressions involving the sides, but no joy.

I know that MAXScript already includes expressions for sines, cosines, and tangents, but I can’t see any way to apply them.

NOTE:
I am controlling the lengths of the cylinders with a simple script in the object properties which defines the positions of the corners and the lengths of the lines.

9 Replies

I read the post, loaded the scene and still don’t understand what exactly you want to do.
You already have a triangle ABC. What should happen to the blue cylinder? Match the pink one? But if the pink one already works, why the troble?

Some more detailed step-by-step explanation (possibly with small illustrations) might be helpful.

Normally, you should be using simple vector math and possibly dot and cross products to get anything you want in this case. To get an angle between two vectors, just get the ACOS of their DOT product as explained in the MAXScript Reference in the Point3 Values topic.

Messing with rotations is normally a pain, setting the .dir property of the node to align its Z axis to a vector is usually the easier solution, otherwise constructing a matrix3 value is the way to go. (See my signature for a good but expensive source of MXS trig knowledge)

If you have 3 point helpers, you can place each cylinder at one point, set its height to the distance to the next point (as you are already doing), then set its .dir property to the vector defined by the next point minus the starting point.
In other words, a cylinder from B to C would be positioned at B and have its .dir property set to (C-B) and its height set to length(C-B). This implements a custom LookAt. You can, of course, just assign a point helper or any other node to the .lookat property which automatically assigns an old-style (pre-Max-4) LookAt controller.

If I am missing the point with these suggestions, please advise.

I actually just bought this yesterday Bobo! Looking forward to the fun.

When’s the next one due? (hint hint).

2 Replies
(@bobo)
Joined: 2 years ago

Posts: 0

When I finish it – (un)fortunately, another project for a large software company is keeping me very busy right now (hint hint)

(@erilaz)
Joined: 2 years ago

Posts: 0

Ah… gotcha! I’d better get back onto testing that! I’ve been a bit slack…

Ah, Bobo’s here! Always good to have help from a pro.

This is part of a bigger project, and while the LookAt solution works just fine for the simple right triangle, I run into trouble when I try and use the rotation of a LookAt-constrained object as a variable in other scripts.

Take a look at www.versatileartist.com/temp/trig_test03.max

The blue box is set to use the rotation of the blue cylinder, the pink box is set to use the rotation of the pink cylinder… the blue one works, the pink one does not. The x, y, or z rotation of a an object using a LookAt constraint seems to always come up as 0 when used as a variable. Perhaps there is simply some different kind of notation to make it work?

The next step after this will be to try and get this working…
www.versatileartist.com/temp/pca_trig02.max

Taking a look at these two animations:
www.versatileartist.com/temp/PCA_Test04.avi
www.versatileartist.com/temp/PCA_Test05.avi

In the second animation I manually put the targets from where they go by default to where I want them. I can’t have the bones crossing over each other. So basically, I am dealing with triangles that each have 2 sides unchanging in length, and a third that does.

I am completely open to the possibility of doing this some other way (preferably one that is easier, but I will settle for one that works!)

I’m not entirely sure how this scene (trig_test03.max) relates to the avi’s in your post, so I might have misunderstood what you’re after. But why don’t you simply link the pink box to the pink cylinder?

In the meantime, I’d suggest reading the Using Script Controllers topic in the MAXScript reference. In particular the section about Variables. You have set up your controllers “the old way”, max 9 has a much better way of dealing with object references.

Cheers,
Martijn

Here is my problem, which the other file is meant to help me figure out:

http://www.versatileartist.com/temp/pca_trig1.avi

That, basically, is what I am trying to make happen.

I’ve attached a max file (max 9) in which I have created a setup as shown in your avi PCA_Test05.avi. There are 4 IK chains (HI Solvers) in the scene and I’ve parented the IK goals of those chains to a dummy. Move the dummy around to see the effect. I hope this is what you’re after

Cheers,
Martijn

Okay, I feel like I am back where I started… see the thread at http://www.3dbuzz.com/vbforum/showthread.php?t=151793

if you can get your setup so that

  1. Bone02 and Bone08 can only move up and down, and

  2. Bone05 and Bone11 can only move from side to side, but

  3. Bone03, Bone06, Bone09, and Bone12 still have a free range of motion and all join up at the end

then that will be what I need.