Discuss and collaborate on GML scripts

You are not logged in.

- Topics: Active | Unanswered

**Marchal_Mig12****Member**- Registered: 2009-05-21
- Posts: 72

Hi,

Edit : nevermind, it works. Feel free to try to optimise it and post it on gmlscripts.

```
var x1 = argument0;
var y1 = argument1;
var x2 = argument2;
var y2 = argument3;
var circleX = argument4;
var circleY = argument5;
var circleR = argument6
var dx = x2 - x1;
var dy = y2 - y1;
var denominator = sqr(dx) + sqr(dy);
if ( denominator > 0 ) {
var position = ( ( circleX - x1 ) * dx +( circleY - y1 ) * dy ) / denominator;
var px = x1 + position * dx;
var py = y1 + position * dy;
var m = point_distance( px, py, circleX, circleY ) / circleR;
if ( m <= 1 ){
var offset = circleR * sin( arccos( m ) );
var mag = sqrt( denominator );
dx /= mag;
dy /= mag;
//Intersection points
ix1 = px + offset * dx;
iy1 = py + offset * dy;
ix2 = px - offset * dx;
iy2 = py - offset * dy;
return true;
}else{
return false;
}
}
```

Thanks

*Last edited by Marchal_Mig12 (2013-07-13 18:18:00)*

Offline

**xot****Administrator**- Registered: 2007-08-18
- Posts: 1,201

Heh, OK. I'll check it out.

*Abusing forum power since 1986.*

Offline