1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

B Help Me Understand Rotation from an Arbitrary basis

  1. Jan 2, 2017 #1
    Apologies on the vague title, I'm having some trouble describing what I'm trying to do and need some context.

    I have a 3D World Coordinate system that is static, using an extrinsic left-handed ZYX system.

    I have an object with a radius of 1 unit (generic), this is arbitrarily placed within the environment, so at any position, within the world's boundaries, but always an initial rotation of (A,0,0). A = an arbitrary (unknown) rotation on the Z axis.

    The goal here is to apply rotation to the object's Y and X coordinates. I am only able to apply rotation based on the World Coordinate system. So if I give it a Rotation of 30units on the Y axis, then 30 units on the X axis, it rotates them based on the World Coordinate system.

    Here's where I become confused, most of what I'm reading assumes the Origin point is somewhere else, or at 0,0,0. In my case, it is quite random. but is always the position of where the object lands / placed. The rotational information comes from the object's basis. which then applied to the object from world basis causes issues.

    Clawing in the dark, i think it may be as simple as multiplying the world vector Matrix by the object's vector Matrix. So I'm really asking, what do I need to know to get to an answer here? The specifics aren't a concern, a general concept would be more helpful.

    Hopefully not in wrong forum, idk where to ask this.
  2. jcsd
  3. Jan 2, 2017 #2

    Stephen Tashi

    User Avatar
    Science Advisor

    What does that mean? Do you mean you want to rotate the object about an axis that is perpendicular to the XY-plane?
  4. Jan 2, 2017 #3
    I'm uploading a 4 min youtube video right now explaining exactly what i'm doing using a 3d environment, so it should be very obvious what the issue is, I just cannot seem to communicate this accurately. I don't know the terms or have the technical ability to do so. It should be uploaded in about 20 minutes.
  5. Jan 3, 2017 #4

  6. Jan 3, 2017 #5

    Stephen Tashi

    User Avatar
    Science Advisor

    The general description of the mathematical algorithm you can use has 3 steps:

    1. Translate the object back to the world origin
    2. Perform the desired rotation about the z-axis while the object is at the world origin
    3. Translate the object back to its original position

    How to implement this in a particular software program interface obviously depends on the interface.

    How the mathematical steps are written as equations depends on what data you use to describe the state of an object. The description of state probably includes the position of the "center" of the object. What else does it include? - the location of the vertices of a triangle?
  7. Jan 3, 2017 #6
    Wings 3d has a feature called rotate to target, you select a vertex, surface or line and chose the direction of rotation, based about that point and only that point. I have a hard time understanding the problem in detail though, but

    1. you want the object to only rotate about the Z axis?
    2. You want this rotation to be carried out on a certain point on the object?
    3. You want to implement this in the in game world, which means you would need to know how to program this?

    Usually when you do the standard rotate in wings 3d the software does it at the geometric centre of your object. If you want it to rotate at another point you have to chose.

    Last edited: Jan 3, 2017
  8. Jan 3, 2017 #7
    maybe I didn't make it clear in the video, but what is happening is that the Player drops an object at his exact location, the rotation of the Player only changes on the Z axis. therefore, the object that is dropped has the same Z rotation as the player. and because i'm getting the Z positions from my triangles at that rotation around the Z axis, it influences the X and Y rotations from coming out right.

    I'm ONLY wanting X and Y rotations based off of the triangles that I solve. The Player may not rotate along the X and Y, but the Object needs to rotate on the X and Y to match the Terrain.

    to answer you question, the object that is dropped has an origin, that origin is what rotates the 3d model. There is no need to determine the vertex manipulation of the object, that is already taken care of by the game engine. the video shows exactly how its handled. in game.

    This is for a game engine, which i'm controlling through a script. I just used 3ds max to demonstrate what I'm doing, and what I need.
  9. Jan 3, 2017 #8
    I want the X and Y rotations, the Z rotation is known. Once i drop my three (stars in the video, ie Point A, Point B, Point C) objects onto the ground, those give me Z positions of the terrain, from those I create and solve triangles to determine the slope of the rotation on the X and Y axises BASED upon the arbitrary Z rotation of the object.

    the rotation happens at the origin of the object.

    I can code just about anything, i already have 2d and 3d rotation matrices setup to be used, b/c I assumed that's what I needed to use, however I don't really understand how to use them.
  10. Jan 3, 2017 #9
    can you give an analogy/example to some other game or real life example where this has been implemented ? : - )
  11. Jan 3, 2017 #10
    Let me just explain exactly what I'm doing. In the game, you can place any object you want at any position along any XYZ axis. so anywhere in 3 dimensions. The problem is that terrain exists that has all kinds of different angles. the engine does not drop an object and give you the correct rotation to match that terrain. So the solution is to fire projectiles at the ground using very small collision objects, these stick to the ground/terrain and give my Z positional data. so i have three shooters, each firing a projectile, in some cases, projectile A = 5, projectile B = -1, projectile C = 2. these represent the different heights of the terrain around the player and future object.

    Next is just using pythagorean theorem and the Law of cosines to create right triangles and solve them for the correct angle/slope in which to apply to my object.

    The problem is that the shooters always follow the player's line of sight, which becomes the Z angle. if the Player is looking at 45 degrees, all three shooters AND the object spawn at 45 degrees on the Z axis, all in tandem with the player's line/angle of sight.

    when i solve the triangles, I'm solving them at 45 degrees, or w/e Z rotation my player is currently looking. now then I attempt to apply those X and Y rotations to my object, but the rotations are applied to the object not based on the 45 degrees but from the world coordinate system. so a Y rotation (pitch) is applied as it would be from the world basis.
    Last edited: Jan 3, 2017
  12. Jan 3, 2017 #11
    Im wondering if the solution is just to put the object's Z rotation to 0 and then apply the Y and X rotations and then rotate it back to the former z rotation?

    my brain is a little fried from thinking about this for so long. i hope i didn't overthink this and make it extremely complicated....

    edit: now i remember why i couldn't do this, but maybe there is a simple solution, i can't use rotation offsets, i can only directly change the rotation, since the game uses an extrinsic ZYX rotation scheme, i have to rotate the Z first, then Y, then X, so i can't turn the thing to Z = 0, apply the rotations on the Y and X. I have to do it all at once, in the correct order.

    edit2: yes, if Z rotation of the object is 45 degrees, i can subtract 45, making it zero, then apply the Y and X rotations, but then I need to do another set of ZYX rotations to put it back to 45 degrees on the Z, which would change the Y and X rotations. There has to be a way to use the 3d rotation matrix or some other math formula to achieve this.
  13. Jan 3, 2017 #12

    Stephen Tashi

    User Avatar
    Science Advisor

    You need to clarify what you mean by "an X rotation". A rotation has an axis. It has an angle of rotation. A point has an x coordinate and if that point is rotated about some axis by some angle, it moves to a point with a different x coordinate. So what is "an x rotation"? Is it a rotation about the x-axis? Is the change in the x-coordinate of a point that is being rotated about some axis?
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted