Jump to content

The Algorithm Of Bending?


Symbolic

Recommended Posts

Hi,

I started to watch the cmiVFX - VEX Vol1 DVD.

I have to say that It is a great and very important learning material.

But I got confused about the first example, the BEND example. I am not good in maths, so I tried to refresh my trigonometry but still could not figure out some of the formulas at the very beginning of the "Bend" example. Could you please help me!?

Here is an image that I did to try to explain the issue to my self. And I figured out some of the things. But there are still parts that are not clear.

bend.gif

So If you have seen the example, could you please help me to find answer to the following questions:

1) How we get R = x - xp ?

Isn't it supposed to be something related to sq(A) + sq(B) = sq R

2) What is "theta" and "thetamax" in that example?

3) How we get the following relation "theta / thetamax = (z - cz) / (zmax - cz)"

4) How we calculate "theta" for each point?

5) How do we use the xmax, xmin, zmax, zmin values?

//

If you have not seen the example, the code takes each point and moves it to a new position by keeping the R constant. So the object gets bent.

Maybe someone can still explain how this works for each point?

//

I hope that I am not violating any copyright terms by posting this question. I tried to keep it in the realm of Maths. as much as possible.

The example belongs to cmiVFX, but the algorithm should be a common maths. issue.

Thanks for your help and time.

Edited by Symbolic
Link to comment
Share on other sites

I started to watch the cmiVFX - VEX Vol1 DVD.

I have to say that It is a great and very important learning material.

But I got confused about the first example, the BEND example.

Hi Symbolic,

I wouldn't worry about violating copyrights since I don't believe anyone holds a copyright to rotations yet (though you never know these days :)).

Anyhoo... I don't own that dvd, so I don't know how they're going about explaining things, but rotation on a plane is:

x' = (x-px)*cos(th) - (y-py)*sin(th) + px

y' = (x-px)*sin(th) + (y-py)*cos(th) + py

where [x',y'] is the resultant position after rotation, [x,y] is the point being rotated, th is "theta" or the angle of rotation, and [px,py] is the pivot (or center of rotation) and can be ignored if you know you're working with everything already centered at [0,0].

There are at least two ways (that I can think of) to derive the above. For me, the easiest way to think about it is to imagine that, instead of rotating a point, you're expressing the old point in a new frame (two new axes) rotated by the negative of the angle (i.e: think of it as transforming the point to a new, rotated space). So that if the two axes of the old frame were {[1,0],[0,1]} (which are the standard X,Y axes), you'll see from simple trig (don't have time to draw a diagram for you, but just make right-angle triangles between the new axes and the old, and solve -- keep in mind these are unit vectors so everything collapses to just sin and cos) that the two new axes (unit-length vectors) will be {[cos(th),-sin(th)],[sin(th),cos(th)]}. Now to transform the point to the new space you just just take the dot product of the old point with each of the new axes, giving you:

x' = x cos(th) - y sin(th)

y' = x sin(th) + y cos(th)

Which is the same as above, except it assumes that the center of rotation (or "pivot") is at [0,0]. If it isn't, then you need to first translate everything so that it's centered at [0,0] (old_position - pivot_position), calculate the rotation as above, and then translate it back to where it was originally (rotated_position + pivot_position), leaving you with the final formula as written at the top.

Also note that it's more efficient to represent this whole transformation as a matrix if you intend to apply it to many points.

Now, "bending" is simply a common rotation (as above) but whose angle of rotation varies according to the distance of the point to the center of rotation (or pivot). Points that are further away from center will bend (rotate) more than points nearby. This means we have to associate the amount of rotation ("th") with the distance of the point to the center -- i.e: th becomes some function of distance, and "distance", or "radius" is given by radius=sqrt((x-px)^2+(y-py)^2) -- keeping with the assumption of a possibly floating pivot.

For example, for a linear relationship (linear falloff), you'd replace every instance of the angle "th" in those equations above with "th*radius". This will rotate every point at a distance of 1 unit from center by the angle "th"; all points further away than 1 unit will get progressively more rotated, and all points closer to the pivot will get less rotated (all the way to no rotation at the center) -- and the relationship between the amount of rotation and the distance from the pivot is, as you can see, linear -- i.e: the amount of rotation is directly proportional to the radius, so that if you were to plot it you'd see a straight line.

For a more natural-looking kind of decay, you might try

1-exp(-radius/stiffness)

where "stiffness" is some value greater than zero, and which has the effect of stiffening the region around the center of rotation more or less. The relationship of rotation-to-distance in this case is exponential (which is generally a little more "natural" than a linear decay).

Here's a hip file (H9.1.139) with the above implemented in a point sop so you can see it put together and experiment (just go into /obj/geo1/point1 and play with the "Pivot", "Angle", and "Stiffness" parameters) -- the formulas are as I give them above except harder to read because of all the "$TX" and "ch()" calls, but otherwise identical.

testBend.hip

HTH. Cheers.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...