Welcome! Log In Create A New Profile

Advanced

Trig challenge

Posted by QuackingPlums 
Trig challenge
February 04, 2014 10:28AM
Not sure if this is the right section(especially since nobody seems to read this one!) but I've been scratching my head over this for a few days now and I realise that my high-school trig has long since departed my grey matter, so any help would be appreciated.

Short version is; I'm trying to fill an arbitrary shape with rounded triangles in OpenSCAD. I've simplified a pair of expressions that describe the canonical problem of filling a rectangle with two triangles but I can't for the life of me figure out how to simplify/solve them.

The equations I need to solve are:
y = a - 2r + w
        ------
        sin x

y =   b
    -----
    tan x
where a, b, r and w are known and 0 < x < 90 degrees.

If I use the following examples for my known values (a = 70, b = 30, r = 1 and w = 3) then I get:
y = 70 - 2 + 3
         ------
         sin x

y =  30
    -----
    tan x
and if I plot the resulting expressions using https://www.desmos.com/calculator then I get the following:

I can see the two graphs intersect exactly once within my range of interest - at around x = 27.

Is it possible to solve those two expressions generically for x? I'm thinking that I'm missing a few trick around trig identities, but I just can't simplify it into something I can use. confused smiley

To prove to myself that the above expressions are correct, if I hard-code the output in OpenSCAD then I get this:

which is what I'm looking for but is only correct for those explicit values of a, b, r and w!
Re: Trig challenge
February 05, 2014 07:43AM
Quote
QuackingPlums
Short version is; I'm trying to fill an arbitrary shape with rounded triangles in OpenSCAD. I've simplified a pair of expressions that describe the canonical problem of filling a rectangle with two triangles but I can't for the life of me figure out how to simplify/solve them.

I think I need a more detailed description than this.
You said "arbitrary shape" with "rounded triangles" but your example uses a rectangle (a x b) and two triangles.

What kind of object are you trying to create?

The two triangles as 3d object or a rectangle with two triangle cutouts?

I am assuming that:
  • a = Long side of the rectangle
  • b = Short side of the rectangle
  • r = radius of the curvature
  • w = The distance between anything and an edge of the triangle

If this is the case, then you don't need any trigonometry (or algebra) at all!

You place the circles in the appropriate locations.

Triangles.scad:
a = 70;
b = 30;
r = 2;
w = 3;

th = 4;
$fn = 50;

module TriangleA() {
	color([1,0,0])
		hull() {
			translate([w + r, a - w - r, th/2])
				cylinder(r = r, h = th, center = true);
				
			translate([w + r, w + r, th/2])
				cylinder(r = r, h = th, center = true);

			translate([b - w - 4.6 * r, w + r, th/2])
				cylinder(r = r, h = th, center = true);
		}
}

module TriangleB() {
	color([0,1,0])
		hull() {
			translate([w + 4.6 * r, a - w - r, th/2])
				cylinder(r = r, h = th, center = true);
				
			translate([b - w - r, a - w - r, th/2])
				cylinder(r = r, h = th, center = true);

			translate([b - w - r, w + r, th/2])
				cylinder(r = r, h = th, center = true);
		}
}

module Rectangle() {
	color([0.7,0.7,0.7])
		translate(0,0,-0.5)
			cube([b, a, 1], false);
}

TriangleA();
TriangleB();

Rectangle();



The script still needs some tweaking for it to work properly for widely varying values of r & w but it should give you the idea.

So the question remains, WHY do you want to do this?

Edited 2 time(s). Last edit at 02/05/2014 09:26AM by rhmorrison.


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Re: Trig challenge
February 05, 2014 09:50AM
Hi, and thanks for replying!

My problem is a variation on the convex polygon puzzle, so my rectangle was just a canonical example (because right angled triangles are slightly easier to work with).
Once I have this I will aim to solve for all convex polygons with n vertices, for which the transformational maths is easy.

One use for this could be to cut triangular holes out of flat shapes, thus leaving the strongest shape possible for a given minimum amount of material, but I am actually just seeing this as a challenge, rather than a specific problem to solve. grinning smiley

Anyway, back to the problem: solving for triangles is easy, but once I factor in a corner radius then the math becomes harder because whilst I can accommodate w in the x and y directions, I need to know the angle of that edge in order to calculate the effect it will have on the gap.

First of all, if I understand your suggestion correctly then I *think* you meant this? (just a typo on the right edge that currently makes it too narrow):
a = 70;
b = 30;
r = 1;
w = 3;

th = 4;
$fn = 50;

module TriangleA() {
	color([1,0,0])
		hull() {
			translate([w + r, a - w - r, th/2])
				cylinder(r = r, h = th, center = true);
				
			translate([w + r, w + r, th/2])
				cylinder(r = r, h = th, center = true);

			translate([b		// width of base
					  - w	// gap between (green) triangleB and edge
					  - 2*r	// tip of triangleB
					  - w	// gap between triangles
					  - r	// corner radius of (red) triangleA
					  , w + r, th/2])
				cylinder(r = r, h = th, center = true);
		}
}

