Control the curvature using Polybevel on a polyline

   1479   8   2
User Avatar
Member
24 posts
Joined: April 2020
Offline
Hi,
For example, as the figure shows (in top view), trying to Polybevel a closed square polygon (green line *4) at its four corner points, the result of which is shown in red and it's not a 'perfect' circle. For comparison, the 1/4 white curve of 'perfect' round are Polybeveled from the primitives Y-extruded from same green line, using totally same bevel parameters.

So with the same parameters and same input shape(just one is polyline, the other is Y-extruded primitives), why their output shape are different and how to procedurally control their output curvature to be consistent?



Thanks!
Edited by Nuuk - Aug. 2, 2022 13:07:04
User Avatar
Member
7 posts
Joined: Aug. 2021
Offline
Did you find an answer to this? Polybevel’s weird rounding has always confused me
User Avatar
Member
24 posts
Joined: April 2020
Offline

Just tried one, inelegantly. :/ it creates equiradius rounded corners, only suits for 2d cases.
working fine so far.


float dist = chf("dist"); int divisions = chi("Divisions");
int corners[] = expandpointgroup(0, chs("group"));


int PrimPts[] = primpoints(0, @primnum), PrimPts_new[]=PrimPts;
int primCorners[]; //intersection of  current prim pts  &  selected pts group
foreach (int pt; PrimPts)
    if (find(corners, pt) >= 0 && chs("group") != "") 
        append(primCorners, pt); 

if(len(primCorners) > 0){
    foreach(int i; primCorners){
        vector corner = point(0, "P", i);

        int p1 = neighbour(0, i, 0);
        int p2 = neighbour(0, i, 1);
        vector P1 = point(0, 'P', p1); //2 neighbouring Pts
        vector P2 = point(0, 'P', p2);
        vector dir1 = normalize(corner - P1); //2 tangents' dirs
        vector dir2 = normalize(corner - P2);
        vector normal = normalize(cross(dir1, dir2)); //normal of the plane

        vector r1 = -normalize(cross(dir1, normal)); //2 radius dirs
        vector r2 = normalize(cross(dir2, normal));
        vector T1 = corner - dir1 * dist; //2 tangency Pts
        vector T2 = corner - dir2 * dist;
        vector C = T1 - r1 * length(cross(T2 - T1, r2)) / length(cross(r1, r2)); //centre of the circle
        float radius = distance(C, T1); 

        vector x = r1; vector z = normal; 
        vector y = normalize(cross(z, x)); 
        float angle = atan2(dot(r2, y), dot(r2, x)); //azimuth angle of r2
        float stepAngle = angle / float(divisions);

        int newPts[] = {};
        for (int j = 0; j <= divisions; ++j) {
            float jAngle = j * stepAngle; //Polar coord: set(jAngle, r, 0)
            vector j_on_plane = set(cos(jAngle) * radius, sin(jAngle) * radius, 0); //Cartesian coord 2D
            //maps 2D coord on the plane into world 3D coord
            matrix M = ident();
            M = set(
                set(x.x, x.y, x.z),
                set(y.x, y.y, y.z),
                set(z.x, z.y, z.z)
            );
            vector j_in_3D = j_on_plane * M + C;

            int newPt = addpoint(0, j_in_3D);
            push(newPts, newPt);
        }
        int insert = find(PrimPts, i);
        int insert_1 = find(PrimPts_new, i);

        if(PrimPts[(insert+1) % len(PrimPts)] == p1) //match new pts' order
            newPts = reverse(newPts);
        removeindex(PrimPts_new, insert_1);
        insert(PrimPts_new, insert_1, newPts);
    }
    removeprim(0, @primnum, 0);
    foreach(int i; primCorners) removepoint(0, i);
    addprim(0, "poly", PrimPts_new);
}
Fixed!


Edited by Nuuk - Sept. 30, 2023 02:48:27
User Avatar
Member
64 posts
Joined: April 2022
Offline
Nuuk
Just tried one, inelegantly. :/ it creates equiradius rounded corners, only suits for 2d cases.
working fine so far.

You need to fix it a bit

Attachments:
curve_bevel_fail.png (705.4 KB)

alexeyvanzhula.gumroad.com
User Avatar
Member
7 posts
Joined: Aug. 2021
Offline
Thanks! This is cool and I'll be keeping it.

I realise it's not the exact topic but I was hoping for a trick, otl, or prayer to the universe that results in correctly rounded edges on 3d edges/prims. Is there anything out there for that?

I've tried toying around with custom curves and the ramp but haven't been able to create a proper circular bevel.
User Avatar
Member
122 posts
Joined: Aug. 2017
Offline
Try FeELib-for-Houdini endless Otl's and Trix.
Conservation of Momentum
User Avatar
Member
24 posts
Joined: April 2020
Offline
Alexey_Vanzhula
You need to fix it a bit

fixed✅
Edited by Nuuk - Oct. 21, 2023 07:20:52
User Avatar
Member
480 posts
Joined: July 2005
Offline
It might be probably better to loop over vertices of each prim and assume, that each prim has unique points probably?
Because if you take a point (vtc(i)), then vtc(i-1) and vtc(i+1) will always be the correct neighbours (taking modulo of course).

Here is a modification of an older file, which is quite similar to Nuuk's example.
Edited by Aizatulin - Sept. 30, 2023 03:13:24

Attachments:
Round_Bevel_PolypathB.hipnc (170.8 KB)

User Avatar
Member
41 posts
Joined: Dec. 2020
Offline
a sort vertex order may solve the flipping of normals. (normals will show front or back faces depending on clockwise/anti clockwise creation of points). all cad software has odd issues with rounding off edges normally breaking when points are blocked by others or shooting past others when forced. Autodesk used to send me crazy trying to do fillets. it wasn't until I started using blender that I could see what was happening with the lines and points folding over each other. the difference in results between different cad programs is crazy when giving each the same information to create the same object using triangles and circles I found they could be meters out from each other, over large distances. the first and last points normal direction can affect the curve and may need accounting for
  • Quick Links