java 我应该如何编程物理模拟?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6719956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How should I program a simulation of physics?
提问by Mahendra Chouhan
I am trying to create a Java package that can be used to write simulation programs. My goal is to create 'objects' like springs or solid objects like cubes and spheres. They will have mass, velocity, gravity etc. and they can interact with each other.
我正在尝试创建一个可用于编写模拟程序的 Java 包。我的目标是创建像弹簧这样的“对象”或像立方体和球体这样的实体对象。它们将具有质量、速度、重力等,并且它们可以相互作用。
I have seen some simulation programs on www.myphysicslab.combut my problem is that I don't want to write different equations for different senarios. Is there any way to do this? I am new to programming.
我在www.myphysicslab.com上看过一些模拟程序,但我的问题是我不想为不同的场景编写不同的方程。有没有办法做到这一点?我是编程新手。
回答by Bart
Creating a physics engine is hard. (Very hard). But it can also be a lot of fun. Well, fun in a "why am I doing this to myself?" kind of way.
创建物理引擎很难。(很难)。但这也很有趣。好吧,有趣的是“我为什么要对自己这样做?” 一种方式。
Assuming your have a fair grasp of the maths involved*, and assuming you're interested in Rigid Body Dynamics there are a couple of classic references to start with:
假设您对所涉及的数学有一定的了解*,并且假设您对刚体动力学感兴趣,那么可以从以下几个经典参考开始:
- First of all Chris Hecker's Rigid Body Dynamics tutorials
- And of course Witkin and Baraff's SIGGRAPH course
- 首先是 Chris Hecker 的刚体动力学教程
- 当然还有 Witkin 和 Baraff 的SIGGRAPH 课程
Those are good places to start and will provide more than enough of a challenge for you.
这些都是很好的起点,将为您提供足够多的挑战。
You could also look at Box2Dby Erin Catto and his associated GDC tutorialswhich you can download.
您还可以查看Erin Catto 的Box2D及其相关的GDC 教程,您可以下载这些教程。
For more specific help, the forums for Bulletalso contain a sub-section where you can discuss and ask questions once you have understood some of the basics.
如需更具体的帮助,Bullet论坛还包含一个子部分,您可以在了解一些基础知识后进行讨论和提问。
*If you don't have this fair grasp, learn. If you're not willing to, don't try and just use an existing engine. If this is your very first programming experience, just focus on the programming first. Don't get yourself overwhelmed.
*如果你没有这个公平的把握,学习。如果您不愿意,请不要尝试只使用现有引擎。如果这是您的第一次编程体验,请先专注于编程。不要让自己不知所措。
Good luck.
祝你好运。
回答by adlawson
To understand physics, you must first understand maths. Attempting to write a physics engine without using mathematical equations is like making a cake without ingredients.
要了解物理,首先要了解数学。尝试在不使用数学方程的情况下编写物理引擎就像制作没有配料的蛋糕。
Entire careers are built on creating physics engines, so my advice is to either use an existing engine, or get your books out.
整个职业生涯都建立在创建物理引擎的基础上,所以我的建议是要么使用现有的引擎,要么把你的书拿出来。
回答by Kipton Barros
Building a physics simulator can be a lot of work. Two dimensions is considerably simpler than three, so maybe you want to start with 2D. You might want to begin with an existing package like JBox2D. It has a constraint solver, friction, etc. You can build on top of JBox2D or study how it works.
构建物理模拟器可能需要大量工作。二维比三维简单得多,所以也许您想从二维开始。您可能希望从现有的包开始,例如JBox2D。它有一个约束求解器、摩擦等。你可以在 JBox2D 之上构建或研究它是如何工作的。
An HTML5 version is available with online demos: GWTBox2D
HTML5 版本可用于在线演示:GWTBox2D
回答by Daneos
There is a program called Easy Java Simulations that does exactly what you want! You can create java applets and has many of the visual objects ready. You can also write java code and subprograms.
有一个名为 Easy Java Simulations 的程序可以完全满足您的需求!您可以创建 Java 小程序并准备好许多可视对象。您还可以编写 java 代码和子程序。
visit http://fem.um.es/Ejs/to download.
访问 http://fem.um.es/Ejs/下载。