We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi forums :)
I'm new to 3D and can't get my head around this very basic 3D logic problem. Say I have two 3D vectors, and I want to draw an elongated box or rod connecting the two. How? In 2D it's easy - get the angle with simple trigonometry, push matrix, rotate, draw, pop matrix.
I understand that in 3D two angles are needed, and I've come across some different ways of calculating them. I can't get any reasonable results though - I think because the first rotation rotates the entire system and makes that second angle I calculated invalid.
Another way of wording it - how can I align the matrix's rotation with a specific unit vector?
What I get:
What I want:
(images stolen from here: https://forum.openframeworks.cc/t/rotate-3d-object-to-align-to-vector/5085 , this guy had the same problem but that environment could be asked to rotate along an arbitrary axis which doesn't seem possible in processing)
Answers
Oh, I solved it! What's the etiquette around here, should I delete the thread or just post my solution for others to see?
For now I'll post it:
This code draws a sphere at pos, and an elongated box between pos and parentPos.
Just found the formulas in an old project, maybe still helpful, since i cannot run your code.
Yes, post solution for others unless homework
@benja: Woe, this is amazing. What does this sketch do?
Let the box look at the sphere wherever you move it?
btw the old 2D line command has a version with 6 paramy which is in fact a 3D version. It looks crappy though.
additionally let me mention a 3D-ine by James :
:)
Impressive!
Kf
amazing. It is like a tree in space. A star tree.
I think Dan Simmons has an Orbital that's a growing tree around a sun. He calls it star tree. IIRC.
@benja:
I tried to add to your sketch a Z-component for the sphere, and I don't think that works really. Could you improve that for me please? Or have I made a mistake?
To invoke the z component of the sphere you need to hold a key while moving the mouse vertically.
At first the sphere is to near towards you then, so you have to move the mouse UP
Thank you!
Best Chrisir ;-)
I see what you mean, you ave to adjust yaw, if direction is facing positive z-values. Try this:
[...]
[...]
@JLJac: looks great :)
Not quite so solved after all :(
Even rotation on the XY plane, and Z angle attached to moouse. That perpendicular line is supposed to be in the same direction and not wobble.
There's some strange rotation going on along the Z axis. I vaguely recognize the pattern (could it be a tangent?) but I'm too bad at trigonometry to figure out exactly what's going on. If I could figure out the formula for the wobble I could just apply the opposite rotation. I've tried brute forcing the problem (applying a bunch of random trigonometry operations to that z rotation) but to no avail.
Here's what my code looks like:
Any ideas?
You asked for ideas, so here- http://inside.mines.edu/fs_home/gmurray/ArbitraryAxisRotation/