[Arm-netbook] python coding help needed (sin, cosine, blah blah)

Luke Kenneth Casson Leighton lkcl at lkcl.net
Sat Jul 29 15:49:21 BST 2017


---
crowd-funded eco-conscious hardware: https://www.crowdsupply.com/eoma68


On Sat, Jul 29, 2017 at 2:51 PM, Benson Mitchell
<benson.mitchell+arm-netbook at gmail.com> wrote:
> On Sat, Jul 29, 2017 at 8:53 AM, Luke Kenneth Casson Leighton <lkcl at lkcl.net
>> wrote:
>
>> http://hands.com/~lkcl/foldable3dsandwich200/belts.py
>>
>> ok, i could use some algorithm help, here, if anyone's interested.
>> the key function is add_bearing in class Belt.
>>
> I don't really speak python, but I'm happy to put my two cents in.

 python's pretty clear and human-readable.

> You've got three of the four cases defined,

 yes.  the last case - which is when 2 or more inverted-belt bearings
are added - i skipped, on the basis that i would not really use it (if
ever).

> but to start with I only looked
> at the simple one (invert==0, oldinvert==0) which you seem to think is
> solved.

 it is... but explaining how it works is not something i can easily
do.  i tend to work by intuition and guess-work.  i was terribly
surprised when a series of random and semi-arbitrary
code-modifications actually produced the desired result.

> Unless I'm missing something, it's not really solved at all -- it
> looks like it completely ignores any difference in radius when figuring the
> contact angles.

 ah.  ok you see the loop "+= 360"?  i vaguely figured that any change
would have to result in a positive increase in angle.  any change that
went over 360 could be made modulus 360 for the *next* change.

 staggeringly this actually works.

> And I think when you fix that, the hard cases will mostly
> explain themselves (you'll basically negate the radius in that calculation,
> and maybe also add/subtract the belt thickness).

 ok the problem of actually creating the belt is passed to that
SurfaceFromCurves function.  you give it a set of points (actually two
sets) and a "thickness" parameter, and it *automatically* creates the
full 3D polygon set needed to create a complete 3D surface of
thickness "thickness".

> So, given the old bearing has radius R1 and the new bearing has radius R2,
> separated horizontally (or at any other angle) by a distance D, we can find
> the deviation from horizontal (or in the general case, the deviation from
> the angle connecting their centers):
> arcsin((R1-R2)/D)

 yep this case is not covered at all.  however given that i am only
using radii of 6 and 7 or 8 and 9, with long separation between them
and also where there is a huge discrepancy the angles are 180 degrees
and dead-straight (lined up by eye), the differences caused by not
taking into account the case R1 != R2 are either actually zero or
negligeably small.

 it's a visual aid and approximation anyway, but i would really like
it to actually be complete and accurate, as i will be doing more
complex belt layouts later.

> And if you're crossing over, with belt thickness T, that should just become
> arcsin((R1+R2+T)/D)
> (again, this is going from noninverted to inverted -- negate for inverted
> to noninverted, or maybe the opposite.)

 if i can be absolutely honest, my mind isn't one that can cope with
or follow accurate mathematical calculations.  when working with the
spline-generating function i had to leave *six years* in between
modifications and it took me 2 days of experimentation to get even a
reaasonably-approximate version of "normalised vectors" up and
running.  that was from a lot of google searches, as well :)

 so if i may, i'd like to leave it to others to discuss this, if they
want to: i'll chip in if necessary.

l.



More information about the arm-netbook mailing list