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!

Homework Help: Function / coding

  1. Jul 26, 2012 #1
    help needed please.. dont need the code. but i need formula or any source that can help me. i want to try code it myself. =)

    can anyone help me with this function:

    // Function to be used to update the position. Given the current position,
    // the direction in which the tank is looking, and the speed it is moving,
    // modify position to the new position
    function UpdatePosition_Axis(ref position, direction, speed)
    *what is this asking for?*

    // Function used to transform a point by an angle and scale, and translated by a position.
    // Follows Linear Transformations: x' = p + A * x
    function TransformPoint(model, position, direction, scale)
    *and this*

    // Function used to render a generic rectangle. It uses the position, angle, and scale to transform
    // each point of the normalized rectangle model, and display the rectangle on the screen
    function RenderRectangle(position, direction, scale, c)
    *sorry, plus this*

    Given: for part b
    // Normalized Model of a rectangle.
    point2d model_top_left = [-0.5, 0.5];
    point2d model_top_right = [ 0.5, 0.5];
    point2d model_bottom_right = [ 0.5, -0.5];
    point2d model_bottom_left = [-0.5, -0.5];

    help is much appreciated. thanks
    Last edited: Jul 26, 2012
  2. jcsd
  3. Jul 26, 2012 #2
    What have you tried? What language is this?

    In the first function, you are going to have something like:

    tank.ref_pos = ref_pos;
    tank.speed =speed;
    tank.direction = direction;
  4. Jul 26, 2012 #3
    yeah.. i had tried it.. is in HLPL

    my function

    pos.x = pos.x * cos(direction) + speed;
    pos.y = pos.y * sin(direction) + speed;

    but the problem is, the object able to move in x direction but when moving in y direction, the object so off elsewhere.
  5. Jul 26, 2012 #4
    Sorry; I don't know HLPL
  6. Jul 26, 2012 #5
    thanks for the offer of helping though. =)
  7. Jul 27, 2012 #6


    User Avatar
    Gold Member

    I just skimmed through the instructions, but to me it seems like you need to do the following:

    1. 2d kinematics, namely [itex]\mathbf{r}(t) = \mathbf{r}_0 + \dot{\mathbf{r}}t[/itex]
    2. Rotation matrix to transfer angle and then add pose vector. (Look at the Wikipedia article on rotation matrices)
    3. Use the given nonrotated rectangle of sides 1 unit and then use linear transformations to scale, rotate, and translate it.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook