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 & HelpSyntax Questions › distort a bezierVertex shape
Page Index Toggle Pages: 1
distort a bezierVertex shape (Read 1954 times)
distort a bezierVertex shape
Jan 21st, 2010, 12:03pm
 
Hi

Is there a method to deform a rectangle like an italic in typography?
I saw that there was a topic to do this with a cube, but I think it does not match what I want to do...

thanks!
Re: distort a bezierVertex shape
Reply #1 - Jan 21st, 2010, 12:33pm
 
If you mean shearing, maybe you can do that with a transformation matrix.
Or, since it is quite simple, just draw it with beginShape(), etc.

Please, delete the extra posts due to a forum glitch, thanks.
Re: distort a bezierVertex shape
Reply #2 - Jan 21st, 2010, 12:40pm
 
Thank you! i'm going to try this

Sorry for the extra posts, I've deleted them
Re: distort a bezierVertex shape
Reply #3 - Jan 21st, 2010, 1:58pm
 
hum...
I believed to have understood, but I haven't....
Have you got a link to show me an example?

I would to do this :
...

I don't know if it's "shearing" (i'm not english...)

thank you
Re: distort a bezierVertex shape
Reply #4 - Jan 22nd, 2010, 1:27am
 
Ynk wrote on Jan 21st, 2010, 1:58pm:
I don't know if it's "shearing" (i'm not english...)

Neither me... I learned the term when dealing with compute graphics. See for example: Shearing definition. It is also called slanting.

Let's go the easy way:
Code:
final int MARGIN = 100;
final int WIDTH = 200;

void setup()
{
 size(500, 500);
}

void draw()
{
 background(255); // First, clear the screen
 
 // Visual parameters
 fill(#000088); // Dark blue
 stroke(#000055);
 strokeWeight(3);
 
 float amount = (float) mouseX / width; // Using mouse position as parameter
 float offset = WIDTH * amount;
 
 beginShape();
 // Bottom left
 vertex(MARGIN, height - MARGIN);
 // Top left
 vertex(MARGIN + offset, MARGIN);
 // Top right
 vertex(MARGIN + offset + WIDTH, MARGIN);
 // Bottom right
 vertex(MARGIN + WIDTH, height - MARGIN);
 endShape(CLOSE);
}

Note how I used constants to avoid hard-coding numbers in the source, thus making easy to change them.

[EDIT] I just noticed your title, your initial message was not mentioning bezierVertex, you talk about simple rectangle.
We might go the matrix way for more complex stuff.
Re: distort a bezierVertex shape
Reply #5 - Jan 22nd, 2010, 7:05am
 
http://mathforum.org/mathimages/index.php/Transformation_Matrix
http://www.imagico.de/imenu/insert_menu.html#226
http://processing.org/reference/applyMatrix_.html

For shearing, using matrices, you should use something like this:

Code:
float f = 2; //shear factor

pushMatrix();
applyMatrix(1,f,0,0,
           0,1,0,0,
           0,0,1,0,
           0,0,0,1);
rect(0,0,100,100);
popMatrix();


(in this example it is a shear of X on Y)
Code:
float f = 2; //shear factor

pushMatrix();
applyMatrix(1,0,0,0,
           f,1,0,0,
           0,0,1,0,
           0,0,0,1);
rect(0,0,100,100);
popMatrix();

(in this example it is a shear of Y on X)

Code:
float f = 2; //shear factor

pushMatrix();
applyMatrix(1,0,0,0,
           0,1,0,0,
           0,f,1,0,
           0,0,0,1);
rect(0,0,100,100);
popMatrix();

(in this example it is a shear of Z on Y)

In general, all those possibilities will result in a shear effect:
Code:
applyMatrix(1,f,f,0,
           f,1,f,0,
           f,f,1,0,
           0,0,0,1);


You have 8 possible shearing

shearXY
shearXZ
shearYX
shearYZ
shearZX
shearZY
Re: distort a bezierVertex shape
Reply #6 - Jan 27th, 2010, 5:55am
 
thanks for your answers, it will help me a lot
I'll give you a feedback soon
Re: distort a bezierVertex shape
Reply #7 - Jan 29th, 2010, 10:05am
 
ok, it works. thanks
There is a problem that I didn't think so : the shape is transformed, but it moves too and I don't reach to "compense" this to get it static (original position)...

and ever the same problem with controlP5 and P3D... argh
Re: distort a bezierVertex shape
Reply #8 - Jan 29th, 2010, 11:53am
 
It is probably like for rotate(), you need to translate to origin point, the one that shouldn't move. I think you can put the translation in the matrix along with the shear parameters.
Re: distort a bezierVertex shape
Reply #9 - Jan 29th, 2010, 2:10pm
 
ok, but parameters of applymatrix are obscurs for me. At what correspond parameters n00 to n15? Is there a notice more complete than http://processing.org/reference/applyMatrix_.html ?
Re: distort a bezierVertex shape
Reply #10 - Jan 29th, 2010, 2:35pm
 
It's your matrix:

[n00 n01 n02 n03]
[n04 n05 n06 n07]
[n08 n09 n10 n11]
[n12 n13 n14 n15]

http://en.wikipedia.org/wiki/Matrix_(mathematics)
http://en.wikipedia.org/wiki/Transformation_matrix

This is a system of equations expressed in a mathematical object. With XYZ you would have a matrix of 3x3, which is enough to represent rotations and scales. This is not enough to represent translations, you need one extra colon (4x3). OpenGL is using 4x4 for projections (basically dealing with view). You may have a look at OpenGL matrices to learn more about it. It is quite a standard in computer graphics.

Why would you need to use matrix when you could calculate them individually (for XYZ with a sequence of operations like x+1,y+2,z+3) The nice thing with matrices is that you could express your transformations in the same general form for usual transformations and then apply them sequentially (concatenate them in one resulting matrix containing all the transformations).

You could say: MatrixTranslate x MatrixRotate = MatrixComplexTransformation

I think that this part remain more obscure for many of us. It's quite complex stuff, not very intuitive. I find it difficult to deal directly with matrices. But you may see it as a set equation with a number of unknowns elements where you want to calculate the resulting XYZ coordinates after a transformation.
Re: distort a bezierVertex shape
Reply #11 - Jan 29th, 2010, 2:55pm
 
ok ok... it seems difficult but thanks for you explanation
=)
Re: distort a bezierVertex shape
Reply #12 - Jan 29th, 2010, 3:10pm
 
Ok, let me try to give a shorter answer then with code.

Let's say that you want to create something like rotateX() using applyMatrix() by your self. In fact, what you have behind rotateX() in processing is something like this:

Code:
void myRotateX(float angle){
 applyMatrix(1,0,0,0,
 0,cos(angle),-sin(angle),0,
 0,sin(angle),cos(angle),0,
 0,0,0,1);
}


Now, if you call myRotateX, this will be equivalent to rotateX.

For shearing:
Code:
void myShearYX(float f){
 applyMatrix(1,0,0,0,
 f,1,0,0,
 0,0,1,0,
 0,0,0,1);
}
Re: distort a bezierVertex shape
Reply #13 - Jan 29th, 2010, 4:57pm
 
i understand now, thanks gll...!
Page Index Toggle Pages: 1