#how can you rotate a point around a point or several points around a point.

55 messages · Page 1 of 1 (latest)

tight cairn
#

I’m trying to make a text based clock in cmd. The clock doesn’t show the actual time it’s just going to be a line that rotates around a point.

I started doing it with printfs but quickly realized that is slow and not smart.

I know the basic concept of rotating points around a point, set point a to a location

Then set point B to a location and have it rotate by angle like with a triangle.

I’ve seen come examples in c++ but that wasn’t helping me a whole lot are there some functions you can call that make this easy?

grizzled falconBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

tight cairn
#

Oh and both of those points will be a period for representation in the console/cmd/terminal

pure goblet
#

Okay, so you want to draw an ASCII art clock basically?

#

Could you show how you want it to look like in one specific setting, like f.e. 15:42 (3:42 PM)?

#

Or do you just want a single clock hand around a center point?

tight cairn
#

@pure goblet One clock hand rotating around one point once I know that I can probably figure out any other hands I could ever need

#

Rotate by say 5 degrees or whatever you choose

#

Sorry it wouldn’t be a line I was using periods to do it but any char is fine I’ll understand the concept just didn’t want the line to confuse anyone

tight cairn
#

correct

pure goblet
#

What exactly didn't you like about your printf version?

tight cairn
#

its VERY hard to format

pure goblet
#

Gimme 10 minutes and time to finish this joint

tight cairn
#

basically id be making 12 printfs and getting the /n/t. to look like an actual perfect line at every angle is VERY hard

pure goblet
#

Ah

#

The rotation part

#

Kk, I see

tight cairn
#

ye it distorts at different angles

pure goblet
#

Ye, you either solve it by pre-drawing every clock position but it should also be doable with math. gimme some time to research the theory

velvet trout
#

you can treat clock as linear function and calculate y for every x

pure goblet
#

errrm...
So I mean there are some examples for code golf (https://codegolf.stackexchange.com/questions/10759/build-an-analog-clock), but that's hardly what one could use as a source.
Hmmmm.
You could probably do it by having an n x n matrix M to simulate all the pixels. Then you need a circle with radius n / 2 pixels to simulate the outer clock circle.
You then need to calculate (based on the current time), where exactly on that circle the hour/minute hand should point to, let's call that position H/M.
Then f.e. for the hour hand you construct a line from the center of the circle to H. Then you reduce the line in size to whatever length you want your hour hand to be, let's say n / 3 for now. With this shorter line you then check every pixel of M for intersection and in each pixel you then set a clock hand character.
Then simply print M (don't forget to reset it after printing).

tight cairn
#

Oh I don’t need an outer circle as per the drawing all I really need to start with is a hand that rotates around a point

tight cairn
#

Even if it’s just rotating 1 point around a point I can figure out the rest

pure goblet
tight cairn
pure goblet
#

Well, then onto the drawing board and draw all clock configurations.

No but really, the math should all be high school level.

#

Maybe the intersection with a pixel is a bit tricky, not sure though

frank kelp
#

Bresenham's line algorithm + matrix mult

#

That's all you need

tight cairn
frank kelp
#

? You're rendering on the command line aren't you?

#

You shouldn't need any graphics librsries

#

Bresenham's line algorithm is a line drawing algorithm that determines the points of an n-dimensional raster that should be selected in order to form a close approximation to a straight line between two points. It is commonly used to draw line primitives in a bitmap image (e.g. on a computer screen), as it uses only integer addition, subtraction...

#

Just read these two to figure out which pixels/characters should be filled

#

Then figure out what printf calls to do

tight cairn
#

because i need an example first and I have yet to find one that just renders the command line

#

!F

#

!f

grizzled falconBOT
tight cairn
#

!f

grizzled falconBOT
#
#include <stdio.h>

void drawline(int x0, int y0, int x1, int y1) {
  int dx, dy, p, x, y;

  dx = x1 - x0;
  dy = y1 - y0;

  x = x0;
  y = y0;

  p = 2 * dy - dx;

  while (x < x1) {
    if (p >= 0) {
      putpixel(x, y, 7);
      y = y + 1;
      p = p + 2 * dy - 2 * dx;
    } else {
      putpixel(x, y, 7);
      p = p + 2 * dy;
    }
    x = x + 1;
  }
}

int main() {
  int : printf("Enter co-ordinates of first point: ");
  scanf("%d%d", &x0, &y0);

  printf("Enter co-ordinates of second point: ");
  scanf("%d%d", &x1, &y1);
  drawline(x0, y0, x1, y1);

  return 0;
}
Peebs
tight cairn
#

I deleted the graphics from this one now if i could figure out how to put a char or printf where the putpixel is I would be all set

frank kelp
#

One way you could do this is make a 2d array of chars that are all the space character to begin with

#

Then putpixel just sets the corresponding char to something like an x

#

And then at the end you print out each row

tight cairn
#

Nope putpixel is in graphics.h

#

For it sorted tho

#

Here’s what I came up with works easy peasy now just as I want expcept the hands go counter clockwise which will be a small fix

#

Answered by me lol

#

!solved