We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › work with koordinates of a point after rotating
Page Index Toggle Pages: 1
work with koordinates of a point after rotating? (Read 768 times)
work with koordinates of a point after rotating?
Jan 4th, 2006, 9:55pm
 
hi
is it possible to work with koordinates of a 3d-point after rotating? look here:
http://processing.org/learning/examples/rgbcube.html
the koordinates are 50, -50 and so on. but after the rotating around the x, y or z axis the koordinates has changed. i want to know the changed koordinates. is it possible??
mfg willy
Re: work with koordinates of a point after rotatin
Reply #1 - Jan 4th, 2006, 11:18pm
 
what you need to do is:
1. create a rotation matrix for each of your rotations.
2. multiply those rotation matrices in the desired order.
3. multiply your point with the resulting transformation matrix to get the 'new' position.

the detailed math to do this is covered in almost every resource about 3D graphics. here is one i like http://www.flipcode.com/documents/matrfaq.html

to understand how those things work is a real eye opener. afterwards it s easy to move, scale and rotate things in 3d space. it s worth the pain trying to understand it.
Re: work with koordinates of a point after rotatin
Reply #2 - Jan 5th, 2006, 12:48pm
 
Yes, it is possible.
In fact I wrote some code to work out how co-ordinates change after rotation. Here's the useful bits:

Code:

class Vector
{
float x,y,z;
float nx,ny,nz;
float mag;
Vector(float _x, float _y, float _z)
{
x=_x;
y=_y;
z=_z;

//calculate the normalised vector (vector of length 1)
//.. doesn't make sense for using vector for co-ords,
//but useful when an actual vector
mag=sqrt(x*x+y*y+z*z);
nx=x/mag;
ny=y/mag;
nz=z/mag;
}
}
Vector rotateX(Vector a,float ang)
{
float mz=a.z*cos(ang)+a.y*sin(ang);
float my=a.y*cos(ang)-a.z*sin(ang);
return new Vector(a.x,my,mz);
}
Vector rotateY(Vector a,float ang)
{
float mz=a.z*cos(ang)-a.x*sin(ang);
float mx=a.x*cos(ang)+a.z*sin(ang);
return new Vector(mx,a.y,mz);
}
Vector rotateZ(Vector a,float ang)
{
float mx=a.x*cos(ang)-a.y*sin(ang);
float my=a.y*cos(ang)+a.x*sin(ang);
return new Vector(mx,my,a.z);
}


And to use it:

Code:

Vector p=new Vector(50,20,-50);
p=rotateX(p,HALF_PI);
p=rotateY(p,-0.854);
println("Vector P, x:"+p.x+", y:"+p.y+" z:"+p.z);


I think this should work. I've only used it with normalised vectors, not absolute co-ordinates. But I don't see why it shouldn't work.
Re: work with koordinates of a point after rotatin
Reply #3 - Jan 5th, 2006, 4:18pm
 
great, thank you
mfg willy
Page Index Toggle Pages: 1