欢迎光临散文网 会员登陆 & 注册

【Aegisub】几何变换与变形

2019-12-23 03:21 作者:多华宫与火火里  | 我要投稿

可参考的网址;

https://blog.csdn.net/qq_40464371/article/details/102518672

https://blog.csdn.net/June_Xixi/article/details/102488630

https://blog.csdn.net/weixin_43943977/article/details/102511052

https://blog.csdn.net/qq_38137411/article/details/83213297







以任意点(a,b)进行x方向缩放c倍、y方向缩放d倍


function transformation(x,y,a,b,c,d)     return a+(x-a)*c,b+(y-b)*d end


说明:平时使用的x*2,y*2这种缩放操作当然是以(0,0)点为基础,就像上面那样说的,当c、d都为0时即有x*2,y*2






θ为正即绕原点逆时针旋转θ°



function rotate(x,y,θ)     return x*math.cos(math.rad(θ))+y*math.sin(math.rad(θ)),-x*math.sin(math.rad(θ))+y*math.cos(math.rad(θ)) end




平面中绕任意点旋转矩阵求法

θ为正即绕任意点(a,b)逆时针旋转θ°   


function rotate(x,y,a,b,θ)     return (x-a)*math.cos(math.rad(θ))+(y-b)*math.sin(math.rad(θ))+a,b-(x-a)*math.sin(math.rad(θ))+(y-b)*math.cos(math.rad(θ)) end





错切几何变换(形变效果样子参考标签如fax)


function Shear(x,y,c,d)     return x+c*y,y+d*x end


上面即在x方向错切c,c为x方向错切系数。然后d为y方向错切系数


更形象的写法如下:

function Shear(x,y,c,d)     return x+math.tan(math.rad(c))*y,y+math.tan(math.rad(d))*x end


说明:c、d均为你所要指定的角度,如x方向错切45度则c=45、d=0,其效果中可见角度"错开"45°


错切加上平移

function Shear(x,y,c,d) if c== 0 then move_x= 0 else move_x= -(by-ly)/math.tan(math.rad(c))/2 end if d == 0 then move_y =0 else move_y = -(bx-lx)/math.tan(math.rad(d))/2 end  return x+math.tan(math.rad(c))*y+ move_x,y+math.tan(math.rad(d))*x+move_y end






扭曲


function warping1(x,y)  r1 =math.sqrt((x-mx)^2+(by-y)^2)     mr1=math.sqrt((lx-mx)^2+(by)^2)    θ=math.rad(90*mr1/r1)  return mx+(x-mx)-(y-by)*math.sin(θ*(1-((maxj-j+1)/maxj))),y end


function warping2(x,y)  r2 =math.sqrt((x-mx)^2+(y-my)^2)     mr2=math.sqrt((lx-mx)^2+(ly-my)^2)    θ=math.rad(30*mr2/r2)  return mx+(x-mx)*math.cos(θ*(1-((maxj-j)/maxj)))-(y-my)*math.sin(θ*(1-((maxj-j)/maxj))),my+(x-mx)*math.sin(θ*(1-((maxj-j)/maxj)))+(y-my)*math.cos(θ*(1-((maxj-j)/maxj))) end


function warping3(x,y)  r3 =math.sqrt((x-mx)^2+(y-my)^2)     mr3=math.sqrt((lx-mx)^2+(ly-my)^2)    θ=math.rad(30*mr3/r3)  return mx+(x-mx)*math.cos(θ*((j/maxj)-1))-(y-my)*math.sin(θ*((j/maxj)-1)),my+(x-mx)*math.sin(θ*((j/maxj)-1))+(y-my)*math.cos(θ*((j/maxj)-1)) end


function warping4(x,y)  r4 =math.sqrt((x-mx)^2+(y-my)^2)     mr4=math.sqrt((lx-mx)^2+(ly-my)^2)     θ=math.rad(30*mr4/r4)  return mx+(x-mx)*math.cos(θ*(1-(j/maxj)))-(y-my)*math.sin(θ*((1- j/maxj))),my+(x-mx)*math.sin(θ*(1-(j/maxj)))+(y-my)*math.cos(θ*((1-j/maxj))) end


function warping5(x,y)  r5 =math.sqrt((x-mx)^2+(y-my)^2)     mr5=math.sqrt((lx-mx)^2+(ly-my)^2)    θ=math.rad(60*r5/mr5)  return mx+(x-mx)*math.cos(θ*(1-(j/maxj)))-(y-my)*math.sin(θ*((1-j/maxj))),my+(x-mx)*math.sin(θ*(1-(j/maxj)))+(y-my)*math.cos(θ*((1-j/maxj))) end


function warping6(x,y)  mod =(y-ly)/(by-ly)  return x+20*math.sin(2*math.pi*mod)*(1-j/maxj),y end



function warping7(x,y,k)  mod =(y-ly)/(by-ly)  return x+k*math.sin(2*math.pi*mod)*(1-j/maxj),y end


function warping8(x,y,k,v)  mod =(y-ly)/(by-ly)    mod2 =(x-lx)/(bx-lx)  return x+k*math.sin(2*math.pi*mod)*(1-j/maxj),y+v*math.sin(2*math.pi*mod2)*(1-j/maxj) end


关于warping8建议其中的k和v都小于字体高度除以8比较好(即小于height/8)




上面扭曲中用到的变量都先定义在前面

style=line.styleref text=_G.Yutils.decode.create_font(style.fontname, style.bold, style.italic, style.underline, style.strikeout,style.fontsize).text_to_shape(syl.text_stripped)  text=string.gsub(text,"c","")   lx,ly,bx,by=_G.Yutils.shape.bounding(text)          mx=(lx+bx)/1.7       my=(ly+by)/2









【Aegisub】几何变换与变形的评论 (共 条)

分享到微博请遵守国家法律