Results 1 to 5 of 5

Thread: How to Translate and Rotate axes to match a vector

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2010
    Location
    UK
    Posts
    9

    How to Translate and Rotate axes to match a vector

    Hello All,

    I am trying to draw an arrow to represent a vector. I have two points with (x,y,z) coordinates of the vector. I have been searching the forums to draw an arrow which suggest the best way is to draw using three lines.
    Now coming to my problem, I can draw the main arrow line joining the two coordinates I have, but drawing the two small lines at the tip is challenging.
    The idea I settled down with is translating and rotating the axes to match the vector as one of the axes. I can calculate the angle but without the sign of the angle, so not sure in which direction I need to rotate.
    Any suggestions as to how can I do this?! My ultimate goal is to draw an arrow along the vector as a representation. Is translation & rotation a good idea or is there a better way to achieve this?

    Thanks in advance
    RChemuturi

  2. #2
    Senior Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Los Angeles
    Posts
    374

    Re: How to Translate and Rotate axes to match a vector

    Quote Originally Posted by RChemuturi
    Is translation & rotation a good idea or is there a better way to achieve this?
    I find scaling, translating, and rotating to be an easy way to do what you're trying to do. Write a subroutine that makes a 3D arrow, one unit long, going down the X axis, with it's tail at the origin, and it's tip at (1,0,0). You can use gluCylinder twice to do that - once for the shaft and once for the tip. Then scale, rotate, and translate that arrow to go between your 2 points.
    Am I doing your homework for you?

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2010
    Location
    UK
    Posts
    9

    Re: How to Translate and Rotate axes to match a vector

    Thank you MaxH.
    I am trying to reproduce your solution, will post back once done.
    RChemuturi

  4. #4
    Junior Member Newbie
    Join Date
    Nov 2010
    Location
    UK
    Posts
    9

    Re: How to Translate and Rotate axes to match a vector

    I did work out, but had to do some complicated math to calculate the angle of rotation.
    Also there are some sites offerring ready-written code for rendering a cylinder given two points (coordinates of two points). Created the code myself, also planning to try the codes available on web to cross-check mine.
    Thank you for all the help
    RChemuturi

  5. #5
    Senior Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Los Angeles
    Posts
    374

    Re: How to Translate and Rotate axes to match a vector

    Quote Originally Posted by RChemuturi
    I did work out, but had to do some complicated math to calculate the angle of rotation.
    You have to do some trig or some vector operations. It's good that you worked it out for yourself.
    Am I doing your homework for you?

Similar Threads

  1. how do I rotate about 2 body axes
    By dwcronin in forum OpenGL: General
    Replies: 2
    Last Post: 01-30-2004, 10:17 AM
  2. how to rotate a object around different axes for many times?
    By pango in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 01-08-2003, 01:45 AM
  3. how to rotate a object around different axes for many times?
    By pango in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 01-07-2003, 09:32 AM
  4. How to rotate about FIXED axes?
    By JiauFoo in forum OpenGL: Basic Coding
    Replies: 16
    Last Post: 04-10-2001, 10:30 PM
  5. Represent Rotate and Translate by one Translate
    By Luin in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-02-2000, 01:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean