Angles, Trigonometry, etc. questions

Started by cpaca, February 28, 2018, 05:58:48 PM

Previous topic - Next topic

cpaca

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.   
 
But if it looks straight up/down the two beams overlap, and it's overlapping now.   

 
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. 

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: 
To use [OUR] Custom Modules, go to Forums/Knuckle Cracker/PFE/Map Makers, Ship Builders, and Coders, Go to the pinned posts, find the one named "Custom Modules Thread", Open it, Scroll down until you find ShipModule, Apply that into your map, do not apply it into map if one copy already exists, Apply the Adder script (Sometimes named "Master.prpl, sometimes [shipname]Adder, etc.) and the actual used scripts [which i will state in my posts]. If one copy already exists, do not apply another copy. -The CMC :-)

GoodMorning


: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...
A narrative is a lightly-marked path to another reality.

cpaca

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)
To use [OUR] Custom Modules, go to Forums/Knuckle Cracker/PFE/Map Makers, Ship Builders, and Coders, Go to the pinned posts, find the one named "Custom Modules Thread", Open it, Scroll down until you find ShipModule, Apply that into your map, do not apply it into map if one copy already exists, Apply the Adder script (Sometimes named "Master.prpl, sometimes [shipname]Adder, etc.) and the actual used scripts [which i will state in my posts]. If one copy already exists, do not apply another copy. -The CMC :-)

GoodMorning

Sigh ... that is the nontrivial element of precisely what you requested.
A narrative is a lightly-marked path to another reality.

bluebolt

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...
Even YOU may survive an apocalypse! Fight back against the creeper today!

cpaca

#5
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 

 
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 ):
To use [OUR] Custom Modules, go to Forums/Knuckle Cracker/PFE/Map Makers, Ship Builders, and Coders, Go to the pinned posts, find the one named "Custom Modules Thread", Open it, Scroll down until you find ShipModule, Apply that into your map, do not apply it into map if one copy already exists, Apply the Adder script (Sometimes named "Master.prpl, sometimes [shipname]Adder, etc.) and the actual used scripts [which i will state in my posts]. If one copy already exists, do not apply another copy. -The CMC :-)

GoodMorning

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.
A narrative is a lightly-marked path to another reality.

cpaca

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"
To use [OUR] Custom Modules, go to Forums/Knuckle Cracker/PFE/Map Makers, Ship Builders, and Coders, Go to the pinned posts, find the one named "Custom Modules Thread", Open it, Scroll down until you find ShipModule, Apply that into your map, do not apply it into map if one copy already exists, Apply the Adder script (Sometimes named "Master.prpl, sometimes [shipname]Adder, etc.) and the actual used scripts [which i will state in my posts]. If one copy already exists, do not apply another copy. -The CMC :-)

GoodMorning

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.
A narrative is a lightly-marked path to another reality.