View Full Version : A perpendicular to a vector

Hi,

I'm having a problem with skeleton bones. I would like to find a perpendicular to a bone.

Since I only have 2 points (pivot point and end point) what is the correct method to get a perpendicular (starting from pivot point in any direction).

I thought I could use a cross product to get a normal (which is perpendicular) but for this I need a third point, and I don't see which.

Or is there any other way ?

Thanks,

Yarp

mfort

06-20-2007, 06:13 AM

In 3D it is not possible to construct perpendicular vector to other vector. There is too much of them (unlimited). Only perpendicular plane exists in 3D.

In 2D, the p. vector is [y, -x]

k_szczech

06-20-2007, 06:39 AM

If you need that for visualisation purposes, then your best bes is eye vector.

Cyranose

06-20-2007, 06:51 AM

Yarp, mfort is correct that the set of all perpendicular vectors to a given input vector forms a uniform perpendicular disc, not a single vector.

But your case is special. In the case of bones, you generally have a parent bone and a child bone. You can simply take the cross product of the parent bone vector and the child bone vector to produce one vector that is perpendicular to both. This will essentially be the axis of rotation for that joint, or at least the axis of rotation to go from one vector to the other. And if you know that axis ahead of time, then you're done.

If you want to find the "normal" of this joint, one way would be to cross that axis vector with each of the two bone direction vectors and average the two results.

Or, just crossing the axis with the child bone gives you that bone's most "visually appealing" perpendicular vector.

Thank you all for your quick answer. Sure I understand there is not a single perpendicular to a vector. So is there a way to construct that disc from which I could extract 1 single vector ?

Cyranose, your idea is good but the problem with Bones is that they sometimes have the same alignement (take a snake for example) in which case this won't work.

My purpose is to generate a mesh around that skeleton in order to visualize it.

Cyranose

06-20-2007, 08:20 AM

You can check the magnitude of the cross product in the method I suggested. If it's too small, the bones are close to parallel. In that case, or in general, you can use what I _think_ k_szczech meant, which is to cross the eye vector (or the up vector, if you want) with the bone direction to produce a single vector perpendicular to both.

BTW, that disc can be treated as if it was a plane with a finite boundary at r = 1 from the bone's position. The disc has a normal, just as a plane would. Basic planar math applies with the boundary in mind.

k_szczech

06-20-2007, 09:11 AM

cross the eye vector (or the up vector, if you want)No, not the "up" vector. I meant the "forward" vector of camera. This will produce one axis, and vector perpendicular to this axis and the bone will produce another axis. Third axis is the bone itself.

Now you can transform any geometry into this bone's space. Note that this geometry will rotate around bone depending on camera view. If it's a cylinder it's no problem.

Or you could just skip second axis and render symbol of bone (an arrow for example) in 2D.

If you want some more fancy geometry then you should build transformation matrices for every bone (I assume your bones are organized as a tree).

Yes, I was thinking to the last solution you suggest (using transformation matrix). Since I cannot make sure all skeletons will face the camera I think it is safer.

Thank so much for your explanations, it helped me a lot see what I have to do.

zeoverlord

06-20-2007, 01:04 PM

I just want to add that in computer animation you often directly define a perpendicular vector in the form of a rotation axis.

You even directly use alignment nodes to make sure things like knees point in the right way.

Yes, that's what I did in the end.

I compute the angle between a bone and the X, Y and Z axis. The one with the smaller angle gives the rotation axis, the one with the larger is the perpendicular axis. So I just rotate around 1 axis, it is simple and works fine.

btw What are alignment nodes ?

zeoverlord

07-04-2007, 09:50 AM

Originally posted by yarp:

btw What are alignment nodes ? Null objects that help IK bones align properly.

They are there to make sure that during a walk cycle the knees don't start pointing outwards when bent, which they in theory could IRL but we don't usually do that (unless we are ninjas that is).

Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.