How Do You Update Position, Transform Points, and Render Shapes in Programming?

  • Thread starter Thread starter seacreature
  • Start date Start date
  • Tags Tags
    Coding Function
Click For Summary

Discussion Overview

The discussion revolves around updating position, transforming points, and rendering shapes in programming, specifically focusing on functions related to 2D transformations and kinematics. Participants are seeking guidance on how to implement these functions without requiring complete code solutions.

Discussion Character

  • Exploratory
  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant requests help with three specific functions: updating position based on direction and speed, transforming points, and rendering a rectangle.
  • Another participant asks for clarification on the programming language being used and suggests initializing tank properties in the first function.
  • A participant shares their attempt at implementing the position update function but notes that the object moves correctly in the x-direction but inaccurately in the y-direction.
  • A later reply outlines a potential approach involving 2D kinematics and rotation matrices, suggesting the use of linear transformations for scaling, rotating, and translating a rectangle.

Areas of Agreement / Disagreement

Participants express uncertainty regarding the implementation details and the correctness of the proposed solutions. There is no consensus on the best approach to take.

Contextual Notes

Some participants mention specific programming concepts like 2D kinematics and rotation matrices, but there are unresolved mathematical steps and assumptions regarding the implementation of the functions.

seacreature
Messages
3
Reaction score
0
help needed please.. don't 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:
Physics news on Phys.org
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;
 
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.
 
seacreature said:
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.

Sorry; I don't know HLPL
 
Robert1986 said:
Sorry; I don't know HLPL

thanks for the offer of helping though. =)
 
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.
 

Similar threads

  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
9
Views
3K
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 23 ·
Replies
23
Views
4K
  • · Replies 12 ·
Replies
12
Views
3K