2

I had seen OpenGL statement to draw a line using two points. However, my requirement is to draw a line using the following detail

  • a point on a line
  • Direction Vector

Im developing function in c++ using openGL library.

Any help is most appreciated.

Roham Rafii
  • 2,929
  • 7
  • 35
  • 49
Ria
  • 225
  • 1
  • 7
  • 18
  • Thanks for your reply. And can you help me with the function if length is known. – Ria Sep 29 '12 at 06:37

2 Answers2

4

The answer depends on the semantics of what you've termed a direction vector.

In the computer graphics context I would normally take that term to mean a unit vector facing in the specified direction. Whereas in a mathematics context you might simply mean the relative vector that results from subtracting the two points' coordinates.

[Using P1 and P2 to represent the required two points, and V for the vector].

In the former case, you also need a specify a length for the vector, so you'll need:

P2 = P1 + n * V

whereas in the latter case, it's just trivially

P2 = P1 + V
Alnitak
  • 334,560
  • 70
  • 407
  • 495
0

Just make that two-point line a very long one, say 10000 to each direction from your point-on-a-line:

void drawLinePointDirection(Point P, Vector D) {
    Point A = P + 10000*D;
    Point B = P - 10000*D
    drawLineTwoPoints(A, B);
}

assuming D is unit length.

yuri kilochek
  • 12,709
  • 2
  • 32
  • 59