Created
March 5, 2020 16:09
-
-
Save shyoshyo/87bad5980302568245d51fd79e897811 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<assert.h> | |
#include<math.h> | |
float ax = 4.5f, ay = 5.5f; | |
float r = 2.0f; | |
float ox = -3.4f, oy = -5.4f; | |
int main() | |
{ | |
float l = sqrtf((ax - ox) * (ax - ox) + (ay - oy) * (ay - oy)); | |
assert(l > r); | |
float sin_theta = r / l; | |
float cos_theta = sqrtf(1.f - sin_theta * sin_theta); | |
// sin_theta = - sin_theta; | |
float _ox = ax + cos_theta * (ox - ax) + sin_theta * (oy - ay); | |
float _oy = ay - sin_theta * (ox - ax) + cos_theta * (oy - ay); | |
float lap = sqrtf(l * l - r * r); | |
float px = ax + (_ox - ax) * lap / l; | |
float py = ay + (_oy - ay) * lap / l; | |
printf("%f %f\n", px, py); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment