Thread: Adding Arrays and Matrices

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    17

    Adding Arrays and Matrices

    Hello everyone,

    I am very new to c++ and only know the basics.

    I am having problems with the code below. I want the user to be able to specify 3 coordinates which can then be added to 3 other coordinates (already specified earlier on in the program) to allow a line to be translated.

    (I hope that makes sense)

    Just wondering if anyone could give me some advice or tips?

    Thanking you all in advance,

    dlf.

    Code:
    void translate_line(double line[][3])
    {
       double translation [2][3];
       
       printf("\nHow much would you like to translate the line by?\n(Between -1000 and 1000):");
       scanf("%lf, %lf, %lf", &translation[0][0], &translation[0][1], &translation[0][2]);
       
       double translate_line=[line]+[translation]
    
       //double translateda=((line[0][0])+(translation[][0]),(line[0][1])+(translation[][1]),(line[0][2])+(translation[][2]));
       //double translatedb=((line[1][0])+(translation[][0]),(line[1][1])+(translation[][1]),(line[1][2])+(translation[][2]));
      
       printf("\nThe new start coordinates are: (%lf,%lf,%lf)", translate_line);
       //printf("\nThe new end coordinates are: (%lf,%lf,%lf)", translatedb);
    
    }

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Presumably, the coordinates entered earlier are contained in the array:

    double line[][3]

    So, you have to get the coordinates from that array. If the coordinates you are interested in translating are in row 0 of that array, then you would access them like this:

    line[0][0], line[0][1], line[0][2]

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    17
    If I had 2 arrays for 2 points and each point had a x, y and z coordinate.

    How would I add a translation for point 1 in one line and point 2 in another line?

    So 2 lines of code to add 3 original coordinates to 3 translated coordinates.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    If I had 2 arrays for 2 points and each point had a x, y and z coordinate.
    Your arrays contain values of type double. I showed you how to retrieve a specific value at a specific location in an array. So, your question boils down to: how do I add two doubles together? You get one double from one array, and you get another double from the other array, and you add them together. Where you put the sum is up to you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help with Matrices and Arrays
    By dcwang3 in forum C Programming
    Replies: 7
    Last Post: 02-17-2008, 04:53 PM
  2. Multidimensional arrays as Matrices
    By alvifarooq in forum C++ Programming
    Replies: 9
    Last Post: 05-30-2005, 12:15 AM
  3. 2-D Arrays (Matrices)
    By Mak in forum C Programming
    Replies: 2
    Last Post: 11-27-2003, 03:01 PM
  4. What are the differences between arrays and matrices?
    By incognito in forum C++ Programming
    Replies: 3
    Last Post: 03-11-2003, 01:09 AM
  5. Adding multidimensional arrays
    By newbie2C++ in forum C++ Programming
    Replies: 3
    Last Post: 11-13-2001, 04:05 PM