fillet betwenn two lines

Hello!Is there an algo to solve the position of the tangent points and circle center between two given lines?ThanksMaelvon
[150 byte] By [lesmaresjaunesa] at [2007-9-29 11:02:23]
# 1

The perpendicular distance from a point(x, y) to a line y = a.x is (a.x-y)/sqrt(1+a**2).

If we have two lines, y = a.x and y = b.x, and distance r, we have two equations:

r = (a.x-y)/sqrt(1+a**2);

r = (b.x-y)/sqrt(1+b**2)

and solve for both x and y, giving:

x = r.(sqrt(1+a**2) - sqrt(1+b**2)) / (a - b);

y = a.x - r.sqrt(1+a**2);

this has four solutions, as can be seen from:

import java.awt.*;

import java.applet.*;

public class Fillets extends Applet {

double a = 0.5;

double b = 2.0;

double r = 40.0;

public void init () {

new Thread (new Runnable() {

public void run () {

try {

while(true) {

synchronized(this) {

Thread.sleep(250);

a+=0.2;

b-=0.1;

repaint();

}

}

} catch (InterruptedException ie) {

return;

}

}

}).start();

}

public void paint (Graphics g) {

int ox = getWidth()/2;

int oy = getHeight()/2;

g.setColor(Color.darkGray);

g.drawLine(0, oy, 2*ox, oy);

g.drawLine(ox, 0, ox, 2*oy);

g.setColor(Color.blue);

g.drawLine(0, oy - (int)(-ox*a), 2*ox, oy - (int)(ox*a));

g.setColor(Color.green);

g.drawLine(0, oy - (int)(-ox*b), 2*ox, oy - (int)(ox*b));

// maths bit here

double sqrt_1_plus_a2 = Math.sqrt(1.0+a*a);

double sqrt_1_plus_b2 = Math.sqrt(1.0+b*b);

// no solution if a==b

if (Math.abs(a-b)>1e-6) {

double x;

double y;

g.setColor(Color.cyan);

for (int sgna = 0; sgna<2; sgna++) {

for (int sgnb = 0; sgnb<2; sgnb++) {

// math bit here

x = r * (sqrt_1_plus_a2 - sqrt_1_plus_b2) / (a - b);

y = a * x - r * sqrt_1_plus_a2;

g.drawLine(ox + (int) x - 4, oy - (int) y,

ox + (int) x + 4, oy - (int) y);

g.drawLine(ox + (int) x, oy - (int) y - 4,

ox + (int) x, oy - (int) y + 4);

g.drawOval(ox + (int) (x - r), oy - (int) (y + r),

2*(int)r, 2*(int)r);

sqrt_1_plus_a2 = -sqrt_1_plus_a2;

}

sqrt_1_plus_b2 = -sqrt_1_plus_b2;

}

}

}

}

Pete

Pete_Kirkhama at 2007-7-15 0:26:21 > top of Java-index,Other Topics,Algorithms...
# 2

> The perpendicular distance from a point(x, y) to a

> line y = a.x is (a.x-y)/sqrt(1+a**2).

>

> If we have two lines, y = a.x and y = b.x, and

> distance r, we have two equations:

>

> r = (a.x-y)/sqrt(1+a**2);

> r = (b.x-y)/sqrt(1+b**2)

>

> and solve for both x and y, giving:

>

> x = r.(sqrt(1+a**2) - sqrt(1+b**2)) / (a - b);

> y = a.x - r.sqrt(1+a**2);

>

> this has four solutions, as can be seen from:

Where did the question say that the radius of the

circle was given?

As stated the question has infinitely many solutions.

The centres of all the circles are on the bisector

of the angle between the lines (or the parallel

line mid way between the two if they are parallel).

An alternative method (which doesn't assume that

the lines pass through the origin), is to find the

bisector. Use trigonometry to get the angle between

the lines tan(B-A) = (tan(B) - tan(A))/(1 - tan(A)*tan(B)),

halve the angle and add to A to get the bisector.

That's essentially what Pete did, but by a slightly

different method. If you find the point on the bisector

that gives a radius of 1, then you need to move the

centre a distance r times as far from the point of

intersection of the lines to get a radius r.

TerryMoorea at 2007-7-15 0:26:21 > top of Java-index,Other Topics,Algorithms...