module TriangleB() {
	color([0,1,0])
		hull() {
			translate([w + 2 * r + w + r, a - w - r, th/2])
				cylinder(r = r, h = th, center = true);
				
			translate([b - w - r, a - w - r, th/2])
				cylinder(r = r, h = th, center = true);

			translate([b - w - r, w + r, th/2])
				cylinder(r = r, h = th, center = true);
		}
}

module Rectangle() {
	color([0.7,0.7,0.7])
		translate(0,0,-0.5)
			cube([b, a, 1], false);
}

TriangleA();
TriangleB();

Rectangle();

The problem with this approach is that the orthogonal distance between the centres of the corner radii are w, but the perpendicular distance is less for angles < 90deg. For angles near 90 it's not noticeable, but the greater that angle the greater the error:
e.g.: original (corrected as above); looks fine:


With a = b = 30; looks slightly narrower than the edges:


With a = 20, b = 30; clearly wrong:


Simplifying the problem further: how far apart do I have to place two cylinders to allow a bar of constant thickness to fit between them at a given angle?


In this illustration, the yellow bar is w wide and as you can see, it fits perfectly (as it should!)

However, if I now rotate that bar by 45 degrees you can see how it cuts into the cylinders (% modifier added for clarity):


How far would I need to move the cylinders further apart in order to accommodate the increased width caused by rotating the bar?

In this example, the distance between the cylinders in the x direction is a function of the angle and could be calculated easily if the angle were known, but in the overall problem the angle is also a function of the containing polygon (or a canonical rectangle!)

Is that any clearer? I guess I won't be called to write high-school math papers any time soon... grinning smiley
Re: Trig challenge
February 05, 2014 10:14AM
Yes, the gap between probably needs trigonometry to find d.

In other words the two left cylinders and two right cylinders are known, the other two are the same x distance d apart, one is the LL + d, the other us UR - d such that the distance between the parallel lines through the center of the circles is 2*r + w.

i.e.
1A                              3A      1B



2A    3B                                2B

For triangles A and be we can simply calculate 1A, 2A, 1B and 2B.
3A and 3B are the same x distance from their corresponding cylinder (x +- d).

Let me think about this, I don't think it will be too difficult to solve...


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Re: Trig challenge
February 28, 2014 06:02AM
I solved this by the way. WIth a little help from a math forum I was reminded that trig identities have another use; by expressing my problem as
sin x = a - y  = opp
        ------   ---
        2r + w   hyp

tan x = b = opp
        -   ---
        y   adj

I could then use Pythagoras to work out the 'missing sides', which allows me to substitute out all the trig functions.

I can then re-write the expression as a quadratic in the form
a y^2 + b y + c = 0
and solve for y using the quadratic formula, substituting my coefficients for a, b and c.

This works for my canonical rectangle, so now I just have to extend to cover my generic polygon! grinning smiley
Re: Trig challenge
March 02, 2014 07:04AM
Quote
QuackingPlums
Not sure if this is the right section(especially since nobody seems to read this one!) !


off topic

You are great in math, but not in logic: How could you define that nobody reads this forum ?
I read it every day, it is even my 'baby' as I asked for it to be defined :-)

btw; these discussions are what is it intended for, so keep up the good work

Thomas


www.3daybreaker.blogspot.com

Orca V4.4 rebuild to Ramps with Mk8 and E3D, as well as a Rostock Delta Mini and an OLO in backorder :-)
Re: Trig challenge
March 03, 2014 03:50AM
Haha, I think the reason why I needed help in the first place is that I'm not great in math, but the fact that you think I am means a lot to me! grinning smiley

I didn't mean to offend when I inferred that nobody reads it - I just meant that compared to the OpenSCAD mailing list (which seems very active but the archaic way of having to subscribe to the mailer etc seems a bit 1980s to me and presents an obstacle to quick and easy discussions like this one - for me anyway), activity in this section of the RepRap forum is very light.

When I first found this section (and responded to your welcome post!) it was a good six months after you'd created it, yet there were only about three threads. I'm pleased to see that it's building momentum now, but it's still nowhere near the level of activity in the official rocklinux feed - even if you strip out all the Nike and Vans spam posts! grinning smiley

EDIT:
Speaking of which, have you seen the release notes for the 2014.03 candidate release? Search and Replace has finally been added to the editor! grinning smiley

Edited 1 time(s). Last edit at 03/03/2014 03:52AM by QuackingPlums.
Re: Trig challenge
March 04, 2014 01:17AM
No offense taken. I was teasing!

I am glad the section starts to live.
I get great feedback in the NL and slicer sections, so I hope this will start to prove itself over time

Thomas


www.3daybreaker.blogspot.com

Orca V4.4 rebuild to Ramps with Mk8 and E3D, as well as a Rostock Delta Mini and an OLO in backorder :-)
Sorry, only registered users may post in this forum.

Click here to login