• Website
  • Search
  • Member List
  • Help
  • Old Forum
  • Social Media
    •   @Wings3dOfficial
    •   @Wings3dOfficial
    •   Wings3dOfficial
    •   Wings3dOfficial
  • Register
  • Login
  • Website
  • Search
  • Member List
  • Help
  • Old Forum
  • Register
  • Login
Wings 3D Development Forum Wings 3D ManifoldLab Plug-ins Collection v
« Previous 1 2 3 4 5 … 7 Next »
Request for automatic handle

 
  • 0 Vote(s) - 0 Average
Request for automatic handle

ggaliens
Offline

Erlang Hacker
Posts: 954
Threads: 143
Joined: Nov 2012
#5
02-04-2016, 02:49 PM (This post was last modified: 02-04-2016, 03:27 PM by ggaliens.)
Micheus ... this is a test REPLY.

Not working correct yet. Padding at ends logic needs help. And Polykind parameter must get used.

Code:
%% http://stackoverflow.com/questions/7054272/how-to-draw-smooth-curve-through-n-points-using-javascript-html5-canvas
%% TEST : cardinal_spline([0.0,0.0,  1.0,0.0,  1.0,1.0,  0.0,0.0], 12)
cardinal_spline(PTS, PolyKind, NumOfSegments) when is_integer(NumOfSegments)
    when PolyKind == polyline orelse PolyKind == polygon ->
    Tension = 0.7,
    Len = length(PTS),
    _Pts = fun(I0) ->
        I = I0 + Len,
        lists:nth((I rem Len) + 1,PTS)
    end,
    Fun = fun
        (I, Acc) ->
            Fun1 = fun(T, Acc1) ->
                %% calc tension vectors

                T1X = (element(1,_Pts(I+1)) - element(1,_Pts(I-1))) * Tension,
                T2X = (element(1,_Pts(I+2)) - element(1,_Pts(I))) * Tension,

                T1Y = (element(2,_Pts(I+1)) - element(2,_Pts(I-1))) * Tension,
                T2Y = (element(2,_Pts(I+2)) - element(2,_Pts(I))) * Tension,

                T1Z = (element(3,_Pts(I+1)) - element(3,_Pts(I-1))) * Tension,
                T2Z = (element(3,_Pts(I+2)) - element(3,_Pts(I))) * Tension,

                %% calc step
                ST = 1.0 * T / NumOfSegments,
                %% calc cardinals
                C1 =   2.0 * pow(ST,3.0)  - 3.0 * pow(ST,2.0) + 1.0,
                C2 = -(2.0 * pow(ST,3.0)) + 3.0 * pow(ST,2.0),
                C3 =         pow(ST,3.0)  - 2.0 * pow(ST,2.0) + ST,
                C4 =         pow(ST,3.0)  -       pow(ST,2.0),

                %% calc x and y cords with common control vectors
                X = C1 * element(1,_Pts(I))  + C2 * element(1,_Pts(I+1)) + C3 * T1X + C4 * T2X,
                Y = C1 * element(2,_Pts(I))  + C2 * element(2,_Pts(I+1)) + C3 * T1Y + C4 * T2Y,
                Z = C1 * element(3,_Pts(I))  + C2 * element(3,_Pts(I+1)) + C3 * T1Z + C4 * T2Z,

                [{X,Y,Z}|Acc1]

            end,
            lists:foldl(Fun1, Acc, lists:seq(0,NumOfSegments-1))
    end,
    lists:foldl(Fun, [], lists:seq(1,length(PTS)-0)).



« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Messages In This Thread
Request for automatic handle - by cyseal - 02-01-2016, 08:57 PM
RE: Request for automatic handle - by ggaliens - 02-03-2016, 03:47 PM
RE: Request for automatic handle - by ggaliens - 02-04-2016, 04:33 AM
RE: Request for automatic handle - by ggaliens - 02-04-2016, 06:13 AM
RE: Request for automatic handle - by ggaliens - 02-04-2016, 02:49 PM
RE: Request for automatic handle - by cyseal - 02-04-2016, 04:01 PM
RE: Request for automatic handle - by ggaliens - 02-04-2016, 04:34 PM
RE: Request for automatic handle - by micheus - 02-04-2016, 04:37 PM
RE: Request for automatic handle - by ggaliens - 02-04-2016, 05:20 PM
RE: Request for automatic handle - by cyseal - 02-05-2016, 10:50 AM
RE: Request for automatic handle - by cyseal - 02-05-2016, 07:33 PM

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D - Powered by MyBB

Linear Mode
Threaded Mode