groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Groff] Problems with arcs and angles


From: Ralph Corderoy
Subject: Re: [Groff] Problems with arcs and angles
Date: Fri, 28 Apr 2017 16:38:32 +0100

Hi John,

> <https://cdn.rawgit.com/Alhadis/language-roff/a7c07744a9d44adf32a546646f7a8d57d52e6e58/preview-tty.html>
> <https://cloud.githubusercontent.com/assets/2346707/25514878/732e09ea-2c23-11e7-97ea-9674d3845dd1.png>

Gorgeous.  :-)

> Groff's output gives me these coordinates to go by:
>
>    - startX, startY - Coordinates of the arc's starting point
>    - centreX, centreY - Coordinates of the arc's centre
>    - endX, endY - Coordinates of the arc's terminal point

I'm assuming centreX and centreY are zero as it's just a simple
translation to get there.  And for the moment that startX and startY are
in the x>0, y>0 quadrant.  This gives a right-angled triangle (0, 0),
(startX, 0), (startX, startY).

> But the canvas arc method I'm working with requires all of these:
>
>    - x - The x coordinate of the arc's centre.
>    - y - The y coordinate of the arc's centre.

0, 0.

>    - radius - The arc's radius.

sqrt(startX**2, startY**2) as pic's arcs are always circular.

>    - startAngle - The angle at which the arc starts, measured clockwise
>    from the positive x axis and expressed in radians.

That's the triangle's angle at its origin corner.  That's the arc sine
of the opposite edge's length, startY.  But this assumes the radius,
i.e. triangle's hypotenuse, is 1.  When it's not, it's
asin(startY/radius).

This bit of Python might help.

    >>> from math import *
    >>> def d(r): return r / pi * 180
    ...
    >>> d(asin(0.001))
    0.05729578906238321
    >>> d(asin(0.999))
    87.43744126687686
    >>>
    >>> d(asin(1))
    90.0
    >>> d(asin(-1))
    -90.0
    >>>
    >>> d(asin(-0.001))
    -0.05729578906238321
    >>> d(asin(-0.999))
    -87.43744126687686
    >>>
    >>> d(asin(0.5))
    30.000000000000004
    >>> d(asin(sqrt(0.75)))
    60.0

You can see asin copes with [1, -1], giving [90, -90] in degrees.
You'll need to check the signs of start{X,Y}, making π/2 adjustments to
the radians you obtain to handle the other quadrants.

Hope that helps.  It's been many decades since I needed this.  :-)

-- 
Cheers, Ralph.
https://plus.google.com/+RalphCorderoy



reply via email to

[Prev in Thread] Current Thread [Next in Thread]