C
C#•3d ago
MKM

C# Basic animation, cant get a circle to align between two lines

I have the following code which aims to animate two basic pistons connected to one crank but genuinely dont understand why the pistons arent on the same crank, the second animates in the correct circle motion just not onto the crank, the code is just the draw code not the full timing stuff if you want that i can add it too. https://paste.mod.gg/capoiiuwymsk/0 i know the code is messy and some subroutines need to be introduced etc i just need to get this working before i clean it up and move into a much larger project
BlazeBin - capoiiuwymsk
A tool for sharing your source code with the world!
No description
26 Replies
JP
JP•3d ago
I'll be so real, I am just having a lot of trouble visualizing this from the math alone lol. Am happy to try to help, but can you toss this up on GitHub (or some other repo -- or just a zip of the whole project) so I can open the project and run the code, so I can see how changing different parts affects things?
MKM
MKM•3d ago
yes sure one sec lol Any uploads i am trying keep failing have you got any websites you would recommend file is pretty big @JP
JP
JP•3d ago
I generally drop things on google drive or use github for code
MKM
MKM•3d ago
its too big lol, i might have a previous version of the project missing some bits but this but should still work let me try that
JP
JP•3d ago
you can open a terminal and run
winget install Git.Git
winget install Git.Git
on windows if you don't have it already then git init inside your project's folder to create a git repository there then you can either use your IDE's git tooling to commit files, if you're using one (like VSCode) or a git add * followed by git commit -m "initial commit" to commit everything
MKM
MKM•3d ago
https://drive.google.com/drive/folders/1Hvo3el73h4d2xas-CURYmJF8zdl4F8vF?usp=sharing i was avoiding this as its linked to a college account with weird restrictions basically launch the project click load engine save click one of the txt files and jost proceed through it all this is an old hacked apart version so it would actually upload over my slow wifi so is a bit weird
JP
JP•3d ago
mfw the MS Forms libs only work on Windows 😢 give me a bit, need to start up a windows box
MKM
MKM•3d ago
nw u on cool ppl linux ?
JP
JP•3d ago
I do be lol
MKM
MKM•3d ago
you got it running all good?
JP
JP•3d ago
no, not at all, I've left the windows pc to install dotnet sdk and such, am just reading through the code on my main computer now until that's done
MKM
MKM•3d ago
okay sounds cool if u need any sorta explanations ill be on stack overflow 🤣
JP
JP•3d ago
sounds good lol Ok, I think the fundamental point of confusion is that there is some transform that is applied to your "crank shaft" that makes it not actually at the center the first piston was designed with the same transform, I think, so it just works but the second piston was rotated using a different transform, which throws everything off you can demo this for yourself by moving these transform lines
g.ResetTransform(); // The transforms below were previously here

// Draw the crank shaft
g.FillEllipse(
Brushes.Gray,
CrankShaftCentre.X - CrankRadius,
CrankShaftCentre.Y - CrankRadius,
CrankRadius * 2,
CrankRadius * 2);


g.TranslateTransform(CentreScene.X, CentreScene.Y);
g.RotateTransform(TiltAngle); // Use first piston tilt angle
g.TranslateTransform(-CentreScene.X, -CentreScene.Y);
g.ResetTransform(); // The transforms below were previously here

// Draw the crank shaft
g.FillEllipse(
Brushes.Gray,
CrankShaftCentre.X - CrankRadius,
CrankShaftCentre.Y - CrankRadius,
CrankRadius * 2,
CrankRadius * 2);


g.TranslateTransform(CentreScene.X, CentreScene.Y);
g.RotateTransform(TiltAngle); // Use first piston tilt angle
g.TranslateTransform(-CentreScene.X, -CentreScene.Y);
JP
JP•3d ago
that yields a layout like this, where the crank shaft is at the center of the two, but neither are aligned
No description
MKM
MKM•3d ago
ah so because my 'crank' isnt the centre of the scene the transforms mean that its always off centre andbeing moved too?
JP
JP•3d ago
I think those transforms make it so it is not truly centered, yes
MKM
MKM•3d ago
and since the its being moved with the first transform it matches the first but not the second i genuinely cant thank you enough i have been trying to fix this for like a couple hours
JP
JP•3d ago
Hah! happy to help lol This is one of those things where you look at the same code so much you become blind to it lol
MKM
MKM•3d ago
im going to test it without the centre being off centre and let you know what it does, but once again thanks so much its such ugly code too i have no idea how you managed
JP
JP•3d ago
I have a lot of experience writing ugly code 😉 yeah, happy to brainstorm if it ends up not straightforward to fix! lmk how it goes!
MKM
MKM•3d ago
will do might not be tonight though how long do threads stay open as i have work tommorow morning 🙄
JP
JP•3d ago
Not sure tbh, you can just ping me in one of the channels if this ends up auto-closed
MKM
MKM•3d ago
alright thanks again for your help :thumbsupsmiley:
JP
JP•3d ago
gotchu!
MKM
MKM•3d ago
hiya man thought id let you know i managed to get it to work perfectly by changing the transforsm to include the fly wheels y coordinate offset and its all working now 🎊 like this:
g.TranslateTransform(CentreScene.X, CentreScene.Y + RodLength + CompressionHight);
g.RotateTransform(315); // Use first piston tilt angle
g.TranslateTransform(-CentreScene.X, -CentreScene.Y - RodLength - CompressionHight);
g.TranslateTransform(CentreScene.X, CentreScene.Y + RodLength + CompressionHight);
g.RotateTransform(315); // Use first piston tilt angle
g.TranslateTransform(-CentreScene.X, -CentreScene.Y - RodLength - CompressionHight);
JP
JP•2d ago
Hey, awesome 🎉 thanks for lettin me know!
Want results from more Discord servers?
Add your server