Uploading previous work

This commit is contained in:
Sacha Ligthert 2022-10-17 18:43:16 +02:00
parent 58ba643f81
commit 96b00a71c0
4 changed files with 155 additions and 0 deletions

55
1axis.go Normal file
View File

@ -0,0 +1,55 @@
package main
import (
"fmt"
"time"
)
// Calculate the velocity (force/mass)
func calcVelocity(m int64, f int64) float64 {
//fmt.Println(float64(f) / float64(m))
acceleration := float64(f) / float64(m)
return acceleration
}
func main() {
// Block center (in mm)
var x int64
var y int64
var z int64
// Velocity (mm/s)
var v float64
// Block mass (in kg)
var mass int64
// Force (Newton)
//var force int
// Initialize values
x = 0
y = 0
z = 0
v = 0
mass = 24
//force = 10
// Array of force applied
force := []int{0, -1, -1, -2, -1, -1, 0, 0, 0, 0, 0}
for i, f := range force {
fmt.Printf("Gonna divide %d by %d\n", f, mass)
v = v + calcVelocity(mass, int64(f))
fmt.Printf("Frame %d: velocity: %f (m/s)\n", i, v)
x = x + int64(v*1000)
fmt.Printf(" Pos: %d x %d x %d\n", x, y, z)
time.Sleep(1 * time.Second)
}
}

46
2axis.go Normal file
View File

@ -0,0 +1,46 @@
package main
import (
"fmt"
"time"
)
type SpaceObj struct {
x int64 // Pos x
y int64 // Pos y
z int64 // Pos z
vx float64 // Velocity x (mm)
vy float64 // Velocity y (mm)
vz float64 // Velocity z (mm)
m int64 // mass (kg)
}
type Force struct {
x int64
y int64
z int64
}
func calcAcceleration(m int64, f int64) float64 {
return float64(f) / float64(m)
}
func main() {
user := SpaceObj{0, 0, 0, 0, 0, 0, 52}
vectors := []Force{{1, 0, 0}, {0, 1, 0}, {-1, 0, 0}, {-1, -1, 0}, {1, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 1, 0}, {1, 0, 0}, {0, 0, 0}, {0, 0, 0}}
for i, f := range vectors {
fmt.Printf("Frame: %d; Vector: %d %d %d\n", i, f.x, f.y, f.z)
user.vx = user.vx + calcAcceleration(user.m, f.x)
user.vy = user.vy + calcAcceleration(user.m, f.y)
fmt.Printf(" velocity: %f %f %f (m/s)\n", user.vx, user.vy, user.vz)
user.x = user.x + int64(user.vx*1000)
user.y = user.y + int64(user.vy*1000)
fmt.Printf(" Pos: %d x %d x %d\n", user.x, user.y, user.z)
time.Sleep((1 * time.Second))
}
}

51
3axis.go Normal file
View File

@ -0,0 +1,51 @@
package main
import (
"fmt"
"time"
)
type SpaceObj struct {
x int64 // Pos x
y int64 // Pos y
z int64 // Pos z
vx float64 // Velocity x (mm)
vy float64 // Velocity y (mm)
vz float64 // Velocity z (mm)
m int64 // mass (kg)
}
type Force struct {
x int64
y int64
z int64
}
func calcAcceleration(m int64, f int64) float64 {
return float64(f) / float64(m)
}
func main() {
user := SpaceObj{0, 0, 0, 0, 0, 0, 52}
vectors := []Force{{1, 0, -1}, {0, 1, 0}, {-1, 0, 0}, {-1, -1, -1}, {1, 0, 0}, {1, 0, 0}, {0, 1, -1}, {0, 1, 0}, {1, 0, 0}, {0, 0, -1}, {0, 0, 0}}
for i, f := range vectors {
fmt.Printf("Frame: %d; Vector: %d %d %d\n", i, f.x, f.y, f.z)
user.vx = user.vx + calcAcceleration(user.m, f.x)
user.vy = user.vy + calcAcceleration(user.m, f.y)
user.vz = user.vy + calcAcceleration(user.m, f.z)
fmt.Printf(" velocity: %f %f %f (m/s)\n", user.vx, user.vy, user.vz)
user.x = user.x + int64(user.vx*1000)
user.y = user.y + int64(user.vy*1000)
user.z = user.z + int64(user.vz*1000)
fmt.Printf(" Pos: %d x %d x %d\n", user.x, user.y, user.z)
time.Sleep((1 * time.Second))
}
}

3
old_go_mod Normal file
View File

@ -0,0 +1,3 @@
module git.sr.ht/~ligthert/Massdriver
go 1.19