Using Google Dart as an online collaboration calculator

How to use Dart as an online collaboration tool

When I’m stuck on math questions I turn to my friend Chris who can write pixel perfect C# code in a chat window. Yesterday I needed to calculate where a line intersects a circle so after a few internet searches I came up with this Dart code:

double x1=100.0;
double y1=100.0;
double x2=200.0;
double y2=200.0;
double radians=Math.atan2(y2-y1, x2-x1) ;
double radius=50.0;
double y3=y2+radius * Math.cos(radians);
double x3=x2+radius * Math.sin(radians);

As it turned out, I made two mistakes. The last two lines should be:

double y3=y1+radius * Math.sin(radians);
double x3=x1+radius * Math.cos(radians);

How did I find out? Easy! I entered the code in the Dart editor and sent the generated link to Chris. He looked at the code, made some changes and sent a link back.

Calculate intersection point of line and circle

I wrote this post to point out the power of a shared code editor and to show how to calculate where a line intersects a circle. Open the link in a recent Chrome or Firefox browser and press play!

Written by Loek van den Ouweland on October 14, 2011. Questions regarding this artice? You can send them to the address below.
By using this site, you acknowledge that you have read and understand our Cookie and Privacy Policy.