Skip to content
Snippets Groups Projects
Commit 9912023a authored by Rafael László's avatar Rafael László :speech_balloon:
Browse files

angles and distances but not good

parent a6125173
Branches
No related tags found
No related merge requests found
......@@ -293,6 +293,18 @@ vec2 getInverse(vec2 p){
return p/(length(p)*length(p));
}
float getSiriusDistance(vec2 a, vec2 d) {
float x = a.x;
float y = a.y;
float dx = d.x - a.x;
float dy = d.y - a.y;
return sqrt(dx * dx + dy * dy) / (1 - x * x - y * y);
}
inline bool equal(const vec2 &a, const vec2 &b) {
return a.x < b.x + 0.0001 && a.x > b.x - 0.0001
&& a.y < b.y + 0.0001 && a.y > b.y - 0.0001;
}
class SiriusTriangle{
vec2 a,b,c;
......@@ -307,6 +319,12 @@ class SiriusTriangle{
return degree;
}
float normalizeAngle(float angle) {
if (angle > 0)
return angle;
return 2.0f * M_PI + angle;
}
std::vector<vec2> getOneSide(vec2 p1, vec2 p2){
// Inverse of p2
vec2 invp2 = getInverse(p2);
......@@ -363,36 +381,62 @@ class SiriusTriangle{
return generated;
}
float calculateAngle(std::vector<vec2> array, vec2 P ) {
for (int i = 0; i < array.size(); ++i) {
if (equal(array[i], P)) {
vec2 p = array[(i - 1 + array.size()) % array.size()] - P;
vec2 n = array[(i + 1) % array.size()] - P;
return abs(normalizeAngle(atan2(p.y, p.x)) - normalizeAngle(atan2(n.y, n.x))) / M_PI * 180.0f;
}
}
return 0;
}
public:
float sideAB=0, sideBC=0, sideCA=0;
vec2 ccAB, ccBC, ccCA;
float angleAB, angleBC, angleCA;
SiriusTriangle(vec2 p1, vec2 p2, vec2 p3) {
a = p1;
b = p2;
c = p3;
ab = getOneSide(a,b);
bc = getOneSide(b,c);
ca = getOneSide(c,a);
for (int i = 0; i < ab.size()-1; ++i) {
sideAB += getSiriusDistance(ab[i], ab[i+1]);
}
for (int i = 0; i < bc.size()-1; ++i) {
sideBC += getSiriusDistance(bc[i], bc[i+1]);
}
for (int i = 0; i < ca.size()-1; ++i) {
sideCA += getSiriusDistance(ca[i], ca[i+1]);
}
std::vector<vec2> getAB() {
printf("AB\n");
for(vec2 pp: ab) {
printf("%f %f\n", pp.x, pp.y);
angleAB = calculateAngle(ab, p1);
angleBC = calculateAngle(bc, p2);
angleCA = calculateAngle(ca, p3);
printf("Alpha: %3.6f, Beta: %3.6f, Gamma: %3.6f, Sum: %3.6f\n",
angleAB, angleBC, angleCA, angleAB + angleBC + angleCA
);
printf("AB: %3.6f, BC: %3.6f, CA: %3.6f\n",
sideAB, sideBC, sideCA
);
}
std::vector<vec2> getAB() {
return ab;
}
std::vector<vec2> getCA() {
printf("ca\n");
for(vec2 pp: ca) {
printf("%f %f\n", pp.x, pp.y);
}
return ca;
}
std::vector<vec2> getBC() {
printf("BC\n");
for(vec2 pp: bc) {
printf("%f %f\n", pp.x, pp.y);
}
return bc;
}
......@@ -477,6 +521,8 @@ std::vector<FilledTriangle> getEars(std::vector<vec2> points){
return tr;
}
std::vector<FilledTriangle> triangles;
std::vector<FilledTriangle> ears;
BaseCircle circle;
......@@ -553,14 +599,10 @@ void onMouse(int button, int state, int pX, int pY) { // pX, pY are the pixel co
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
userPoints.emplace_back(cX, cY);
// redpts.addPoint({cX, cY});
if (userPoints.size() == 3) {
SiriusTriangle st(userPoints[0], userPoints[1], userPoints[2]);
siriustriangles.emplace_back(st);
// linestrip.emplace_back(st.getAB());
// linestrip.emplace_back(st.getBC());
// linestrip.emplace_back(st.getCA());
std::vector<vec2> siriusPoints = st.getPoints();
linestrip.emplace_back(siriusPoints);
siriusPoints.pop_back(); // remove extra point
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment