Skip to content

Instantly share code, notes, and snippets.

@lopesivan
Created March 20, 2025 07:30
Show Gist options
  • Save lopesivan/c36477e692c166e5fa54cd89d164475e to your computer and use it in GitHub Desktop.
Save lopesivan/c36477e692c166e5fa54cd89d164475e to your computer and use it in GitHub Desktop.
Equação da posição no Movimento Uniformemente Acelerado (MUVA)
/*
* __ __ ___
* /\ \\ \ /'___`\
* \ \ \\ \ /\_\ /\ \
* \ \ \\ \_\/_/// /__
* \ \__ ,__\ // /_\ \
* \/_/\_\_//\______/
* \/_/ \/_____/
* Algoritmos
*
*
* Author: Ivan Lopes
* Mail: [email protected]
* Site: ivanlopes.eng.br
* License: gpl
* Language: C ansi
* File: a.c
* Date: qui 20 mar 2025 01:50:26
* Description:
*/
#include <stdio.h>
#include <stdlib.h>
typedef double Scalar;
struct s {
Scalar s;
Scalar s0;
};
struct velocidade {
Scalar v0;
};
Scalar poisicao(struct s *s, struct velocidade *velocidade, Scalar a, Scalar t);
Scalar poisicao(struct s *s, struct velocidade *velocidade, Scalar a,
Scalar t) {
s->s = s->s0 + velocidade->v0 * t + a * t * t / 2;
return s->s;
}
Scalar aceleracao(struct s *s, struct velocidade *velocidade, Scalar t);
Scalar aceleracao(struct s *s, struct velocidade *velocidade, Scalar t) {
if (t == 0)
return 0; // Evita divisão por zero
Scalar deslocamento = s->s - (s->s0 + velocidade->v0 * t);
Scalar aceleracao = 2 * deslocamento / (t * t);
return aceleracao;
}
/*****************************************************************************
* *
* --------------------------------- main --------------------------------- *
* *
*****************************************************************************/
int main(int argc, char *argv[]) {
struct s s;
struct velocidade velocidade;
s.s0 = 30;
velocidade.v0 = 20;
Scalar t, a;
t = 3.2;
a = 9.8;
printf("S = %4.3f\n", poisicao(&s, &velocidade, a, t));
printf("S = %4.3f\n", s.s);
printf("a = %4.3f\n", aceleracao(&s, &velocidade, t));
// t = 0;
// for (int i = 0; i < 20; ++i)
// {
// printf("S = %4.3f\n", poisicao(&s, &velocidade, a, t));
// t = t + .5;
// }
return EXIT_SUCCESS;
}
/* -*- vim: set ts=4 sw=4 tw=78 ft=c: -*- */
sources := ./main.c
CC = gcc
LD = $(CC)
CFLAGS = -Wall -c
LDFLAGS = -o
target := main
targets := $(target)
# Compile
.c.o:
$(CC) $(CFLAGS) $<
all: $(targets)
main: $(sources:.c=.o)
$(CC) $(LDFLAGS) $@ $(notdir $^) $(LIBS)
clean:
/bin/rm -rf $(target) $(notdir $(sources:.c=.o))
# END OF FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment