Knuckle Cracker

Particle Fleet => Map Makers, Ship Builders, and Coders => Topic started by: cpaca on February 28, 2018, 05:58:48 PM

Title: Angles, Trigonometry, etc. questions
Post by: cpaca on February 28, 2018, 05:58:48 PM
First, it may be easier to understand *why* I ask this question. 
 
I want to create a Particle Maker (Custom module, might be similar to one of FOXX's, haven't checked) that fires straight forward. 
 
However, I want to make it have two beams. 
 
I could make it fire a beam from y+1 and y-1, which would work fine if it looks straight left/right all the time.   
(https://www.dropbox.com/s/izuo594cxvxi5qt/Diagramming-works-one-way.png?raw=1) 
But if it looks straight up/down the two beams overlap, and it's overlapping now.   
(https://www.dropbox.com/s/kh05iha0xfyd0av/Diagramming-fails-other-way.png?raw=1)
 
I could do it for x +/- 1, but then the problem reverses (overlap L/R, double beam U/D) 
 
I could do it conditionally (which way is the ship looking), but then it looks weird to my eyes, and I plan to use it in roleplay, so it looks really weird in the ship crew's eyes. 
(https://www.dropbox.com/s/a285vayb7gb1jtq/Diagramming-conditinal.png?raw=1)
So I want to have a way to fire a beam from slightly up/down and slightly left/right, so that (In the best way I can describe): 
A) The two beams are parallel (I already have a particle-maker script that fires in a straight line given an X and Y coordinate, so checked off) 
B) A line segment made connecting the "start point" of the two beams should overlap over the center of the Custom Module (angles/trigo?) 
C) The distance between the center and the start point of both beams should be *variable* (easily confirmed, pythagorean a^2 + b^2 = c^2) 
C has "Variable" as in the future I may want a triple-beam, with distances 1.5 away instead of 1 away 
 
