Compare commits
7
Commits
main
..
f1083e2bb4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f1083e2bb4 | ||
|
|
a2e85eb66d | ||
|
|
db011416f4 | ||
|
|
0abe919535 | ||
|
|
d4f500956f | ||
|
|
8b4a639e20 | ||
|
|
daac645c9a |
No files matched your search
@@ -1,4 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
*.csv
|
*.csv
|
||||||
*.wav
|
*.wav
|
||||||
*.png
|
|
||||||
Generated
+9
-79
@@ -14,18 +14,6 @@ version = "0.2.21"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
|
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "arrayref"
|
|
||||||
version = "0.3.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "arrayvec"
|
|
||||||
version = "0.7.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.5.1"
|
version = "1.5.1"
|
||||||
@@ -38,12 +26,6 @@ version = "1.3.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bitflags"
|
|
||||||
version = "2.13.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytemuck"
|
name = "bytemuck"
|
||||||
version = "1.25.2"
|
version = "1.25.2"
|
||||||
@@ -86,6 +68,13 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dpsim"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"macroquad",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "equivalent"
|
name = "equivalent"
|
||||||
version = "1.0.3"
|
version = "1.0.3"
|
||||||
@@ -155,7 +144,7 @@ dependencies = [
|
|||||||
"byteorder",
|
"byteorder",
|
||||||
"color_quant",
|
"color_quant",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"png 0.17.16",
|
"png",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -170,12 +159,6 @@ version = "0.2.16"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
|
checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "log"
|
|
||||||
version = "0.4.34"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "macroquad"
|
name = "macroquad"
|
||||||
version = "0.4.16"
|
version = "0.4.16"
|
||||||
@@ -267,20 +250,7 @@ version = "0.17.16"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "82151a2fc869e011c153adc57cf2789ccb8d9906ce52c0b39a6b5697749d7526"
|
checksum = "82151a2fc869e011c153adc57cf2789ccb8d9906ce52c0b39a6b5697749d7526"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags",
|
||||||
"crc32fast",
|
|
||||||
"fdeflate",
|
|
||||||
"flate2",
|
|
||||||
"miniz_oxide 0.8.9",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "png"
|
|
||||||
version = "0.18.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "60769b8b31b2a9f263dae2776c37b1b28ae246943cf719eb6946a1db05128a61"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags 2.13.2",
|
|
||||||
"crc32fast",
|
"crc32fast",
|
||||||
"fdeflate",
|
"fdeflate",
|
||||||
"flate2",
|
"flate2",
|
||||||
@@ -299,46 +269,6 @@ version = "0.3.10"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea"
|
checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "strict-num"
|
|
||||||
version = "0.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "symplectic-double-pendulum"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"macroquad",
|
|
||||||
"tiny-skia",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tiny-skia"
|
|
||||||
version = "0.12.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "47ffee5eaaf5527f630fb0e356b90ebdec84d5d18d937c5e440350f88c5a91ea"
|
|
||||||
dependencies = [
|
|
||||||
"arrayref",
|
|
||||||
"arrayvec",
|
|
||||||
"bytemuck",
|
|
||||||
"cfg-if",
|
|
||||||
"log",
|
|
||||||
"png 0.18.1",
|
|
||||||
"tiny-skia-path",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tiny-skia-path"
|
|
||||||
version = "0.12.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "edca365c3faccca67d06593c5980fa6c57687de727a03131735bb85f01fdeeb9"
|
|
||||||
dependencies = [
|
|
||||||
"arrayref",
|
|
||||||
"bytemuck",
|
|
||||||
"strict-num",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ttf-parser"
|
name = "ttf-parser"
|
||||||
version = "0.25.1"
|
version = "0.25.1"
|
||||||
|
|||||||
@@ -5,4 +5,3 @@ edition = "2024"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
macroquad = "0.4.16"
|
macroquad = "0.4.16"
|
||||||
tiny-skia = "0.12.0"
|
|
||||||
@@ -17,13 +17,6 @@ the simulation can be ran with:
|
|||||||
cargo run --bin anim
|
cargo run --bin anim
|
||||||
```
|
```
|
||||||
|
|
||||||
Alternatively you can generate a trace image of the path the outer bob
|
|
||||||
takes with:
|
|
||||||
|
|
||||||
```
|
|
||||||
cargo run --bin trace
|
|
||||||
```
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Copyright © Camden Dixie O'Brien, available under the Komorebi 2.0.0
|
Copyright © Camden Dixie O'Brien, available under the Komorebi 2.0.0
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
use symplectic_double_pendulum::*;
|
use dpsim::*;
|
||||||
|
|
||||||
use macroquad::prelude::*;
|
use macroquad::prelude::*;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
use symplectic_double_pendulum::*;
|
use dpsim::*;
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufWriter, Write};
|
use std::io::{BufWriter, Write};
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
use symplectic_double_pendulum::*;
|
use dpsim::*;
|
||||||
|
|
||||||
use std::ops::{Add, Mul};
|
use std::ops::{Add, Mul};
|
||||||
|
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
use symplectic_double_pendulum::*;
|
|
||||||
|
|
||||||
use tiny_skia::*;
|
|
||||||
|
|
||||||
const WIDTH: u32 = 800;
|
|
||||||
const HEIGHT: u32 = 800;
|
|
||||||
|
|
||||||
const MIN: f32 = -2.0;
|
|
||||||
const MAX: f32 = 2.0;
|
|
||||||
const MARGIN: f32 = 0.2;
|
|
||||||
|
|
||||||
fn system_xy(q: &DoublePendulum) -> [f64; 2] {
|
|
||||||
[
|
|
||||||
q.theta.sin() + (q.theta + q.phi).sin(),
|
|
||||||
q.theta.cos() + (q.theta + q.phi).cos()
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn canvas_xy(q: &DoublePendulum) -> [f32; 2] {
|
|
||||||
system_xy(q).map(|x| (x as f32 * (1.0 - MARGIN) - MIN) * WIDTH as f32 / (MAX - MIN))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let omega = 500.0;
|
|
||||||
let h = 1e-3;
|
|
||||||
let t = 20.0;
|
|
||||||
|
|
||||||
let mut state = Augmented::from(State {
|
|
||||||
q: DoublePendulum { theta: std::f64::consts::PI, phi: 0.1 },
|
|
||||||
p: DoublePendulum { theta: 0.0, phi: 0.0 },
|
|
||||||
}, omega);
|
|
||||||
|
|
||||||
let path = {
|
|
||||||
let mut pb = PathBuilder::new();
|
|
||||||
|
|
||||||
let [x, y] = canvas_xy(&state.average().q);
|
|
||||||
pb.move_to(x, y);
|
|
||||||
|
|
||||||
let n = (t / h) as u32;
|
|
||||||
for _ in 0..n {
|
|
||||||
state.evolve(h);
|
|
||||||
let [x, y] = canvas_xy(&state.average().q);
|
|
||||||
pb.line_to(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
pb.finish().unwrap()
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut paint = Paint::default();
|
|
||||||
paint.set_color_rgba8(0, 0, 0, 0xff);
|
|
||||||
paint.anti_alias = true;
|
|
||||||
let mut stroke = Stroke::default();
|
|
||||||
stroke.width = 4.0;
|
|
||||||
stroke.line_cap = LineCap::Round;
|
|
||||||
let mut pixmap = Pixmap::new(WIDTH, HEIGHT).unwrap();
|
|
||||||
pixmap.stroke_path(&path, &paint, &stroke, Transform::identity(), None);
|
|
||||||
pixmap.save_png("trace.png").unwrap();
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user