CodingTrain / CodingTrain/Suggestion-Box

VERY important Simple Pendulum Project

Aperta
#1,172 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Nessun dato sulla lingua
Stelle
570
Fork
85
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I have a project.This is very important to me.I have similar code to this project but this code is too hard and not understanding to me.I want to very easy code because this project wants to be some calculation and simple pendulum.Details:
![adsiz](https://user-images.githubusercontent.com/46270210/50552107-670fd380-0c9d-11e9-8ae4-502b9e3b9777.png)
OR
https://i.imgur.com/GUGheoR.png

I PREPARE THIS CODE:

>

void setup() {
size(1000,900);
}
float t = 0;
void draw() {
float g = 9.8;
float l = 1;
float w = sqrt(g/l);
float theta0 = 1.5;
float theta = theta0 * sin(w*t);
println(theta);
t += 0.1;
}

>
AND I FIND THIS CODE:

>
Pendulum p;
void setup() {
size(1000,950);
// Make a new Pendulum with an origin position and armlength
p = new Pendulum(new PVector(width/2,500),300);
}
void draw() {
background(255);
p.go();
}
void mousePressed() {
p.clicked(mouseX,mouseY);
}
void mouseReleased() {
p.stopDragging();
}
class Pendulum {
PVector position; // position of pendulum ball
PVector origin; // position of arm origin
float L; // Length of length
float angle; // Pendulum arm angle
float aVelocity; // Angle velocity
float aAcceleration; // Angle acceleration
float ballr; // Ball radius
float damping; // Arbitary damping amount

boolean dragging = false;

Pendulum(PVector origin_, float r_) {

origin = origin_.get();
position = new PVector();
L = r_;
angle = PI/2;
aVelocity = 0.0;
aAcceleration = 0.0;
damping = 0.995; // Arbitrary damping
ballr = 100; // Arbitrary ball radius
}
void go() {
update();
drag();
display();
}
void update() {

if (!dragging) {
float gravity = 0.05; // gravity constant
aAcceleration =sqrt((gravity / L)) * cos(angle); // Calculate acceleration(w)
aVelocity += aAcceleration; // Increment velocity
aVelocity *= damping; // Arbitrary damping
angle += aVelocity; // Increment angle
}
}
void display() {
position.set(L*cos(angle), L*sin(angle), 0); // Polar to cartesian conversion
position.add(origin); // Make sure the position is relative to the pendulum's origin

stroke(0);
strokeWeight(5);

line(origin.x, origin.y, position.x, position.y);
ellipseMode(CENTER);
ellipse(position.x, position.y, ballr, ballr);
}

void clicked(int mx, int my) {
float d = dist(mx, my, position.x, position.y);
if (d < ballr) {
dragging = true;
}
}

// This tells us we are not longer clicking on the ball
void stopDragging() {
if (dragging) {
aVelocity = 0; // No velocity once you let go
dragging = false;
}
}

void drag() {
// If we are draging the ball, we calculate the angle between the
// pendulum origin and mouse position
// we assign that angle to the pendulum
if (dragging) {
PVector diff = PVector.sub(origin, new PVector(mouseX, mouseY)); // Difference between 2 points
angle = atan2(-1*diff.x, diff.y) - radians(90); // Angle relative to vertical axis
}
}
}

>

BUT SECOND CODE VERY HARD AND COMPLICATE TO ME. Please help me to simple code :D Thank you

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Non sono indicati file del repository, test o punti di ingresso. Inizia esaminando i due esempi di codice e le immagini dei pendoli collegate per chiarire se la richiesta riguarda un calcolo più semplice, una visualizzazione o entrambe le cose. Il lavoro sarà considerato completato quando l’esempio di pendolo richiesto sarà chiaramente definito e il suo comportamento previsto sarà documentato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Ambito
computer-graphics
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
15/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.