Displaying an analog clock
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Displaying an analog clock
How do you display an analog clock on the NXT, using NXC? I know how to use the draw circle function, and I know how to draw lines, but how do I draw a line that starts at the center of the circle, and goes to one of 360 positions (or however many), without entering all the values manually? What math function do I need to perform?
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Displaying an analog clock
Actually, I think what I want, is to know the math that is used to write a 2D array of values, used to plot a circle.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: Displaying an analog clock
Is this within a RIC file?
If not, just use trigonometry!
I'm a getting bit shaky with my NXC now, so here's some pseudo-code:
If not, just use trigonometry!
I'm a getting bit shaky with my NXC now, so here's some pseudo-code:
Code: Select all
int xCenter = 50;
int yCenter = 32;
int radius = 20;
float angle = Pi/6 * hour;
drawLine(xCenter, yCenter, xCenter + radius * sin(angle), yCenter + radius * cos(angle));
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Displaying an analog clock
Well, I can't say as though I know much of any trigonometry. Thanks a lot, that seems to be almost exactly what I want.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: Displaying an analog clock
It's a pretty "simple" algorithm, actually. It uses the Pythagorean Theorem, which I expect you've heard of. It's called the Midpoint Circle Algorithm which uses a similar method to Bresenhan's Line Algorithm. It's very fast for non anti-aliased graphics (aka monochrome display).mattallen37 wrote:Actually, I think what I want, is to know the math that is used to write a 2D array of values, used to plot a circle.
I've written a few versions for NXC (including stealing Ellipse code [when I couldn't find what I was looking for] off the EF source ), but I'm sure you don't really want these.
What you want is this:
Code: Select all
inline LocationType GetCircleVectorOfTerriblyLongNamesForSimpleFunctionsDeg(float deg, float radius)
{
LocationType ltTemp;
ltTemp.X = cosd(deg) * radius;
ltTemp.Y = sind(deg) * radius;
return(ltTemp);
}
Last edited by muntoo on 19 Dec 2010, 02:16, edited 1 time in total.
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
-
- Posts: 73
- Joined: 29 Sep 2010, 12:05
Re: Displaying an analog clock
Muntoo, you meant to write "Temp.Y = sind(deg) * radius;" not "Temp.Y = sin(deg) * radius;", right?
Regards, Morton
Re: Displaying an analog clock
Shhh! Only the Secret Order Of The Volcano is supposed to know that, remember?m-goldberg wrote:Muntoo, you meant to write "Temp.Y = sind(deg) * radius;" not "Temp.Y = sin(deg) * radius;", right?
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
Re: Displaying an analog clock
We are always watching...muntoo wrote:Shhh! Only the Secret Order Of The Volcano is supposed to know that, remember?
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
Who is online
Users browsing this forum: No registered users and 1 guest