A diagram of this: 
(https://www.dropbox.com/s/c4cwxumy7u2t14t/Diagram-goal.png?raw=1)
Title: Re: Angles, Trigonometry, etc. questions
Post by: GoodMorning on February 28, 2018, 07:39:21 PM

:RotateCoords #[X Y Angle - X' Y']
    ->Ang ->PreRotateX ->PreRotateY

    <-PreRotateX <-Ang cos mul <-PreRotateY <-Ang sin mul sub ->PostRotateX
    <-PreRotateX <-Ang sin mul <-PreRotateY <-Ang cos mul add ->PostRotateY


Fire the beams at the angle you choose. This will give your start point.

Also, it's so much easier to explain this kind of thing with a diagram...
Title: Re: Angles, Trigonometry, etc. questions
Post by: cpaca on February 28, 2018, 08:15:07 PM
I don't think you understood what I mean, GM 
 
I drew a diagram to help any future attempters 
 
Thanks for trying, anyway 
 
I also added a PRPL script (it's the Custom Module script I use to fire it, I just plan to do it with different X and Y)
Title: Re: Angles, Trigonometry, etc. questions
Post by: GoodMorning on February 28, 2018, 08:18:49 PM
Sigh ... that is the nontrivial element of precisely what you requested.
Title: Re: Angles, Trigonometry, etc. questions
Post by: bluebolt on February 28, 2018, 09:10:35 PM
I can't explain how to do it at the current moment, but I suggest you look at my proton torpedo custom module. It places 2 shots parallel to each other and should provide a nice resource to look at for making particles do the same. However, I don't remember if I commented it effectively...
Title: Re: Angles, Trigonometry, etc. questions
Post by: cpaca on February 28, 2018, 11:26:56 PM
Quote from: GoodMorning on February 28, 2018, 08:18:49 PM
Sigh ... that is the nontrivial element of precisely what you requested.

Sorry, I don't understand trigo very well. 
 
... 
 
In that case, what am I doing wrong?   
 
Edit: Forgot to add image and PRPL file, LOL 
(https://www.dropbox.com/s/fl2471mppsqlita/Screenshot%202018-02-28%2020.25.09.png?raw=1)
 
Quote from: bluebolt on February 28, 2018, 09:10:35 PM
I can't explain how to do it at the current moment, but I suggest you look at my proton torpedo custom module. It places 2 shots parallel to each other and should provide a nice resource to look at for making particles do the same. However, I don't remember if I commented it effectively...

I found one or two comments in the area that actually fires the missiles, so yeah, not very effective sadly ):
Title: Re: Angles, Trigonometry, etc. questions
Post by: GoodMorning on March 01, 2018, 12:02:15 AM
This ought to do what you needed. I apologise that my stack notation was wrong, I'd forgotten two "#"s. You seemed to understand the code well enough, though.

A quick rundown on what you did and what I did:
As a useful image, imagine a plate at (0,0) on a coordinate grid. Now imagine that the function I gave marks a spot on the plate, spins the plate by however much you said, and returns where the point ends up.

In your code, the "plate" was at the lower-left corner of the map. I've adjusted it to use a plate that's centred on your module.

I wasn't clear enough above, and for that I apologise.

Code (The (Edited) End.) Select

:emit
CurrentPixelCoords @MakeParticle
CurrentPixelCoords 0 12 <-ShipAngle @RotateCoords @AddCoords @MakeParticle
CurrentPixelCoords 0 -12 <-ShipAngle @RotateCoords @AddCoords @MakeParticle

:MakeParticle #[PX PY - ]
<-ShipAngle 0.75 <-health 1 sub <-IsEnemy CreateParticle <-life SetParticleMaxAge

:AddCoords #[X1 Y1 X2 Y2 - X+ Y+]
->Temp_AddCoords #X1 Y1 X2
swap <-Temp_AddCoords #X1 X2 Y1 Y2
add ->Temp_AddCoords #X1 X2
add <-Temp_AddCoords #X+ Y+

:RotateCoords #[X Y Angle - X' Y']
    ->Ang ->PreRotateX ->PreRotateY

    <-PreRotateX <-Ang cos mul <-PreRotateY <-Ang sin mul sub #PostRotateX
    <-PreRotateX <-Ang sin mul <-PreRotateY <-Ang cos mul add #PostRotateY


I've shuffled the code to some utility functions in order to make this clearer.
Title: Re: Angles, Trigonometry, etc. questions
Post by: cpaca on March 01, 2018, 01:11:37 AM
Quote from: GoodMorning on March 01, 2018, 12:02:15 AM
This ought to do what you needed. I apologise that my stack notation was wrong, I'd forgotten two "#"s. You seemed to understand the code well enough, though.

A quick rundown on what you did and what I did:
As a useful image, imagine a plate at (0,0) on a coordinate grid. Now imagine that the function I gave marks a spot on the plate, spins the plate by however much you said, and returns where the point ends up.

In your code, the "plate" was at the lower-left corner of the map. I've adjusted it to use a plate that's centred on your module.

I wasn't clear enough above, and for that I apologise.

Code (The (Edited) End.) Select

:emit
CurrentPixelCoords @MakeParticle
CurrentPixelCoords 0 12 <-ShipAngle @RotateCoords @AddCoords @MakeParticle
CurrentPixelCoords 0 -12 <-ShipAngle @RotateCoords @AddCoords @MakeParticle

:MakeParticle #[PX PY - ]
<-ShipAngle 0.75 <-health 1 sub <-IsEnemy CreateParticle <-life SetParticleMaxAge

:AddCoords #[X1 Y1 X2 Y2 - X+ Y+]
->Temp_AddCoords #X1 Y1 X2
swap <-Temp_AddCoords #X1 X2 Y1 Y2
add ->Temp_AddCoords #X1 X2
add <-Temp_AddCoords #X+ Y+

:RotateCoords #[X Y Angle - X' Y']
    ->Ang ->PreRotateX ->PreRotateY

    <-PreRotateX <-Ang cos mul <-PreRotateY <-Ang sin mul sub #PostRotateX
    <-PreRotateX <-Ang sin mul <-PreRotateY <-Ang cos mul add #PostRotateY


I've shuffled the code to some utility functions in order to make this clearer.

Thanks, this worked perfectly! 
 
Yeah, I was wondering why it said "X Y angle" when reversing the stack notation stated "Y X Angle" 
 
Ah, I guess that's one way to do it. I had that thought in my head, but I don't know sin/cos/tan very well (I know you didn't use tan, but it's trigo, so i'd get that in too somehow) 
 
Sidenote: I had to flip the 0 and the 12 (and -12) to get it to work properly, I think this is because the 3 beams being made were "overlapping" and when two particles are in the same spot, they spread. The rest from there is just "spread out more and more"
Title: Re: Angles, Trigonometry, etc. questions
Post by: GoodMorning on March 01, 2018, 03:22:08 AM
Sigh, I erred in absorbing the arguments. It should read:

   ->Ang ->PreRotateY ->PreRotateX


The perils of writing code when tired.

Anyway, good to know I could help.