Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: How to simulate a line function in C++

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2006
    Posts
    15

    How to simulate a line function in C++

    Hi all:

    I need a function which dynamically simulate a line function for example

    r(t) = r0 + t * v;

    where r0 is the 3D point on the line, v is the direction vector. The value of t can only be obtained dynamically. And when the function is fixed, I can send some points to test if they are on the line. Is there a good solution to do this in c++ please??

    Thanks
    Asura

  2. #2
    Junior Member Regular Contributor
    Join Date
    Jul 2005
    Location
    Berlin, Germany
    Posts
    188

    Re: How to simulate a line function in C++

    Code :
    Given: r0, v, p
     
    /* find coefficient for point on line nearest to p */
    t = v * (p - r0) / v^2
     
    /* check whether p and that point are the same */
    delta = p - (r0 + t * v)
     
    if (|delta| < epsilon) { /* floating point demons be lurking here */
      /* optionally check whether p lies on the line segment r0 to r0+v */
      if (lambda >= 0 &amp;&amp; lambda <= 1) {
        /* do something */
      }
    }
    355/113 -- Not the famous irrational number PI, but an incredible simulation!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •