# Implement own Bend function

I'm trying to write a mesh deformer that bends a Cube around an axis like this: The bend degree in figure A is 90 and something like 35 in B. So if I know my desired bend degree how can I get alpha?

I know that the distance between the vertices v1 and v2 stays the same and that i basically just have to rotate the edge alpha degrees. I can't figure out where the center of the Circle has to be, so that the bend looks organic.

• Looks like simple trigonometry to me, if you consider that the two triangles are mirror images of each other. The triangle (v1, v2, middle) is isosceles and you know both the length of v1-v2 and the angle defined by (v1, middle, v2), so you should be able to calculate both v1-middle and alpha. – Quinchilion Jun 10 '16 at 14:45
• I don't know where middle is, though. I only have the vertices of the cube and a degree by which I want it bend. – lega Jun 10 '16 at 15:00
• If you know where v1 and v2 are, you can calculate where 'middle' is from the requested angle. If you don't, can you clarify the problem? I see no cube in the picture. – Quinchilion Jun 10 '16 at 15:45
• prntscr.com/ber3a7 that is input and result (with a 45° angle). Those are Screenshots from Cinema4D's bending tool. As you can see the 45° is the angle of the topmost edge of the cube. The bending process strectches the sides but not the 'spine' of the object. I'm trying to emulate the tool in code with a given Mesh. – lega Jun 10 '16 at 15:55

It's easy to work out if you consider not that case but the angle at v3 (if the "cube" were continued past v3). By the time you get to v3, the angle is simply the desired bend angle. (That's not quite right, though: because you've got alpha on the decreasing side, it's 90 degrees minus the desired angle.) You have to split that angle equally among all the segments going along the bend direction, so the angle alpha is simply 90 degrees minus (the desired angle divided by the number of vertices). So for A, where the requested angle is 90 degrees, each vertex gets a third of that angle: alpha is (90 - 30) degrees.

For cube B, if the total bend is 35 degrees, each vertex gets just over 11 degrees, so alpha is just under 79 degrees.

This doesn't generalise to an arbitrary axis, though. It only works for bends like those in your diagram. For a more general (and more useful!) tool, it makes more sense to simply apply a 2D rotation (about the axis) to each vertex independently. Exactly what rotation to apply depends on some design decisions about how the bend should behave when the axis goes through the mesh, and how strong a bend you want to allow. The crucial point is that it's not the same rotation for every vertex: the rotation is proportional to the perpendicular distance from the vertex to the neutral line of the transformation. In your example, the neutral line is the bottom edge of each cube.

## α = 90° - β/4

Lets call the bend angle β. The math is quite easy after following observation: We can draw a perpendicular bisector middle->w of the isoscles triangle v1->middle->v2. Then the anlge at v1 is the desired α, the angle at w is 90° and the angle at middle is just β/4.

By the triangle postulate the sum of the interior angles of a triangle is 180°. By applying this to our new triangle we get 180° = α + 90° + β/4, so we get