图形学算法:

1,cubic-bezier

vector start = point(0,"P",0);
vector end = point(0,"P",@numpt-1);

vector range_01 = fit(@ptnum,0,@numpt-1,0,1);
float ix = range_01.x;

float dx = end.x - start.x;
float dy = end.y - start.y;

vector p2 = set(start.x + dx * 0.5 , start.x + dy * 0.1, 0 );
vector p3 = set(start.x + dx * 0.5 , start.x + dy * 0.9, 0 );


float x= pow((1-ix),3) * start.x + 3* pow((1-ix),2) * ix * p2.x + 3*(1 - ix)* pow(ix,2) * p3.x + pow(ix,3) * end.x;  
float y= pow((1-ix),3) * start.y + 3* pow((1-ix),2) * ix * p2.y + 3*(1 - ix)* pow(ix,2) * p3.y + pow(ix,3) * end.y;  
@P.x = x;
@P.y = y;
View Code

 https://en.wikipedia.org/wiki/B%C3%A9zier_curve

如果将代码的0.1 和 0.9改成0.5 , 0.5 又会变成直线。

2 Houdini中的四元数.

float theta = @Time ;

vector axis = set(0,1,0);

float vx = axis.x * sin(theta/2);
float vy = axis.y * sin(theta/2);
float vz = axis.z * sin(theta/2);

float s = cos(theta/2);
vector v = set(vx,vy,vz);

// so the q = <s, v>


@P = @P * s *s + cross(v*2*s , @P) + v * dot(v,@P ) - cross(cross(v,@P),v);

q = cos(theta/2) + A*sin(theta/2)

A表示旋转轴向。是个单位向量

还需要个q的共轭四元数

3,rotation by axis 非矩阵形式来自 PBRTv2

vector axis = chv("axis");
float angle = chf("angle");
angle = radians(angle);

vector vc = axis * dot(@P , axis);
vector v1 = @P - vc;
vector v2 = cross(v1,axis);

@P = vc + v1 * cos(angle) + v2 * sin(angle);
原文地址:https://www.cnblogs.com/gearslogy/p/7763263.html