Skip to content

Instantly share code, notes, and snippets.

@shyoshyo
Created March 5, 2020 16:09
Show Gist options
  • Save shyoshyo/87bad5980302568245d51fd79e897811 to your computer and use it in GitHub Desktop.
Save shyoshyo/87bad5980302568245d51fd79e897811 to your computer and use it in GitHub Desktop.
#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