Rotations in 3 Dimensions

View as PDF

Submit solution


Points:12
Time limit:2.0s
Memory limit:256M

Problem type

Your task is simple: given some points in 3D, rotate them around an axis of rotation.

Input Specification

The first line of input will contain T, the number of test cases (1 \le T \le 1\,000).
The next T lines will each contain 7 real numbers to 6 decimal places, x\ y\ z\ rx\ ry\ rz\ \theta. You are to rotate the point (x, y, z) around the axis of rotation (rx, ry, rz) such that if you look at the origin from the axis of rotation, it will be rotated \theta radians counterclockwise. All coordinates will have absolute value of at most 1\,000 and \theta will be such that 0 \le \theta < 2\pi. It is guaranteed at least one of rx, ry, rz is nonzero.

Output Specification

Output T lines, each line should have the (x', y', z'), the result of rotation as three space-separated real numbers. Your answer will be judged as correct if it is within an absolute or relative error of 10^{-6}.

Sample Input

2
0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 3.141593
1.000000 0.000000 0.000000 1.000000 1.000000 1.000000 1.570796

Sample Output

0.000000 0.000000 0.000000
0.333334 0.910683 -0.244017

Comments


  • 0
    neal_nicdao
     commented on Jan. 15, 2016
    How do I output correctly?

    Sample input and output work perfectly. I tried printf("%f %f %f\n", x, y, z), printf("%.6f %.6f %.6f\n", x, y, z), %e, and many other combinations and all of them return WA... Im using g++ as well. What did I do wrong?


    • 1
      Xyene
       commented on Jan. 15, 2016

      Your code suffers from floating point precision issues: if you change your variables to doubles, your solution passes.


      • 0
        neal_nicdao
         commented on Jan. 15, 2016

        Thanks mate, some of math was already in doubles but after changing data to doubles from float, everything worked.


  • 0
    sinxcosx
     commented on Oct. 26, 2015
    Order of Rotationa and Axis of Rotation

    First of all, I'm wondering what's the order of rotation?

    Secondly, say if I want to rotate pie/4 (45 degree) by the z-axis, and then for the next rotation, let say by the x-axis, is it rotating along the old x-axis or the new x-axis, which is the axis produced after the previous rotation with a 45 degree offset?

    Can someone explain this program to me?

    Thank you


    • -1
      bobhob314
       commented on Dec. 2, 2015

      Now that you've solved it, can you explain it to us?

      ^ serious question. Thanks!


      • 0
        omysho
         commented on Dec. 7, 2016

        Hi, I notice that you convert the angle to radian value in your code.

        But the input specification has said that the angle is already radian