public static void Main()
Point center = new Point(15,15);
Point a = new Point(10,5);
Point b = new Point(30,25);
double angle_r = (double) Math.PI * angle_d / 180.0;
Line l_ = new Line(a, b);
rotate(l_, angle_r, center);
Console.WriteLine("l=" + l + "\nl_=" + l_);
drawConsole c = new drawConsole();
for (int i = 0; i < 5; i++) {
center.x + radius * Math.Cos((Math.PI * 144 * i + 60 ) / 180),
center.y + radius * Math.Sin((Math.PI * 144 * i + 60 ) / 180)
center.x + radius * Math.Cos((Math.PI * 144 * (i + 1) + 60) / 180),
center.y + radius * Math.Sin((Math.PI * 144 * (i + 1) + 60) / 180)
c.drawCircle(center, radius);
c.drawRegularPolygon(new Point(40,10), 12, 3, 60);
c.drawRegularPolygon(new Point(35,20), 8, 12, 0, true);
public Point(int a, int b) {
public Point(double a, double b) {
public override string ToString() {
return ("[" + this.x + "," + this.y + "]");
static Point rotate(Point point, double radians, Point origin = null) {
if (origin == null) { origin = new Point(0,0); }
x_ = Math.Cos(radians) * (point.x - origin.x) - Math.Sin(radians) * (point.y - origin.y) + origin.x;
y_ = Math.Sin(radians) * (point.x - origin.x) + Math.Cos(radians) * (point.y - origin.y) + origin.y;
return new Point(x_, y_);
static Line rotate(Line line, double radians, Point origin = null) {
double x1_, y1_, x2_, y2_;
if (origin == null) origin = new Point(0,0);
x1_ = Math.Cos(radians) * (line.p1.x - origin.x) - Math.Sin(radians) * (line.p1.y - origin.y) + origin.x;
y1_ = Math.Sin(radians) * (line.p1.x - origin.x) + Math.Cos(radians) * (line.p1.y - origin.y) + origin.y;
x2_ = Math.Cos(radians) * (line.p2.x - origin.x) - Math.Sin(radians) * (line.p2.y - origin.y) + origin.x;
y2_ = Math.Sin(radians) * (line.p2.x - origin.x) + Math.Cos(radians) * (line.p2.y - origin.y) + origin.y;
return new Line(x1_, y1_, x2_, y2_);
static Point rotateDeg(Point p, double angle_deg, Point origin = null) {
double angle_rad = (double) Math.PI * angle_deg / 180.0;
return ((Point) rotate(p, angle_rad, origin));
public Line (double x1, double y1, double x2, double y2) { this.p1 = new Point(x1, y1); this.p2 = new Point(x2, y2); }
public Line (Point p1, Point p2) { this.p1 = new Point(p1.x, p1.y); this.p2 = new Point(p2.x, p2.y); }
public Line (Point p, double radius, double angle) {
this.p1 = new Point(p.x, p.y);
this.p2 = new Point(0,0);
p2.x = p.x + radius * Math.Cos(angle);
p2.y = p.y + radius * Math.Sin(angle);
public override string ToString() {
return ("[" + this.p1.x + "," + this.p1.y + ";" + this.p2.x + "," + this.p2.y + "]");
public class drawConsole {
public int ScreenWidth = 50;
public int ScreenHeight = 30;
private int[,] ScreenBuf;
private string Screen = "";
this.ScreenBuf = new int[ScreenHeight, ScreenWidth + 1];
public void drawScreen() {
string Screen = String.Empty;
for (int i = 0; i < ScreenBuf.GetLength(0); i++) {
if (ScreenBuf[i, 0] == 0) { Screen += "\n"; continue; }
for (int j = 1; j <= ScreenBuf[i, 0] + 1; j++) {
if (ScreenBuf[i, j] == 1) Screen += "[]"; else Screen += " ";
Console.WriteLine(Screen);
public void putPixel (int x, int y) {
if (x >= this.ScreenWidth || x < 0 || y >= this.ScreenHeight || y < 0) { return; }
if (this.ScreenBuf[y, 0] < x) {
this.ScreenBuf[y, 0] = x;
this.ScreenBuf[y, x + 1] = 1;
public void putPixel (Point p) {
putPixel((int) Math.Round(p.x), (int) Math.Round(p.y));
public void drawLine(int x,int y,int x2, int y2) {
int dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0;
if (w<0) dx1 = -1; else if (w>0) dx1 = 1;
if (h<0) dy1 = -1; else if (h>0) dy1 = 1;
if (w<0) dx2 = -1; else if (w>0) dx2 = 1;
int longest = Math.Abs(w);
int shortest = Math.Abs(h);
if (!(longest>shortest)) {
if (h<0) dy2 = -1; else if (h>0) dy2 = 1;
int numerator = longest >> 1;
for (int i=0;i<=longest;i++) {
if (!(numerator<longest)) {
public void drawLine(Line line) {
(int) Math.Round(line.p1.x),
(int) Math.Round(line.p1.y),
(int) Math.Round(line.p2.x),
(int) Math.Round(line.p2.y));
public void drawLine(Point p1, Point p2) {
public void drawCircle(Point center, double radius) {
int x = (int) Math.Round(radius);
putPixel((int) Math.Round(center.x + x), (int) Math.Round(center.y + y));
putPixel((int) Math.Round(center.x + y), (int) Math.Round(center.y + x));
putPixel((int) Math.Round(center.x - y), (int) Math.Round(center.y + x));
putPixel((int) Math.Round(center.x - x), (int) Math.Round(center.y + y));
putPixel((int) Math.Round(center.x - x), (int) Math.Round(center.y - y));
putPixel((int) Math.Round(center.x - y), (int) Math.Round(center.y - x));
putPixel((int) Math.Round(center.x + y), (int) Math.Round(center.y - x));
putPixel((int) Math.Round(center.x + x), (int) Math.Round(center.y - y));
public void drawRegularPolygon(Point center, double radius, int sides, double rotation = .0, bool dotted = false) {
double angle = 360 / sides;
for (int i = 0; i < sides; i++) {
double angleRad = (Math.PI * angle * i + rotation ) / 180;
center.x + radius * Math.Cos(angleRad),
center.y + radius * Math.Sin(angleRad)
double angleRad_ = (Math.PI * angle * (i + 1) + rotation ) / 180;
center.x + radius * Math.Cos(angleRad_),
center.y + radius * Math.Sin(angleRad_)