zoukankan      html  css  js  c++  java
  • 图形学算法:

    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);
  • 相关阅读:
    G-sensor驱动分析
    写i2c_client驱动的两种方式
    TP分析
    JAVA基础知识要点
    springboot-线程池简单使用
    java 实现好看的图形验证码
    正则表达式校验15/18位生份证-JAVA版
    springboot2.X集成HttpClient 发送HTTPS 请求
    linux-修改时区时间
    springboot2.X 在项目启动后执行一段自定义代码
  • 原文地址:https://www.cnblogs.com/gearslogy/p/7763263.html
Copyright © 2011-2022 走看看