nortikin / sverchok

Sverchok
http://nortikin.github.io/sverchok/
GNU General Public License v3.0
2.21k stars 231 forks source link

Adaptive Edges error #2272

Open stansu opened 5 years ago

stansu commented 5 years ago

when i use Adaptive Edges to create saw disc, it will have error when i use circle with vertices 6,10,14,18,22.... see my attachment for detail saw_disc.zip

vokoscreen-2018-09-07_10-37-14

Durman commented 5 years ago

Fast solution is to add rotation node for recipient. Nevertheless you found corner case that does not work properly. I think it relates with quaternions that used in this node. Perhaps if quaternions will be changed to matrix this gives correct result.

https://github.com/nortikin/sverchok/blob/185ecb198c4ff8d4ac95df614abb499402dc6024/nodes/modifier_make/edges_adaptative.py#L80-L87

2018-09-07_08-29-12

Durman commented 5 years ago

Unfortunately using of matrix does not give better result. Perhaps implementation of additional checkings can fix this situation.

mat_r = Matrix.Rotation(d_vector.angle(e_vector), 4, d_vector.cross(e_vector))

2018-09-10_13-03-15

alessandro-zomparelli commented 5 years ago

I'm reporting another wierd result that I'm getting from that node generating a path along a spiral:

immagine

It is mostly correct, but at some point it just twist. This is what happend if I multiply a circle along itself:

immagine

One of them is rotated of 90°.

Really nice Node anyway!

Durman commented 5 years ago

@alessandro-zomparelli Try to use duplicate objects along edges node. It has several different algorithms of determination position of new mesh. Also it is possible to create sinusoid along spiral without special nodes.)))

2018-11-02_09-33-41 https://gist.github.com/Durman/df9a4bffb74cd513125d9f8d5f2cc862.js

alessandro-zomparelli commented 5 years ago

Thanks @Durman It is exactely what I wanted. To be honest I loved adaptive edges for simplicity (I'm using Sverchock for some workshop and I really wanted to keep things simple). This approach gives the expected result but it's a bit too complicated to teach... :-( Apparently, if I got it correctly, in order to control the twist of object along a polyline/curve there are two strategies, specify an UP direction (like you did), or evaluating the curvature of the polyline in order to align coherently with that. Seems that Blender itself doesn't handle that correctly (while it do for Z up). immagine immagine

I tried to check the curvature graph in of a spiral in Rhino and I get a correct tilt of a curve in 3D space. immagine (of course it's a NURBS, it should be more simple in that case)

alessandro-zomparelli commented 5 years ago

I created a script for evaluating the normals/curvature and tangent vectors to a curve, maybe can help fixing some issues with "Adaptive Edges":


"""
in verts v d=[] n=[]
out nor v
out tan v
"""

from mathutils import Vector

curve_2D = False
plane_normal = Vector((0,0,1))
cyclic = False
normalize = False

if verts:
    if len(verts[0])>2:
        if cyclic:
            verts = [verts[0][-1]] + verts[0] + [verts[0][0]]
        else:
            verts = [verts[0][0]] + verts[0] + [verts[0][-1]]
        nor = []
        tan = []
        for i in range(1,len(verts)-1):
            p0 = Vector(verts[i-1])
            p = Vector(verts[i])
            p1 = Vector(verts[i+1])

            v0 = (p-p0).normalized()
            v1 = (p1-p0).normalized()
            t = (v0+v1)/2
            if curve_2D:
                n = t.cross(plane_normal)
            else:
                n = (v1-v0)
                if normalize: n.normalize()
            nor.append(tuple(-n))
            tan.append(tuple(t))
        if not cyclic:
            tan[0] = tan[1]
            tan[-1] = tan[-2]
            nor[0] = nor[1]
            nor[-1] = nor[-2]
        tan, nor = [tan], [nor]

These are some examples: 2D normal (for having consistency with the direction like an offset should be): immagine

3D Spiral: immagine

Generic 3D curve (curvature not normalized): immagine

Tangents: immagine

Durman commented 5 years ago

@alessandro-zomparelli I also tried to do something in this direction.))

2242

nortikin commented 5 years ago

@Durman so what did you consider than? Can someone handle adaptive edges fixings?

nortikin commented 5 years ago

would the transformation matrix from tangent the same clean?

alessandro-zomparelli commented 5 years ago

would the transformation matrix from tangent the same clean?

you should consider both tangent and curvature direction.