C
C
cyberkilla2020-06-21 22:28:41
OpenGL
cyberkilla, 2020-06-21 22:28:41

How to make a graph directed (C#)?

Graph drawing program:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tao.OpenGl;
using Tao.FreeGlut;
using Tao.Platform.Windows;

namespace WindowsFormsApp1

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

            AnT.InitializeContexts();

        }

        private void Form1_Load(object sender, EventArgs e)

        {

            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_RGBA | Glut.GLUT_DOUBLE);
            Gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            Glu.gluOrtho2D(-6.0, 6.0, -6.0, 6.0);
            Gl.glMatrixMode(Gl.GL_MODELVIEW);
            Gl.glLoadIdentity();

        }


        private void button1_Click(object sender, EventArgs e)
        {
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);

            Gl.glLineWidth(3.0f);
            // ребра графа
            Gl.glBegin(Gl.GL_LINES);
            Gl.glColor3f(1.0f, 0.0f, 1.0f);
            Gl.glVertex2d(-4.0, -4.0);
            Gl.glVertex2d(-2.0, 2.0);
            Gl.glVertex2d(1.0, 6.0);
            Gl.glEnd();

            Gl.glBegin(Gl.GL_LINES);
            Gl.glColor3f(1.0f, 0.0f, 1.0f);
            Gl.glVertex2d(-4.0, -4.0);
            Gl.glVertex2d(-2.0, 2.0);
            Gl.glVertex2d(1.0, 6.0);
            Gl.glEnd();

            Gl.glBegin(Gl.GL_LINES);
            Gl.glColor3f(1.0f, 0.0f, 1.0f);
            Gl.glVertex2d(-2.0, 2.0);
            Gl.glVertex2d(0.0, -4.0);
            Gl.glEnd();

            Gl.glBegin(Gl.GL_LINES);
            Gl.glColor3f(1.0f, 0.0f, 1.0f);
            Gl.glVertex2d(-3.0, -1.0);
            Gl.glVertex2d(-1.0, -1.0);
            Gl.glEnd();

            Gl.glBegin(Gl.GL_LINES);
            Gl.glColor3f(1.0f, 0.0f, 1.0f);
            Gl.glVertex2d(-4.0, -4.0);
            Gl.glVertex2d(0.0, -4.0);
            Gl.glEnd();

            Gl.glBegin(Gl.GL_LINES);
            Gl.glColor3f(1.0f, 0.0f, 1.0f);
            Gl.glVertex2d(0.0, -4.0);
            Gl.glVertex2d(0.0, 2.0);
            Gl.glEnd();

            Gl.glBegin(Gl.GL_LINES);
            Gl.glColor3f(1.0f, 0.0f, 1.0f);
            Gl.glVertex2d(-2.0, 2.0);
            Gl.glVertex2d(0.0, 2.0);
            Gl.glEnd();

            Gl.glBegin(Gl.GL_LINES);
            Gl.glColor3f(1.0f, 0.0f, 1.0f);
            Gl.glVertex2d(0.0, 2.0);
            Gl.glVertex2d(2.5, 2.0);
            Gl.glEnd();

            Gl.glBegin(Gl.GL_LINES);
            Gl.glColor3f(1.0f, 0.0f, 1.0f);
            Gl.glVertex2d(0.0, -4.0);
            Gl.glVertex2d(2.5, 2.0);
            Gl.glEnd();

            Gl.glColor3f(0.0f, 0.0f, 1.0f);

            Gl.glPointSize(10.0f);
            // вершины графа
            Gl.glBegin(Gl.GL_POINTS);
            Gl.glVertex2d(-4.0, -4.0);
            Gl.glVertex2d(-3.0, -1.0);
            Gl.glVertex2d(-2.0, 2.0);
            Gl.glVertex2d(-1.0, -1.0);
            Gl.glVertex2d(0.0, -4.0);
            Gl.glVertex2d(0.0, 2.0);
            Gl.glVertex2d(2.5, 2.0);
            Gl.glEnd();

            AnT.Invalidate();
        }
    }

}


I can't figure out how to draw the arrows (should be GL_LINES) so that their lines make the same angle with the edges.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2020-06-22
@vabka

Here in the answers there are approximately the formulas that are needed: 2D rotation around the center?
And in more detail: https://ru.wikipedia.org/wiki/Trigonometry
And more How to draw an arrow in opengl

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question