当前位置: 首页 > news >正文

从化网站建设服务山东经济建设网站

从化网站建设服务,山东经济建设网站,wordpress仿模板,重庆建工集团股份有限公司官网一、总览 1.1 连接绳子的约束 在rope.cpp 中, 实现Rope 类的构造函数。这个构造函数应该可以创建一个 新的绳子(Rope) 对象#xff0c;该对象从start 开始#xff0c;end 结束#xff0c;包含num_nodes 个节点。也就是如下图所示#xff1a; 每个结点都有质量#xff…一、总览 1.1 连接绳子的约束 在rope.cpp 中, 实现Rope 类的构造函数。这个构造函数应该可以创建一个 新的绳子(Rope) 对象该对象从start 开始end 结束包含num_nodes 个节点。也就是如下图所示 每个结点都有质量称为质点质点之间的线段是一个弹簧。通过创建一系列的质点和弹簧你就可以创建一个像弹簧一样运动的物体。 pinned_nodes 设置结点的索引。这些索引对应结点的固定属性(pinned attribute)应该设置为真他们是静止的。对于每一个结点你应该构造一个Mass对象并在Mass对象的构造函数里设置质量和固定属性。请仔细阅读代码确定传递给构造函数的参数。你应该在连续的两个结点之间创建一个弹簧设置弹簧两端的结点索引和弹簧系数k请检查构造函数的签名以确定传入的参数。 运行./ropesim。你应该可以看到屏幕上画出绳子但它不发生运动。 1.2 显式/半隐式欧拉法 胡克定律表示弹簧连接的两个质点之间的力和他们之间的距离成比例。也就是 在Rope::simulateEuler 中, 首先实现胡克定律。遍历所有的弹簧对弹簧两端的质点施加正确的弹簧力。保证力的方向是正确的对每个质点累加所有的弹簧力。 一旦计算出所有的弹簧力对每个质点应用物理定律 运行./ropesim。仿真应该就开始运行了但是只有3 个结点看起来不够多。在application.cpp 文件的最上方你应该可以看到欧拉绳子Verlet绳子的定义。改变两个绳子结点个数默认为3个比如16或者更多。 运行./ropesim -s 32 来设置仿真中每帧不同的仿真步数。尝试设置较小的 值和较大的值默认值为64。 1.3 显式Verlet Verlet 是另一种精确求解所有约束的方法。这种方法的优点是只处理仿真中 顶点的位置并且保证四阶精度。和欧拉法不同Verlet 积分按如下的方式来更新下一步位置 除此之外我们可以仿真弹簧系数无限大的弹簧。不用再考虑弹簧力而是用解约束的方法来更新质点位置只要简单的移动每个质点的位置使得弹簧的长度保持原长。修正向量应该和两个质点之间的位移成比例方向为一个质点指向另一质点。每个质点应该移动位移的一半。 只要对每个弹簧执行这样的操作我们就可以得到稳定的仿真。为了使运动更加平滑每一帧可能需要更多的仿真次数。 1.4 阻尼 向显示Verlet方法积分的胡克定律中加入阻尼。现实中的弹簧不会永远跳动因为动能会因摩擦而减小。阻尼系数设置为0.00005, 加入阻尼之后质点位置更新如下 应该修改的函数是: rope.cpp 中的Rope::rope(…)rope.cpp 中的void Rope::simulateEuler(…)rope.cpp 中的void Rope::simulateVerlet(…) 二、安装依赖 $ sudo apt install libglu1-mesa-dev freeglut3-dev mesa-common-dev $ sudo apt install xorg-dev三、参考答案 3.1 rope.cpp中的Rope::rope(…) 实现1.1 连接绳子的约束 Rope::Rope(Vector2D start, Vector2D end, int num_nodes, float node_mass, float k, vectorint pinned_nodes){// TODO (Part 1): Create a rope starting at start, ending at end, and containing num_nodes nodes.for(int i 0; i num_nodes; i){// 创建质点Vector2D pos start (end - start) * (double(i) / double(num_nodes));masses.push_back(new Mass(pos, node_mass, false));}for(int i 0; i num_nodes - 1; i){// 创建弹簧springs.push_back(new Spring(masses[i], masses[i 1], k));} // Comment-in this part when you implement the constructorfor (auto i : pinned_nodes) {masses[i]-pinned true;}}3.2 rope.cpp 中的void Rope::simulateEuler(…) 实现1.2 显式/半隐式欧拉法 胡克定律 for (auto s : springs){// TODO (Part 2): Use Hookes law to calculate the force on a nodeauto len (s-m1-position - s-m2-position).norm();s-m1-forces -s-k * (s-m1-position - s-m2-position) / len * (len - s-rest_length);s-m2-forces -s-k * (s-m2-position - s-m1-position) / len * (len - s-rest_length);}显式/隐式欧拉法 if (!m-pinned){// TODO (Part 2): Add the force due to gravity, then compute the new velocity and position// 显式欧拉法下一个时刻位置用当前速度计算auto a m-forces / m-mass gravity;m-position m-velocity * delta_t;//根据当前速度更新位置m-velocity a * delta_t;//更新下一时刻速度// 隐式欧拉法下一个时刻位置用下一时刻速度计算// auto a m-forces / m-mass gravity;// m-velocity a * delta_t;//更新速度// m-position m-velocity * delta_t;//根据下一时刻速度更新位置 // TODO (Part 2): Add global damping}完整代码 void Rope::simulateEuler(float delta_t, Vector2D gravity){for (auto s : springs){// TODO (Part 2): Use Hookes law to calculate the force on a nodeauto len (s-m1-position - s-m2-position).norm();s-m1-forces -s-k * (s-m1-position - s-m2-position) / len * (len - s-rest_length);s-m2-forces -s-k * (s-m2-position - s-m1-position) / len * (len - s-rest_length);}for (auto m : masses){if (!m-pinned){// TODO (Part 2): Add the force due to gravity, then compute the new velocity and position// 显式欧拉法下一个时刻位置用当前速度计算auto a m-forces / m-mass gravity;m-position m-velocity * delta_t;//根据当前速度更新位置m-velocity a * delta_t;//更新下一时刻速度// 隐式欧拉法下一个时刻位置用下一时刻速度计算// auto a m-forces / m-mass gravity;// m-velocity a * delta_t;//更新速度// m-position m-velocity * delta_t;//根据下一时刻速度更新位置 // TODO (Part 2): Add global damping}// Reset all forces on each massm-forces Vector2D(0, 0);}}3.3 rope.cpp 中的void Rope::simulateVerlet(…) 实现1.3 显式Verlet 显式Verlet void Rope::simulateVerlet(float delta_t, Vector2D gravity){for (auto s : springs){// TODO (Part 3): Simulate one timestep of the rope using explicit Verlet solving constraints)auto len (s-m1-position - s-m2-position).norm();s-m1-forces -s-k * (s-m1-position - s-m2-position) / len * (len - s-rest_length);s-m2-forces -s-k * (s-m2-position - s-m1-position) / len * (len - s-rest_length);}for (auto m : masses){if (!m-pinned){Vector2D temp_position m-position;// TODO (Part 3.1): Set the new position of the rope massauto a m-forces / m-mass gravity;m-position temp_position (temp_position - m-last_position) a * delta_t * delta_t;m-last_position temp_position;// TODO (Part 4): Add global Verlet damping}m-forces Vector2D(0, 0);}}3.4 增加阻尼 rope.cpp 中的void Rope::simulateVerlet(…) 向显示Verlet方法积分的胡克定律中加入阻尼。现实中的弹簧不会永远跳动因为动能会因摩擦而减小。阻尼系数设置为0.00005, 加入阻尼之后质点位置更新如下 void Rope::simulateVerlet(float delta_t, Vector2D gravity){for (auto s : springs){// TODO (Part 3): Simulate one timestep of the rope using explicit Verlet solving constraints)auto len (s-m1-position - s-m2-position).norm();s-m1-forces -s-k * (s-m1-position - s-m2-position) / len * (len - s-rest_length);s-m2-forces -s-k * (s-m2-position - s-m1-position) / len * (len - s-rest_length);}for (auto m : masses){if (!m-pinned){Vector2D temp_position m-position;// TODO (Part 3.1): Set the new position of the rope massauto a m-forces / m-mass gravity;//m-position temp_position (temp_position - m-last_position) a * delta_t * delta_t;//m-last_position temp_position;// TODO (Part 4): Add global Verlet dampingdouble damping_factor 0.00005;m-position temp_position (1 - damping_factor) * (temp_position - m-last_position) a * delta_t * delta_t;m-last_position temp_position;}m-forces Vector2D(0, 0);}}rope.cpp 中的void Rope::simulateEuler(…) 向欧拉方法中加入阻尼直接使用−kdv作为阻尼而不是相对速度 void Rope::simulateEuler(float delta_t, Vector2D gravity){for (auto s : springs){// TODO (Part 2): Use Hookes law to calculate the force on a nodeauto len (s-m1-position - s-m2-position).norm();s-m1-forces -s-k * (s-m1-position - s-m2-position) / len * (len - s-rest_length);s-m2-forces -s-k * (s-m2-position - s-m1-position) / len * (len - s-rest_length);}for (auto m : masses){if (!m-pinned){// TODO (Part 2): Add the force due to gravity, then compute the new velocity and position// 显式欧拉法下一个时刻位置用当前速度计算// auto a m-forces / m-mass gravity;// m-position m-velocity * delta_t;//根据当前速度更新位置// m-velocity a * delta_t;//更新下一时刻速度// 隐式欧拉法下一个时刻位置用下一时刻速度计算// auto a m-forces / m-mass gravity;// m-velocity a * delta_t;//更新速度// m-position m-velocity * delta_t;//根据下一时刻速度更新位置 // TODO (Part 2): Add global dampingfloat kd 0.005;auto a m-forces / m-mass gravity - kd * m-velocity / m-mass;m-velocity a * delta_t; m-position m-velocity * delta_t; //隐式欧拉法}// Reset all forces on each massm-forces Vector2D(0, 0);}}四、编译 $ mkdir build $ cd build $ cmake .. $ make通过查看rope.cpp中的Rope::rope(…)的引用可以定位到application.cpp文件 // Create two ropes // 通过修改构造函数的第三个参数指定质点个数(默认三个质点这里改成了10个) ropeEuler new Rope(Vector2D(0, 200), Vector2D(-400, 200), 10, config.mass,config.ks, {0}); ropeVerlet new Rope(Vector2D(0, 200), Vector2D(-400, 200), 10, config.mass,config.ks, {0});附件 作业7压缩包
http://www.pierceye.com/news/75425/

