Raised This Month: $12 Target: $400
 3% 

Geometry to create circle


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Furibaito
Member
Join Date: Aug 2012
Location: Colossal Titan
Old 07-16-2013 , 11:53   Geometry to create circle
Reply With Quote #1

Well..... this is a Geometry question but it's connected to scripting =D
Big thanks to zeroibis. I'm currently using one of his stocks. To make a circle laser (Different from TE_SetupBeamRing(Point)). Note that the PI already defined 3.1415926535897932384626433832795
PHP Code:
/*
 * DRAW A VERTICAL CIRCLE
 * 
 * NOTE MUST PLACE OnMapStart_Circle() in OnMapStart of program to use
 *
 * @param Float:vecLocation[3]        Location of circle.
 * @param Float:radius                Radius of circle.
 */
stock Circle(Float:vecLocation[3], Float:radius)
{
    new 
Float:angle=0.0Float:xFloat:y;
    
    new 
Float:pos1[3];
    new 
Float:pos2[3];
        
    
//Create the start position for the first part of the beam
    
pos2[0] = vecLocation[0];
    
pos2[1] = vecLocation[1] + radius;
    
pos2[2] = vecLocation[2];
    
    while (
angle <= PI)
    {            
        
radius Cosine(angle);
        
radius Sine(angle);
        
        
pos1[0] = vecLocation[0];
        
pos1[1] = vecLocation[1] + x;
        
pos1[2] = vecLocation[2] + y;

        
TE_SetupBeamPoints(pos1pos2BeamSpriteCircleHaloSpriteCircle008.0Float:5.0Float:5.050.0, {255,255,255,255}, 3);
        
TE_SendToAll();
        
        
pos2[0] = pos1[0];
        
pos2[1] = pos1[1];
        
pos2[2] = pos1[2];
        
        
angle += 0.7;
    }

I'm currently want to make 20 entities arranged in a half circle shape by learning out of this stock. But I haven't learn much in Geometry in school. So what actually this loop do?

PHP Code:
while (angle <= PI)
    {            
        
radius Cosine(angle);
        
radius Sine(angle);
        
        
pos1[0] = vecLocation[0];
        
pos1[1] = vecLocation[1] + x;
        
pos1[2] = vecLocation[2] + y;

        
TE_SetupBeamPoints(pos1pos2BeamSpriteCircleHaloSpriteCircle008.0Float:5.0Float:5.050.0, {255,255,255,255}, 3);
        
TE_SendToAll();
        
        
pos2[0] = pos1[0];
        
pos2[1] = pos1[1];
        
pos2[2] = pos1[2];
        
        
angle += 0.7;
    } 
I is pretty sure that this loops creates a very short beams what is looped until it reach a circle. But I don't understand how. I thought Trigonometry is to calculate Triangle Angles or the ratio of two sides of a triangle. What does it do with a circle?? Or maybe you can explain what this whole loop do? ^^

Thanks for readin
__________________
フリー

Currently making : ZRiot - like mod in CS:GO - - 45%

Can do private plugins or private community maps for small money.
Furibaito is offline
Doodil
Senior Member
Join Date: Mar 2012
Old 07-16-2013 , 17:06   Re: Geometry to create circle
Reply With Quote #2

Let's try this line by line:

PHP Code:
while (angle <= PI
For a whole cirlce (a circle is 2*PI, 4*PI would be the same circle twice, 1*PI half a circle, so it repeats every 2PI [since its a circle and circles dont end]).

PHP Code:
        x radius Cosine(angle); 
        
radius Sine(angle); 
using cosine and sine on the angle value(which is between 0 and 2PI) you get the x and y value for the circle. x and y are between -1 and 1.
Take a look at this picture:

(t is your angle value here)
so cosine(t=0) is +1, with increasing t the value drops to cosine(t=1/2*PI) is 0 and cosine(t=PI) is -1. After that the value increases with increasing t: cosine(3/2*PI) is 0, cosine(2*PI)=1 (and drops from there on again). cosine(t) keeps moving left and right along the x axis.

sine is pretty equal to that, but sine(t=0) is 0, sine(t=1/2PI) is 1, sine(t=PI) is 0 again, sine(t=3/2PI) is -1, sine(t=2PI) is 0. So it moves up and down the y axis.

Combining the two allows you to get the x and y coordinates of a circle around the point (0,0) with 1 unit radius.

PHP Code:
        pos1[0] = vecLocation[0]; 
        
pos1[1] = vecLocation[1] + x
        
pos1[2] = vecLocation[2] + y
add the x and y value to the player position

PHP Code:
        TE_SetupBeamPoints(pos1pos2BeamSpriteCircleHaloSpriteCircle008.0Float:5.0Float:5.050.0, {255,255,255,255}, 3); 
        
TE_SendToAll(); 
set a beam from "pos1" to "pos2"

PHP Code:
        pos2[0] = pos1[0]; 
        
pos2[1] = pos1[1]; 
        
pos2[2] = pos1[2]; 
save the old position

PHP Code:
        angle += 0.7
increase the angle for the next loop.



EDIT:

for your 20 entities in a half circle thing you have to:
1. change the while() part to something like while(angle<=PI) instead of 2PI, to only do a half circle.
2. change the step angle+=0.7 to angle+=(PI/20); because you want 20 steps in 1 halfcircle(so 1 PI)

the pos value holds the position where you want to place the entity

Last edited by Doodil; 07-16-2013 at 17:13.
Doodil is offline
Furibaito
Member
Join Date: Aug 2012
Location: Colossal Titan
Old 07-16-2013 , 22:37   Re: Geometry to create circle
Reply With Quote #3

Wow a very detailed tutorial! Thanks
I'm able to use this correctly and working half circle ^^

Some thing that I'm still not sure though, It would be wonderful if I'm also understand what I am copying

Quote:
For a whole circle (a circle is 2*PI, 4*PI would be the same circle twice, 1*PI half a circle, so it repeats every 2PI [since its a circle and circles dont end]).
I understand the basic of this and able to make this to do half circles, 1/3 circles, etc. But I'm still confused. Why it is (2 x PI) = Whole circle, PI = Half Circle, (10 x PI) = 5 Circle?? (Able to make gaussing(spiral?) beam with (10xPI).. Looks really cool!) Is it connected to the basic circle perimeter formula somehow? (I think so?) I try to make it 360 but it seems like many looped full circles. As far as i know 360 angle is full circle

Quote:
so cosine(t=0) is +1, with increasing t the value drops to cosine(t=1/2*PI) is 0 and cosine(t=PI) is -1. After that the value increases with increasing t: cosine(3/2*PI) is 0, cosine(2*PI)=1 (and drops from there on again). cosine(t) keeps moving left and right along the x axis.
Thank you for this. I think i'll learn these stuff in physics class next year. (Readin some seniors books, the arc-like force and stuff, I understand them from your post! Good to be able to understand it from now ). But somehow, why it is in my calculator cos(1/2*PI) is 0.99~ and other calculations with PI is different from yours? Well with the fact that your calculations are correct, proven to be working to make circle lasers in SM, so what is wrong with my windows calculator or my physical calculator? Both my calculators value are same..


(ignore that glowing root button, nothing to do with that)

Sorry for these dumb questions.. I haven't learn these :c

EDIT: google calculator is same with your calculation.. whats wrong with my calculators D:
__________________
フリー

Currently making : ZRiot - like mod in CS:GO - - 45%

Can do private plugins or private community maps for small money.

Last edited by Furibaito; 07-16-2013 at 22:39.
Furibaito is offline
wanted2411
Senior Member
Join Date: Jun 2012
Old 07-17-2013 , 01:11   Re: Geometry to create circle
Reply With Quote #4

Well, what's about sphere? Do you know how do it?
wanted2411 is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 07-17-2013 , 11:39   Re: Geometry to create circle
Reply With Quote #5

Quote:
Originally Posted by Furibaito View Post
I understand the basic of this and able to make this to do half circles, 1/3 circles, etc. But I'm still confused. Why it is (2 x PI) = Whole circle, PI = Half Circle, (10 x PI) = 5 Circle?? (Able to make gaussing(spiral?) beam with (10xPI).. Looks really cool!) Is it connected to the basic circle perimeter formula somehow? (I think so?) I try to make it 360 but it seems like many looped full circles. As far as i know 360 angle is full circle
Yes, a complete circle is 360°, but there is another method to measure angles: radians. A full circle is 2PI radians. Hence half a circle is PI radians.

In your calculator image, you are using degrees. You can see the setting to change to radians on the left hand side of the calculator, just under the text field.
__________________

Last edited by 11530; 07-17-2013 at 11:43.
11530 is offline
Doodil
Senior Member
Join Date: Mar 2012
Old 07-17-2013 , 14:42   Re: Geometry to create circle
Reply With Quote #6

Quote:
Is it connected to the basic circle perimeter formula somehow? (I think so?) I try to make it 360 but it seems like many looped full circles. As far as i know 360 angle is full circle
As 11530 already said, there are radians and degrees to measure a circle... this picture explains it I think:


so a degree of 180° equals 2*PI radian. The difference is just whether you look at the angle or the perimeter.

Thats also the reason why your calculator "doesn't work". You enter the radians value where you should enter the degree value. Switching radians and degrees on your calculator switches the behavior of cosine and sine. Degree cos(180) = Radians cos(PI)
(Trust me, understanding the difference between radians and degree will help you later in school where everyone by default uses the wrong option in exams).
Doodil is offline
Furibaito
Member
Join Date: Aug 2012
Location: Colossal Titan
Old 07-17-2013 , 21:17   Re: Geometry to create circle
Reply With Quote #7

Ah I see!

So there is another angle measurement other than degrees (Where full circle is 360) which is radian (Where full circle is 2*PI radian). That gif from wikipedia explains a lot.

Well.. in my place they didn't use radians so I don't know what radians are before
But it would be certainly useful to understand as it seems to be formerly SI unit (From wikipedia)
Thanks a lot for explaining this

edit : is there any way to convert Degree to Rad without defining PI in SM?
edit 2 : nvm found these DegToRad(Float:value) and RadToDeg
__________________
フリー

Currently making : ZRiot - like mod in CS:GO - - 45%

Can do private plugins or private community maps for small money.

Last edited by Furibaito; 07-17-2013 at 21:20.
Furibaito is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:48.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode