discuss@lists.openscad.org

OpenSCAD general discussion

View all threads

Re: Tangential arc between two circles

AM
Adrian Mariano
Fri, Jan 14, 2022 3:56 AM

In your arc drawing code, ang2 is very close to zero in one case, and close
to 360 in the other case.  You should somehow explicitly resolve the
ambiguity about how to draw the arc between two points, as there are always
two options.

On Thu, Jan 13, 2022 at 10:37 PM gadgetChris via Discuss <
discuss@lists.openscad.org> wrote:

---------- Forwarded message ----------
From: gadgetChris hobbies@klomp.ca
To: OpenSCAD general discussion discuss@lists.openscad.org
Cc:
Bcc:
Date: Thu, 13 Jan 2022 22:37:16 -0500
Subject: [OpenSCAD] Re: Tangential arc between two circles
I have this weird behaviour of flipping the angles.
I've not yet been able to pin-point where the issue is?

rt=74.711;  // radius tangent
[image: image.png]

rt=74.712;  // radius tangent
[image: image.png]

//
// https://www.frassek.org/2d-mathe/kreise-verbinden/
//
// $t = animation step
$fn=40;
cx1=0; // circle 1
cy1=0;
cr1=20;
//cx2=5+sin($t*360)*17; // circle 2
cx2=50;
cy2=50;
cr2=2.5;
rt=74.712;  // radius tangent

// do we have valid values

d12=sqrt( (cx1-cx2)^2+(cy1-cy2)^2 ); // distance between circles
echo("distance between circles=",d12);
testR=(cr1+cr2+d12)/2; //
assert(rt > testR, concat("Tangent radius not big enough! Needs to be
larger than:",str(testR)));

function rm(theta)=[[cos(theta),sin(theta)],[-sin(theta),cos(theta)]];

function ang(x,y)=
x>=0&&y>=0?atan(y/x):x<0&&y>=0?180-abs(atan(y/x)):x<0&&y<0?180+abs(atan(y/x)):360-abs(atan(y/x));

function
cir(r,p=[0,0],s=50)=[for(i=[0:360/s:360-360/s])[p.x+rcos(i),p.y+rsin(i)]];

module p_line(path,size=.5){
for(i=[0:len(path)-1])
let(p0=path[i],p1=i<len(path)-1?path[i+1]:path[0])

 hull(){
 translate(p0)circle(size/2);
 translate(p1)circle(size/2);}}

module p_lineo(path,size=.5){
for(i=[0:len(path)-2])
let(p0=path[i],p1=path[i+1])

 hull(){
 translate(p0)circle(size/2);
 translate(p1)circle(size/2);}}

function
arc(radius,ang1=0,ang2=355,cp=[0,0],s=20)=[for(i=[ang1:(ang2-ang1)/s:ang2])cp+[radiuscos(i),radiussin(i)]];

function 2cir_tarc(r1,r2,cp1,cp2,r)=
let(
l1=norm(cp2-cp1),
l2=r-r1,
l3=r-r2,
x=(l2^2-l3^2+l1^2)/(2l1),
h=sqrt(l2^2-x^2),
v1=cp2-cp1,u1=v1/norm(v1),
p0=cp1+u1
x,
cp3=p0-u1hrm(90),
v2=cp2-cp3,u2=v2/norm(v2),
v3=cp1-cp3,u3=v3/norm(v3),
ang1=ang(u2.x,u2.y),
ang2=ang(u3.x,u3.y)
)
arc(r,ang1,ang2,cp3);

arc=2cir_tarc(cr1,cr2,[cx1,cy1],[cx2,cy2],rt);
arc2=2cir_tarc(cr2,cr1,[cx2,cy2],[cx1,cy1],rt);

color("cyan") p_lineo(arc,.2);
color("green") p_lineo(arc2,.2);
p_line(cir(cr1,[cx1,cy1]),.2);
p_line(cir(cr2,[cx2,cy2]),.2);

On Sat, Jan 8, 2022 at 6:26 AM MichaelAtOz oz.at.michael@gmail.com
wrote:

I am using openSCAD 2021.09.12 and it not showing any errors or

warnings

Something to check against a recent snapshot.


From: Sanjeev Prabhakar [mailto:sprabhakar2006@gmail.com]
Sent: Sat, 8 Jan 2022 20:51
To: OpenSCAD general discussion
Subject: [OpenSCAD] Re: Tangential arc between two circles

Ah, just downloaded the Jan 2021 version

Remove true from line number 9,10,17,18

Then there is no error

On Sat, 8 Jan 2022, 14:58 MichaelAtOz, oz.at.michael@gmail.com wrote:

Hmmm, don't know why.


From: Sanjeev Prabhakar [mailto:sprabhakar2006@gmail.com]
Sent: Sat, 8 Jan 2022 18:20
To: OpenSCAD general discussion
Subject: [OpenSCAD] Re: Tangential arc between two circles

Thanks for your comments

I am using openSCAD 2021.09.12 and it not showing any errors or warnings

On Sat, 8 Jan 2022, 12:15 MichaelAtOz, oz.at.michael@gmail.com wrote:

Note that circle() does not take a Boolean, in 4 places. That now
generates warnings.

Also an extra comma


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

---------- Forwarded message ----------
From: gadgetChris via Discuss discuss@lists.openscad.org
To: OpenSCAD general discussion discuss@lists.openscad.org
Cc: gadgetChris hobbies@klomp.ca
Bcc:
Date: Thu, 13 Jan 2022 22:37:16 -0500
Subject: [OpenSCAD] Re: Tangential arc between two circles


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

In your arc drawing code, ang2 is very close to zero in one case, and close to 360 in the other case. You should somehow explicitly resolve the ambiguity about how to draw the arc between two points, as there are always two options. On Thu, Jan 13, 2022 at 10:37 PM gadgetChris via Discuss < discuss@lists.openscad.org> wrote: > > > > ---------- Forwarded message ---------- > From: gadgetChris <hobbies@klomp.ca> > To: OpenSCAD general discussion <discuss@lists.openscad.org> > Cc: > Bcc: > Date: Thu, 13 Jan 2022 22:37:16 -0500 > Subject: [OpenSCAD] Re: Tangential arc between two circles > I have this weird behaviour of flipping the angles. > I've not yet been able to pin-point where the issue is? > > rt=74.711; // radius tangent > [image: image.png] > > > rt=74.712; // radius tangent > [image: image.png] > > // > // https://www.frassek.org/2d-mathe/kreise-verbinden/ > // > // $t = animation step > $fn=40; > cx1=0; // circle 1 > cy1=0; > cr1=20; > //cx2=5+sin($t*360)*17; // circle 2 > cx2=50; > cy2=50; > cr2=2.5; > rt=74.712; // radius tangent > > // do we have valid values > > d12=sqrt( (cx1-cx2)^2+(cy1-cy2)^2 ); // distance between circles > echo("distance between circles=",d12); > testR=(cr1+cr2+d12)/2; // > assert(rt > testR, concat("Tangent radius not big enough! Needs to be > larger than:",str(testR))); > > > function rm(theta)=[[cos(theta),sin(theta)],[-sin(theta),cos(theta)]]; > > function ang(x,y)= > x>=0&&y>=0?atan(y/x):x<0&&y>=0?180-abs(atan(y/x)):x<0&&y<0?180+abs(atan(y/x)):360-abs(atan(y/x)); > > function > cir(r,p=[0,0],s=50)=[for(i=[0:360/s:360-360/s])[p.x+r*cos(i),p.y+r*sin(i)]]; > > module p_line(path,size=.5){ > for(i=[0:len(path)-1]) > let(p0=path[i],p1=i<len(path)-1?path[i+1]:path[0]) > > hull(){ > translate(p0)circle(size/2); > translate(p1)circle(size/2);}} > > module p_lineo(path,size=.5){ > for(i=[0:len(path)-2]) > let(p0=path[i],p1=path[i+1]) > > hull(){ > translate(p0)circle(size/2); > translate(p1)circle(size/2);}} > > function > arc(radius,ang1=0,ang2=355,cp=[0,0],s=20)=[for(i=[ang1:(ang2-ang1)/s:ang2])cp+[radius*cos(i),radius*sin(i)]]; > > function 2cir_tarc(r1,r2,cp1,cp2,r)= > let( > l1=norm(cp2-cp1), > l2=r-r1, > l3=r-r2, > x=(l2^2-l3^2+l1^2)/(2*l1), > h=sqrt(l2^2-x^2), > v1=cp2-cp1,u1=v1/norm(v1), > p0=cp1+u1*x, > cp3=p0-u1*h*rm(90), > v2=cp2-cp3,u2=v2/norm(v2), > v3=cp1-cp3,u3=v3/norm(v3), > ang1=ang(u2.x,u2.y), > ang2=ang(u3.x,u3.y) > ) > arc(r,ang1,ang2,cp3); > > arc=2cir_tarc(cr1,cr2,[cx1,cy1],[cx2,cy2],rt); > arc2=2cir_tarc(cr2,cr1,[cx2,cy2],[cx1,cy1],rt); > > color("cyan") p_lineo(arc,.2); > color("green") p_lineo(arc2,.2); > p_line(cir(cr1,[cx1,cy1]),.2); > p_line(cir(cr2,[cx2,cy2]),.2); > > > On Sat, Jan 8, 2022 at 6:26 AM MichaelAtOz <oz.at.michael@gmail.com> > wrote: > >> > I am using openSCAD 2021.09.12 and it not showing any errors or >> warnings >> >> Something to check against a recent snapshot. >> >> >> >> >> ------------------------------ >> >> *From:* Sanjeev Prabhakar [mailto:sprabhakar2006@gmail.com] >> *Sent:* Sat, 8 Jan 2022 20:51 >> *To:* OpenSCAD general discussion >> *Subject:* [OpenSCAD] Re: Tangential arc between two circles >> >> >> >> Ah, just downloaded the Jan 2021 version >> >> Remove true from line number 9,10,17,18 >> >> Then there is no error >> >> >> >> On Sat, 8 Jan 2022, 14:58 MichaelAtOz, <oz.at.michael@gmail.com> wrote: >> >> Hmmm, don't know why. >> >> >> >> >> ------------------------------ >> >> *From:* Sanjeev Prabhakar [mailto:sprabhakar2006@gmail.com] >> *Sent:* Sat, 8 Jan 2022 18:20 >> *To:* OpenSCAD general discussion >> *Subject:* [OpenSCAD] Re: Tangential arc between two circles >> >> >> >> Thanks for your comments >> >> I am using openSCAD 2021.09.12 and it not showing any errors or warnings >> >> >> >> On Sat, 8 Jan 2022, 12:15 MichaelAtOz, <oz.at.michael@gmail.com> wrote: >> >> Note that circle() does not take a Boolean, in 4 places. That now >> generates warnings. >> >> Also an extra comma >> >> >> >> >> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > > > > ---------- Forwarded message ---------- > From: gadgetChris via Discuss <discuss@lists.openscad.org> > To: OpenSCAD general discussion <discuss@lists.openscad.org> > Cc: gadgetChris <hobbies@klomp.ca> > Bcc: > Date: Thu, 13 Jan 2022 22:37:16 -0500 > Subject: [OpenSCAD] Re: Tangential arc between two circles > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >