zoukankan      html  css  js  c++  java
  • 团队项目·冰球模拟器——插值算法接口设计

    1 需求分析

    1.1 插值算法的特征

    • 输出参数(如位移、速度等)是时间的函数。
    • 配置算法参数和触发计算是空间上相互独立的。

    1.2 结构模型

    根据1.1中的分析,参考《Head First 设计模式》,可以明显地认为这是属于典型的“策略模式”。因此,可以按照策略模式设计接口。

    2 接口设计

    由于C++的自由度远比Java的高,故可以不完全按Java的设计模式处理实现问题。

    2.1 算法接口——Interpolation

    2.2 配置接口——InterpolationConfigure

    3 实现接口

    只需要按如下图使用public属性实现接口即可:

    4 使用接口

    4.1 配置

    InterpolationConfigure *new_cmd;                // 定义为配置接口的指针
    new_cmd = new TrapezoidInterpolation();         // 设定算法类型
    new_cmd->set_time(time);                        // 设定目标时间
    new_cmd->set_position(position);                // 设定目标位置
    new_cmd->set_velocity(velocity);                // 设定目标速度
    new_cmd->set_acceleration(acceleration);        // 设定加速度
    new_cmd->set_jerk(jerk);                        // 设定急动度
    

    4.2 触发计算

    Interpolation algorithm = ...;                  // 当前算法
    algorithm.start(time_now,                       // 初始化,初始时间戳
                    start_position,                 // 初始位置
                    start_velocity);                // 初始速度
    
    while (1) {
        algorithm.move(time_now);                       // 触发一次运算,提供当前时间戳
    
        position = algorithm.get_position();            // 返回计算位置
        velocity = algorithm.get_velocity();            // 返回计算速度
        acceleration = algorithm.get_acceleration();    // 返回计算加速度
        jerk = algorithm.get_jerk();                    // 返回计算急动度
    }
    
  • 相关阅读:
    随题而学(二)多维数组转一维数组
    随题而学(一)
    谁能破解“无法定位程序输入点ucrtbase.abort与动态链接库api-ms-win-crt-runtime-l1-1-0.dll上”
    虚拟机8—tools安装失败
    win7介绍
    win xp安装
    Linux正则表达式,grep总结,sed用法
    Linux将用户添加到组的指令
    xxx is not in the sudoers file.This incident will be reported.的解决方法
    69-70连接查询
  • 原文地址:https://www.cnblogs.com/passerby233/p/RTCSD_proj_interpolation_design.html
Copyright © 2011-2022 走看看