-
Notifications
You must be signed in to change notification settings - Fork 0
/
spring_point.cpp
34 lines (28 loc) · 969 Bytes
/
spring_point.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//
// Created by 16411 on 9/3/2022.
//
#include "spring_point.h"
num_vector spring_point::get_position() {
return position;
}
num_vector spring_point::compute_force() {
double k1 = 1, k2 = 1, mu = 0.1;
num_vector position_(position.get_x() - 200, (position.get_y() - 200) / 1.25);
num_vector force = -position_ * k1 - speed * mu + NEGATIVE_Y_VECTOR * 20;
// double sin = position_.get_x() / position_.length(), cos = position_.get_y() / position_.length();
// num_vector force(k2 * sin * cos - k1 * position_.length() * sin, k2 * sin * sin - k1 * position_.length() * cos);
// force = force - speed * mu + POSITIVE_Y_VECTOR * 10;
return force;
}
void spring_point::update_position() {
double alpha = 0.1;
position = position + speed * alpha;
}
void spring_point::update_speed() {
double alpha = 0.1;
speed = speed + compute_force() * alpha;
}
void spring_point::update_() {
update_speed();
update_position();
}