# transformation problem

This topic is 4056 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

HI I have a circle with multiple lines passing through the center. Currently i am able to select and grab the circle as a whole( along with the lines) and the individual lines and move them around space. I want the motion of the lines to be restricted to the plane in which the circle is currently drawn and they should also be able to rotate around the center of the circle but only in the plane defined by the circle. How to go about it? For the coding part i have individual matrices for each line which is shown and a separate matrix for the circle. I am attaching an image in case u guys want to visualize it. Please help

##### Share on other sites
I don't know what your ultimate aim is or what your constraints are etc., but one approach could be to represent each line using 2d polar coordinates (r, theta)-(r, theta + Pi) which will naturally give you lines constrained within a 2d circle and drawn through the circle centre, then just apply the circle rotation matrix to the resulting points to transform them to your required 3d position and orientation. If you need to go from 3d to 2d then you can apply the inverse of the circle rotation matrix to the points first.

##### Share on other sites
i really apologise if i wasnt able to convey my problem in an effective manner. Well as for my ultimate aim, this diagram represents a consraint space where the individual lines are constraints which may be applied to the body. This is a space which has a characteristic wherein all lines which belong to this space pass through a common point ALWAYS, no matter what the orientation of the circle is in space. therefore the lines must follow this and always pass through the center and as this space is more like a disc(there are others which are 3D too) the lines are also supposed to fall in this plane ALWAYS. So what i need to do is 2 things

1. Constrain their motion to this plain only. they cannot be moved in any other plane.

2. Make them pass thru the center always.

i think it makes sense now. Now if i define my lines in polar coordinates as you said would they only move within the plane of this circle always? Even if i select them and try to move them anywhere else ?

##### Share on other sites
Ok, with that extra info I don't think polar coords will be of use to you. I think you have a few options, including:

- As I mentioned before if you apply the inverse of the circle matrix to your points then naturally all of your points will be "untransformed" into the reference frame they would lie in if the circle matrix was always identity. You can then manipulate them in 2d (you'll need to transform your mouse movements into this new reference space too), then re-apply the circle matrix to the manipulated points to get them back into their current reference frame.
- Or transform your mouse's movements into the circle's current reference frame then manipulate the points in this reference frame directly. It may be harder to constrain things in this reference frame though, depending on how you have things set up and what information is available.

##### Share on other sites
Hi i have doubts

1st. When you say "points" do you mean to say the end points of the individual line segments ?

2nd. The circle matrix doesnt always remain identity and as soon as i select it and start moving it around space it changes. It is a gmtl::Matrix44f type.

3rd. So now as the circle matrix is not remaining identity always and is having its own matrix, does what you said still holds true?

4th. By "reference frame" do u mean the local coordinate system of the circle ?

Actually to tell u more about the code.

1st. This circle is made using polar coordinates. I calculate each point of the circle using radius * Cos theta , radius * Sin theta. I get individual points of the circle and store them in a vector. In the draw function i just display them. Making the circle this way helps me in collision detection as i can check the position of the mouse with each point of the circle and if its close enough i can grab it and move it. Initially the circle matrix is identity but as soon as i start moving it it changes as per the orientation.

2nd. The lines are given their initial position wrt the circle points. I draw a line on each circle point passing through the center. I have a line class and every instance of the line has its own matrix which is initialized as identity. But then too when instead of selecting the circle i select any line and start moving it its matrix also changes as per the orientation.

##### Share on other sites
1. Yes
2. I realise that. What I am saying is that initially your circle matrix is a 4x4 identity matrix I assume (i.e. before you have started moving / rotating it around). To get the local space position of a point on your circle you can multiply it's original position by this circle matrix. You can also multiply the point's transformed position by the inverse of the circle matrix and it will transform the point back to where it would be if the circle matrix was still an identity matrix. The reason for doing this is that depending on what you are doing you may find it easier to manipulate / constrain your lines on their original untransformed plane.
3. Yes
4. Yes. Objects in 3d space can be considered to have a reference frame which describes their current orientation - this is usually the 3 orthogonal vectors emanating from the same position that form the objects current local x,y,z axis vectors.

I don't think I am following what your inputs are, and what sort of manipulations you are trying to do etc. very well. I am not sure why you need a matrix per-point as essentially your points as described are 2d and initially lie on the plane of the circle anyway, so you can just transform them by the circle matrix to get their 3d local space position - they would always be on the circle's plane then.

##### Share on other sites
my init and draw functions

circle init
gmtl::Point3f tempcirclePt;	for(float i = 0; i <= 2*PI; i += 0.1){   tempcirclePt[0] = radius * gmtl::Math::cos(i);   tempcirclePt[1] = radius * gmtl::Math::sin(i);   tempcirclePt[2] = 0;      mpApp->circlePoints.push_back(tempcirclePt);}//the circle matrix is initially identitygmtl::identity(object->objectMatrix);

lines init
for(mpApp->circlePtIter = mpApp->circlePoints.begin(); mpApp->circlePtIter < mpApp->circlePoints.end(); mpApp->circlePtIter ++){		    if(size - index < 4)	break;    tempLinePt = mpApp->circlePoints[index];    //the origin and the direction of the lines    myLine = new Line(tempLinePt[0], tempLinePt[1], tempLinePt[2], 0, 0, 0);    gmtl::identity(myLine->lineMatrix);    allLines.push_back(myLine);    //draw a line on every 4th point of a circle    index += 4;}

circle draw
for(mpApp->circlePtIter = mpApp->circlePoints.begin(); mpApp->circlePtIter < mpApp->circlePoints.end(); mpApp->circlePtIter ++){	gmtl::Point3f tempPt;	gmtl::Point3f tempPt1;	tempPt  = mpApp->circlePoints[index];	if( tempPt == mpApp->circlePoints.back() )               tempPt1 = mpApp->circlePoints.front();	else		tempPt1 = mpApp->circlePoints[index + 1];        glBegin(GL_LINE_STRIP);		glVertex3fv(tempPt.mData);		glVertex3fv(tempPt1.mData);	glEnd();	        index ++;}

line draw

i check while drawing the lines that if it is being moved individually calculate the matrix of the line in a different way(islineSelected) else if it is being moved along with the circle then just multiple it with the line matrix.

for the first case when isLineSelected is true, i post multiply the inverse of the current circle matrix which makes the line go back to the origin of the world, then i rotate it 2 degrees in the z direction(as i had defined the circle initially in XY plane) and then multiply it again by the current circle matrix to position it where it was previously wrt the circle
if(myLine->isLineSelected == true){	glPushMatrix();			   	glMultMatrixf(object->inverseObject.mData);	glRotatef(2.0, 0,0,1);		   	glMultMatrixf(object->objectMatrix.mData);	glBegin(GL_LINES);	glVertex3f(lineSeg.mOrigin[0], lineSeg.mOrigin[1], lineSeg.mOrigin[2] );	glVertex3f(lineSeg.mDir[0], lineSeg.mDir[1], lineSeg.mDir[2]);	glEnd();	glPopMatrix();}else{	glPushMatrix();	glMultMatrixf(myLine->lineMatrix.mData);		glBegin(GL_LINES);	glVertex3f(lineSeg.mOrigin[0], lineSeg.mOrigin[1], lineSeg.mOrigin[2] );	glVertex3f(lineSeg.mDir[0], lineSeg.mDir[1], lineSeg.mDir[2]);	glEnd();	glPopMatrix();}

Still it doesnt seem to work

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633654
• Total Posts
3013168
×