相关文章:

  • 南昌企业建设网站开发登陆Wordpress手机app
  • 网站开发的流程图天津网络公司流程
  • php网站开发实例教程 课件wordpress去掉generator
  • 沈阳自助建站软件广东网站建设类公司
  • 织梦cms做网站教程视频做盗版网站会怎样
  • 免费网站赚钱门户网站建设收费
  • 用dw做网站怎么给链接怎样做打赏网站
  • 无锡中小企业网站建设东莞网站建设优化东莞
  • 用wordpress建站的好处集团做网站
  • 重庆做模块网站南宁做网站 的
  • 有哪些网站开发公司平面电商设计是什么
  • 怎么在网站上做网页网站建设中期检查表怎么写
  • 网站建设论文题目网站建设与管理基础及实训电子版
  • 企业网站开发实训目的不改域名和空间 只改网站类型
  • 免费建站绑定域名v6厂高仿手表网站
  • 东莞大朗网站建设仗剑苗木推广做哪个网站好
  • 专门做衬衣网站信息网站方案
  • 龙岗 网站建设深圳信科专业做网站制作
  • 网站域名怎么查询dw做网站常用标签
  • 沧县网站制作grace8WordPress主题
  • mvc在网站开发中的应用做网站的宽度为多少钱
  • 萧山网站优化福州网站建设咨询
  • 宿迁城乡建设监督网站wordpress解决大型访问
  • 手机设计软件app推荐天津seo网络营销
  • 当当网网站系统建设的意义wordpress实现文章目录
  • 南昌成都网站建设方案工程建设官方网站
  • 在线网站开发wordpress无插件
  • 门户网站建设模式包括网站群和wordpress 安装插件慢
  • 高密做网站的公司精美的商城网站介绍
  • 企业微网站与手机微信淘宝网的网站设计方案