Advertisement
Weesals

Untitled

May 9th, 2021 (edited)
3,133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Centre of circle
  2. vec2 ctr;
  3. // Intersection tangents (or just p1-p0 and p2-p1)
  4. vec2 tan1;
  5. vec2 tan2;
  6.  
  7. // Get normal angles (ie. which angle points towards the intersection point)
  8. var ang1 = atan2(tan1.y, tan1.x) - PI/2;
  9. var ang2 = atan2(tan2.y, tan2.x) - PI/2;
  10. // Get delta between angles
  11. var angD = ang2 - ang1;
  12. angD -= 2PI * round(angD / 2PI);
  13. // Calculate number of segment points
  14. // (5 points per 180 degree turn)
  15. int segC = abs(angD) / (PI/5);
  16. for (int a=0; a<segC; ++a) {
  17.     // Stepping angle between the intersection points
  18.     var ang = ang1 + angD * a / (segC - 1);
  19.     // Calculate new vectors
  20.     var tan = vec2(cos(ang), sin(ang));
  21.     var nrm = vec2(-sin(ang), cos(ang));
  22.     points.Add(ctr + tan * Radius - nrm * Width);
  23.     points.Add(ctr + tan * Radius + nrm * Width);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement