## Re: [canvas-developers] Re: Text placement by angle

Expand Messages
• ... The translate method however needs coords to move to. I think it s just some trig I need. And to get said trig working. Unfortunately the JS Math.sin
Message 1 of 6 , Sep 28 12:36 PM
> Hm, I'm not sure why you need an arc() -- note that arc() doesn't
> actually draw anything, it just adds an arc to the current path.
> drawText ignores the current path (or should!). What you want is
> something like:

The translate method however needs coords to move to. I think it's
just some trig I need. And to get said trig working. Unfortunately the
JS Math.sin function comes out differently tro my calculator.

To recap, I'm trying to get horizontal text (ie readable) text at a
point but only knowing the angle in relation of the hypotenuse, and
the length of said line. So the equation would be:

Opposite = Math.sin(45) * 100

Where 100 is the radius of the circle I'm drawing (for example) and 45
is 45 degrees. I've just got to get it working... :-/

--
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.phpguru.org/RGraph
• ... [...] ... Javascript s trig functions work in radians, not degrees (as do most other programming languages and libraries). To convert from degrees to
Message 2 of 6 , Sep 28 1:45 PM
--- In canvas-developers@yahoogroups.com, "Richard Heyes"
<richard.heyes@...> wrote:
>
> Unfortunately the
> JS Math.sin function comes out differently tro my calculator
[...]
> Opposite = Math.sin(45) * 100
>
> Where 100 is the radius of the circle I'm drawing (for example) and 45
> is 45 degrees. I've just got to get it working... :-/

Javascript's trig functions work in radians, not degrees (as do most
other programming languages and libraries). To convert from degrees to
radians, multiply by Math.PI/180 (e.g. Math.sin(45 * Math.PI/180) in
this case). More generally though, for this sort of thing it helps to
get into the habit of 'thinking' in radians and using them
consistently across your application rather than having to convert

- Matt
• ... Ah, that explains a lot... :-) ... Well it s a public API, and people recognise degrees. Most probably don t even know what a radian is (radioactive?), so
Message 3 of 6 , Sep 29 1:12 AM
> Javascript's trig functions work in radians, not degrees

Ah, that explains a lot... :-)

> (as do most
> other programming languages and libraries). To convert from degrees to
> radians, multiply by Math.PI/180 (e.g. Math.sin(45 * Math.PI/180) in
> this case). More generally though, for this sort of thing it helps to
> get into the habit of 'thinking' in radians and using them
> consistently across your application rather than having to convert

Well it's a public API, and people recognise degrees. Most probably
don't even know what a radian is (radioactive?), so for said API, I
think I'll have to stick with convertiong to radians.

>
> - Matt
>
>

--
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.phpguru.org/RGraph
Your message has been successfully submitted and would be delivered to recipients shortly.