[VEX for Algorithmic Design] E13 _ Trigonometry Basics

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] [Music] hello this is richard horikowa and this is the 13th episode for vex for algorithmic design and the topic today is trigonometry now let me first outline what i'm going to talk today i'm first going to describe what trigonometry is briefly then uh first explained about the differences of angles between the radians and degrees then i'm going to explain the basic um trigonometry functions which is sine cosine and tangent and together with some exercises using them to draw some computational geometry after that i'm going to show you another type of trigonometry functions which is a inverse type of a sine cosine and tangent which is called as cosecant secant and cotangent then in the last i'm going to also show you the inverse trigonometry which you can use to estimate the angle from the cosine sine and tangent values with some excess size as well and let me first explain what trigonometry is a trigonometry is a field in mathematics which explains the relationship between the edge lengths and the angle of the triangle meaning if you know the edges the edge length of the triangle you'll be able to estimate the angle of one of the edge on the triangles if you know the angle and some other edges edge lengths then you'll be able to have another the left over edge length from these informations so by using it you'll be able to estimate the shape of the triangle from a limited number of information and this trigonometry is one of the essential mathematical field you cannot avoid going through which is useful for many purposes including mathematics and physics as well and of course the 4d algorithmic design for compute to create a computational geometry so in this video um there are tons of videos out there x which explains the theory of trigonometry so i'm going to pass that detailed theory of the trigonometry but instead i'm going to show you how you can use this trigonometry by understanding the basics of course but to actually how you can use this as a tool for computational geometry for algorithmic design so that you can use it for your own design purpose for for modeling purpose with a coding so the key part in this video is to do the exercise what i'm going to show you so please try to follow it now the first thing i would like to talk about is about the angles how you express angle and there are two ways to express angle one is in radians and one is in degrees and i believe most of the people are using degrees in order to express the angle when there is like a circle and if you want to know this arc angle right here you might say this angle is equal to 90 degrees so this expression is a degrees the way to express angle in this way is degrees and if you the whole angle for this circle is equal to 360 degrees so you can mostly express the angle between zero to 360 degrees so that's the degrees now when it comes to radians it's a bit different you still can express the angle but when the degree is in 90 degrees in radians this is pi divided by 2 meaning this is 90 degrees so if so the pi itself is 180 degrees and i think you have heard about pi as a number from a high school or maybe mid high school and which is equal to 3.1415 or something like that and this value comes from a calculation between this edge this the length of the circle divided by the diameter of the circle so let's say the the length of the circle is a and the diameter is d then the a divided by d is always equal to 3.1415 so on and which is equal to pi and this pi represents the angle as 180 degrees which is half arc now the point here is that in most of the computational uh programming languages you use radians in order to express the angle i mean there are some languages using degrees instead but in most of the cases it uses radians to calculate to express angles and used it together with some trigonometry functions so even if you want to express the angle in degrees you somehow have to convert it into radians in order to actually use it for the prepared functions in that computational language and it is uh the same for the vex language the vex uses radians for the angle so that you have to remember about it although a funny thing about houdini is that in vex you use radians but in h-script expressions you use degrees so in the channel you have to use degrees in order to express angles but in vex you have to use radians so that's a bit of confusing but remember that there's two types of angle now fortunately there is a function in houdini in order to convert an angle from degrees to radians or radians to degrees so let's try that out first first i'm going to explain by converting degrees into radians so i've just created the geometry node let's go inside and let's create a no attribute wrangle with the detail run over so add reviewed wrangle with the detail then let's create first create some parameter channel to create some degrees so let's say float degrees is equal to chf degrees and let's promote this channel and let's set the range of this degrees from 0 to 360. okay so going into the edit parameter interface i have clicked this one and set the range from 0 to 360 degrees now you have a slider which goes from 0 to 360 degrees now what i want to do next is to convert this degrees into a radiance value which is in which if the degrees in between 0 to 180 degrees it should be in between zero to pi which is is from zero to one point uh three point one four y and one by something like that and if it's 360 degrees then that's a a 2 multiplied by pi so which is going to be 6.28 something like that so let's see if that's uh true by using a function and really need to convert degrees into radians and to do that first i'm going to create a a attribute detail attribute called radians and then use the function called radians and this function converts a volume inside a parameter to a radians from degrees to radians so inside here i'm going to enter this degrees value okay and as a result you'll be able to see by going into the geometry spreadsheet i can go here to the detail and there you see this value which is expressed which is expressing the angle and radians so right now it is 360 degrees so that is 2 pi which is equal to 6.2819 and so on if it's 180 you see 1.3.14159 and so on so this is the really handy functions you use a lot in order to convert the degrees into a radiance since most of us use angle and degrees um i think you use i'm you you're going to use this functions a lot now there's also the other way around functions in order to convert radians into degrees so let's look at that as well so let's go back and let me rename this first to degrees to radians and next i'm going to create another attribute wrangle for this one i'm going to name this radians to degrees for this one i'm going to create another channel let's name this radiance and in order to convert this radiance i'm going to promote this and i'm in order to convert this radiance into degrees you can say by i'm first going to create a detailed attribute called degrees and there is a function in routine called degrees in order to convert a radian value into a degree value so let's see how it goes and currently the the range of this radiance is from zero to one in order for you to make this range in between zero to pi uh for example um what i would always do is to use the value in between zero to one and then multiply this by a constant value pi so by using dollar sign and capital p i you'll be able to access to this constant value for the pi which is 3.1415 and so on and which is pretty handy so when you want to create a slider that in order to control the angle and radians i always do like this so create an angle like from zero to one and multiply with the pi so that you can have an angle between zero to uh 100 degrees in degrees in this case from zero to pi in radians okay so and if you want to have the range from zero to two pi which is equal to equivalent to zero to 360 degrees then you can just multiply this by 2 as well okay now let's see how it goes now how this degrees in being expressed okay now uh i forgot to make this detail okay if i look at it if it's if the value is zero then that's zero pi so the degrees is also zero if it's one pi i mean if it's one multiply by two pi then that's 360 degrees and if it's 0.5 which will be one pi and that is equivalent to 180 degrees so that's the method how you can converge from radians to degrees now this function is pretty useful both functions from degrees to radians or radians to degrees is pretty useful so um remember this remember how you can do use this so now that we know about the the types of degrees let's also try to see how we can actually estimate this pi itself with the calculations and as i explained in the sketch you can calculate this pi the constant value for the pi which is equivalent to 180 degrees by dividing the length of the circle by a diameter of the circle so let's try to see that in houdini by actually creating a circle and try to get that parameter i mean the length of the circle and divided by the diameter first i'm going to create a circle let's set it to polygon and make the division as large as possible to make it look like a real circle if it's too low which looks like a polygon so let's make it high enough and let's also make this as an open arc now what i want to do first is to calculate estimate the length of this circle the parameter of the circle and to do that i'm going to just use this measure node connect it to the circle and set the measure to a perimeter so that in the primitive attribute you'll be able to get the length of the circle which is currently 6.282145 and some of you might notice that this seems like already related to a pi value which if you look carefully this is the two pi values so two multiplied by pi is already a perimeter and which is which can be calculated since the radius is currently 1 so the diameter is equal to 2 right and if you divide this perimeter which is currently a 6.28215 divided by 2 then the answer is 3.1415 and so on and that is equivalent to a pi value so you already have some hint here that what pi really is okay and let's try to create some functions so that even if you have any kind of radius for the circle you get you always get this pi value so uh as a practice right okay so let's create a primitive wrangle so that you can access to a parameter of attribute easily and i'm going to name this estimate pi okay and going back here now i'm going to create a primitive attribute called pi and calculate the division between the perimeter which you have created from the measure node divided by diameter of this circle now the diameter haven't been parameterized yet so like let's create a parameter to control the diameter of the circle okay now i promote this diameter which is currently in between zero to one let's set the range to zero to say five okay and copy this parameter and paste it right here for the uniform scale for the circle the uniform scale is used as a radius so in order to convert diameter into a radius you have to multiply by 0.5 now let's see how it goes with the attribute um i would like to show the view port as well as the geometry spreadsheet for this one so let's split the viewport like from top to bottom here and to the bottom view i'm going to set it a geometry spreadsheet going into the new paint tab inspectors jump to spreadsheet and to the primitive attribute now you see that there is a value called pi which is a set as 3.14108 now it's a bit different from the the original constant value which is a pi goes to 3.1415 and so on which is because of the resolution of this circle so if you increase this division more exact value you'll get so if you have low lower quality of circle like making this as like a polygon you have a bit less accurate pi value here so that's how it works how that's how you can calculate the pi if you have if you want to calculate the pi itself you can do like this but most of the cases you don't need to do this you can just say you can just access to this dollar pi in order to access to the pi value which is more accurate i mean that pi value is always constant so this is a already a preserved value so in most of the cases you can just use this instead of calculating yourself but i just wanted to show you how you can calculate it by yourself what's the relationship between the pi and the circle now that we understand the difference between the radians and degrees as an angle let's talk about the trigonometry functions which is sine cosine and tangent how we can use this to express the relationship of the triangle information now first i'm going to draw an axis x y and draw a circle using uh center of this axis as the center of the circle now let's create a line from the center to some point on a circle and from that intersected point i'm going to project it on to x direction and x axis and use this triangle to explain the relationship using sine cosine and tangent functions now from this triangle you can extract four different informations one is the angle of this triangle at from the center axis center of the axis and one is the length of this edge from the center to the intersected point on the circle which is equivalent to the radius of the circle and you can also retrieve the [Music] the y-coordinate of this point here from the projected x from the x axis and you can also retrieve the x coordinate of this point let's call this c okay and which is aligned with the x-axis i say coordinate because if the intersected line comes here and if you project it if you projected the point to this positions then the coordinate becomes like this and in this case this point position is negative value that is because we are looking at this coordinate and this point is zero zero so now on the left side is x value is negative and to the right side the x factor is positive and the top side the y value is positive and the bottom side the bottom part the y value is negative so if you have a triangle if you have an intersected point right here and have an intersection like this then this point here is the x value is negative and as well the y value is also negative and if you have an intersected point right here and if you projected the point this point to an x axis then in this case x value x coordinate for this point is positive but the y coordinate is negative so for value b and c it is uh [Music] affected by where the point is located on a circle so if it's on the right top uh positions the b and c will be positive if it's right here the the c will be negative and b is positive this is negative negative for both b and c and this is uh c is positive if b is negative so that's um how you use this b and c as a coordinate in this case in order to express the the this information c and this information b now let me redraw this and start with the really simple example which is this triangle when b and c is positive and you have theta now sine function cosine and function tangent function drills a relationship between those four information and you can use this to express like this so when you say sine theta you use sine cosine tangent with a angle this angle and when it's sine theta that is equivalent to b divided by a so b divided by a is a sine function okay and if it's cosine theta that is equivalent to c divided by a sorry c divided by a yeah like this so that is equivalent to cosine so goes like this and if its sine goes like this and if it's tangent it's b divided by c so goes like this and if you look carefully to these functions this indicates that if you know at least two information out of this 4 for this triangle you'll be able to get the other values as well let's say if you have theta and a that you know then in that case if you use sine theta you'll be able to estimate what b is by moving this b or moving this a into the left side so this case a sine theta is equal to b so you'll be able to get the v value here by having a and theta if you want to know the value for c using a and theta then you can use this cosine value the cosine functions so in this case you can bring a to the left side and say a cosine theta is equal to c so by having a and theta you can also estimate what c is as well now let's say you want to get the theta value by having c and b in that case you can use tangent theta to estimate what the angle is by calculating the function for tangent theta now i'm going to explain how you extract the actual angle from the tangent theta later on but you can also extract the angle itself by having two of the edge lengths same for other functions as well so that's how powerful the track this trigonometry is you can estimate the other information about this triangle by having just two information out of this and if you have an angle like this if you have the edge from this point the the center to this point then you have an angle like this theta prime and the projected x coordinates comes here so let's say this is c prime which is negative value and a is the same that is because that's the radius of the circle and b could be a b prime and in this case b is positive now in this case cosine theta prime is equivalent to c prime divided by a sine theta prime is equivalent to b prime divided by a and tangent theta prime is equivalent to c prime b prime divided by c prime now one thing you have to be careful is that when calculating when estimating this value for ch c coordinate and a b coordinate and a at lengths you have to start the angle from the x axis so in this case we're using this angle instead of this angle so that's how it works if you just use this angle here then this c value becomes positive so if you want to know this c as a coordinate instead of a length then you should use this angle instead of this one and it's pretty pretty useful using this way because you can estimate the position of the circle position of the point coordinate on a circle by providing the angle information the angle in this case a theta information which in this case when you are estimating the c prime or b prime here which is also can be expressed as a coordinate of this point on the circle c theta and b theta and this point can also be expressed as c b and like this so by calculating the cosine and sine or cosine prime x sine prime you'll be able to estimate the point position on the circle and if you look carefully to this sine theta and cosine theta sine theta can contains the information b here which is the y-coordinate and cosine theta contains the information d which is this value and both of them have a value a and a bottom and if you multiply this by a then the bottom part will disappear and you in that case you also have to multiply it to the left side as well this will come this will become c and b which is equivalent to the coordinate of the point on a circle so and the a is also equivalent to the radius of the circle so meaning if you multiply radius multiply by sine you'll be able to get the y value y coordinate of the point on a circle and if you multiply radius together with the cosine theta you'll be able to get estimate the the y-coordinate i mean the x-coordinate of the point on a circle and this understanding can be a really great tool in order to control the point position uh if you want to create a point position on a circle based on a circle and in algorithmic design or computational geometry this understanding is very essential this is very important to know knowing a you'll be able to create a lot of interesting geometries or shapes and let's try to see how this works this really works by writing some code in houdini with the vex so that we have more understanding more deeper understanding so let's go to houdini and let's first create some setup with the lines and a circle okay first i'm going to create a line in a x direction so i'm going to set 1 for the x and 0 for the y and z for the zero and i'm going to keep the radius for 1 for now okay to make it simple next i'm going to create a transform node to control the rotation of this line so that i can rotate this line using z-axis from 0 to 360 degrees and as i said before in the channel instead of using radians you have to use degrees so in this case if you say 90 degrees you try you exactly type degrees in expressions if you say 100 degrees that's like this let's keep it like 45 for now we're gonna later on make it prometric next thing i would like to do is to create a horizontal line projected projecting the end line endpoint of this line to the x-axis and also create a vertical line okay so to do that i'm going to create a two-point wrangle connected to this frame uh this transform one here and i'm gonna copy one again and connect it to a transform the one for the horizontal line i'm going to call it h line and for the vertical line i'm going to call it for a v line now let's go to the h line and in order to project this point to an x-axis you just want to con access to the second point of this primitive which you can check it by first i'm going to make the guide point a bit larger then show the point number here so this is the number zero this is number one so i'm i want access to this number one point and project it on x axis so if the pt num at pt num is equal to one then i'm going to set the y uh at y-coordinate for this point to be zero so that it will be projected on the x-axis to have a x line the horizontal line now for this one similar to what i have just done if a pt num is equal to 0 in this case with this one i'm gonna i want to project this one to right here so that it aligns with a point uh the second point which is a id is equal to one so in this case i need to access to the point position information for this point so before getting into the if conditions i maybe inside if condition i can first access to this point position right here vector n plus is equal to point zero p one and the point that i'm going to update is this one so point x coordinate i want to update x coordinate align with this one this point which is this point so and pause dot x so you have a vertical line projected from this point now let's merge these together and also merge this one as well and let's bring this a transform to the first so we have a merged three lines to create a triangle like this i also would like to create a circle so that this point here is touching the edge of the circle so the size of the circle should be equivalent to the edge length right here for the line the initial line here which is this line so this line edge this lines length should be the radius of this circle so i'm going to copy this parameter then create a circle x y plane is fine i'm going to paste the radius here then connect it right here and let's also set it as a polygon set the division to 50 and set it as open arc so that we can see the edges now in order to get the information for the cosine sine and tangent uh for this triangle uh using a theta which is from this x-axis we need to know uh three information one is this length here and one is the coordinate of this point for the y and the x-coordinate for this point as well now i can retrieve those information this coordinate for this point x coordinate for this point y coordinate for this point and the length for this one by first of all let's access to the x coordinate for this point by going into the h9 point wrangle and inside the pt num is equal to one conditions which we were looking at this point we can access it x coordinate of this point so i am going to use that and set it as a detail attribute set detail at rib let's say c is equal to at p dot x okay and then if you look at the detail now you have the c value here which is the coordinate for this point and for this vertical point vertical line here i'm going to access to the pt num equal to 1 again so in this case if that pt num is equal to one then set detail attribute at p dot y let's name this b and add p dot y like this now that we have a v value with a this coordinate value for the y direction now this is positive right now so this is also equivalent to the height of this edge now we also want to know the edge length of this a value here this cannot be negative since this is the radius of the circle so for this one i can just say measure node and calculate the parameter now let's promote this to the detail by using attribute promote and from the perimeter to detail i want to promote perimeter and just saying average is fine because there's only one value here now if you go back the parameter is equal to 1 since this is the radius of the circle if you change the radius then this should also changes now i want to change the name to a all right now that we have a b and c value here let's go to the last one to see all those values being merged as an attribute detail attribute now let's connect this merge node to attribute wrangle and i'm going to change the runover to detail and try to calculate the sine and cosine and dungeon functions using those informations okay so make it detail and access to the a and b and c first by saying float a is equal to f at a float e is equal to f at b called c goes f at c now let's try by calculating the sine function first so the sine function was using this equations b divided by a so dividing this value with this one this a value here so let's try to see what the value is by actually calculating it f at sine value is equal to a i mean b divided by a okay and similar for a cosine value that was c divided by a and for the tangent that was b divided by c and let's see the result and the currently the value looks like these now we don't know if those are correct but we can we know we can know that this is correct by actually using the function prepared in a vex code vex programming language using sine function cosine function and tangent functions so let's try to use those functions which is prepared in vex and see if this calculation is really correct or not okay and in order to do that we need to use an angle in order to use those three functions sine cosine and tangent and currently there are no angle informations here but if you go back here using this transform you're using the angle right here we are controlling angle right here so we need to access this information in order to use sine cosine and tangent functions for the x so what i would like to do is to first create a angle parameter here like this promote this and let's try to use this parameter to link with this angle right here so that we can also use this inside this triangle as well okay so let's set the range for this angle i want to use it as a degrees for use user-friendly to make it user-friendly and convert it into radians inside of x because inside of x we need to use it as radians the angle should be in radians okay so right now the angle ranges in between 0 to 360 degrees let's copy this value and go back to the transform and paste relative reference to link it now if you try to change this parameter you can see that the triangle this edge is rotating and the projected triangles also been changing and you can also see that abc while a is fixed but b and c is changing and the cosine value sine value in tangent value is also changing based on the position of this point right here okay and let's see if this value is correct by actually using the sine cosine and tangent functions prepared in vex so signbot i'm going to create another attribute called sine value 2 and in this case i'm going to use the sine function together with this angle information here and this for this angle information i need to change this to radians so i'm going to create i'm going to use the function that i've explained previously to convert the degrees into radians like this and use this angle inside a sine function same for other values cosine vowel 2 is equal to the sine and for f at conjunct value 2 is equal to tangent value okay and let's see if there are any differences or if those values are the same and if you look carefully cosine vowel and cosine val2 is exactly the same value sine values line value exactly the same and tangent value tangent value 2 is exactly the same so you can you can see that you can skip calculating these functions using those three informations by just calling this find function cosine function tangent function using vects but you can also estimate the other values if you only know the angle and one of the edge lengths then you can estimate the other edge lengths as well using those two information two ways one one way is to use sine cosine and tangent functions prepared by x and one way is to calculate a sine sine cosine and tangent value using those edge length relations so let's say if you know if you only know a value and you want to know c or b and you also know what the angle is then that case let's create another attribute for b let's call b2 and which can be calculated by this sine value here or this sine value here since we only know the angle right so sine and multiply by a and using this calculation you'll be able to get the b value in this case a height or the y coordinate of this point which is equivalent to the original b coordinate which is currently negative 3.7 okay same for the c f at c 2 is equal to cosine and multiply by a and you'll be able to retrieve the c coordinate for the x and this understanding is pretty essential you can the relation between the angle and edge lengths now let's also try to change the radius of the circle which is currently estimated as a and which is set as 1 for now now let's create a parameter for the radius here float red like this and let's set the range from 0 to 5. copy this start with one and go to the line and set the line length with this radius value okay now let's see how those value changes by changing this radius if i change this you see that a b c value the edge length and the coordinate value for b and c changes but those cosine values sine value and tangent value doesn't changes doesn't change that is because these are the relationship uh these are ex just expressing the relationship between the edge and the angle but the edge length itself is changing so you can say that these cosine sine and tangent value kind of a relationship information the ratio of the how each edge size is dependent on the angle okay by changing so if you change the angle you see the cosine and sine and tangent value are changing together with a b and c but just changing the radius doesn't really change cosine and sine and tangent value because the the shape of the triangle the the relationship the ratio between the edge lengths is always the same even if you change the scale so only the coordinate value changes which is an essential information when it when you are you actually using trigonometry functions for your own purpose for your computational design purpose so by understanding this basic idea of this trigonometry function sine cosine and function let's try to use this actually for real practice as i said that the trigonometry using trigonometry functions like cosine and sine you'll be able to estimate the point position on the circle which means you can actually drill circles using cosine and sine functions so let's try to do that first as a basic exercise now let's create attribute wrangle let's set up the detail okay and let's first set the number of points you want to create you want to use to create the points to draw a circle as a polygon so let's parameterize this okay and let's set the range for this number from 0 to 100 i'm going to set the default value to 100 okay now i'm going to use the for loop to loop through the number of points that i want to create and create a point using add point function at some position now we haven't declared a position yet so this is where we want to use a trigonometry functions in order to estimate the point position on a circle now in order to draw a circle first you need to have a point of information on a circle right and if you know all those coordinates for each point on the circle then you'll be able to drill a circle at circle trail as a point collection of points then later on you can just connect those points together with the polyline or something all right so the essential thing is to know the coordinates for each point like x y and you should you can actually estimate this coordinate position by if you know this angle information right here and also the radius of the circle and as i explained previously when you calculate sine theta the value is y divided by r if it's cosine theta then that is x divided by r and if you want to know this coordinate x and y then what you just need to do is to bring this r to the left side so multiply r on the both side then in the right side the r will disappear and the r comes to the west side of the equations and as a result you'll be able to get the y value from r sine theta and x value from all cosine theta so that's how you can calculate the coordinate for the point on a circle using the angle with the radius so let's see if this actually works china and houdini with the vex okay so inside the for loop we're going to create first we need to have an information for the angle right for each point on the circle and the angle is in between 0 to 360 degrees and in radians that is equivalent to 3 0 to 2 pi so first i'm going to calculate a 2.0 by pi then we're going to divide this by a total number of points which is this one and then multiply by i so this calculation will create a a series of numbers which starts from 0 to 2 pi since i iterates increase increment by one inside a for loop until a number value here let's end with the semicolon now that we have an angle we can calculate the sine value and cosine value using the sine and cosine functions for using vex function so float sine val or in this case we can just say x coordinate is equal to a cosine of an angle multiplied by a radius and we don't have a radius yet so let's also create a radius so float red chf red and let's use this red variable as a radius and float y will be a sine angle multiply by the radius okay and let's use this x and y to create a position value so x y zero i'm going to set the z z value as a zero then use this position to actually add the point and let's see how it goes now we don't have a parameter yet for the radius let's set the radius range from 0 to 5 and let's also name this drill circle let's see if i change the radius you can see that i have just drawn the collection of points which is on top of the circle a radius of 0.75 for now and if i crease the radius the point position just changes depending on the radius of the circle and let's also try to create a circle to compare if the position of those points are correct and let's set it to polygon like division 50 open arc and i'm going to copy this radius copy this parameter and paste it to the uniform scale to use it as a radius now let's show this and you see that the the point is overlaying on top of the circle so i we have just successfully created the points which is on top of the circle the radius of 0.73 and if even if i change this one it's still on a circle like this so this is one of the powerful feature of the trigonometry using trigonometry to estimate the point position on a circle which is pretty useful for many cases to expand this basic knowledge let's try to also create some animations using this uh trigonometry functions together with this circle information that we can draw circle using those cosine and sine functions what i want to try out here is to try to create some object rotating like an orbit uh rotating around this circle like an orbit so let's try to do that first i'm going to create a object that i want to rotate let's start with the sphere and set the size to 0.1 to make it small enough then i'm going to create a single point i'm going to and i'm going to rotate this point counterclockwise and use this point to position this sphere right let's do that since i have only one point i can use either point wrangle or detail i'm going to just use point wrangle and let's name this rotate round rotate or let's say orbit of it okay now first of all in order to make this points rotated uh like a circle we need to know the the angle information in order to use the cosine and sine functions to rotate the points we need to know the angle to estimate the point location and also the radius so let's create two parameters angle and the radius float radius this remote and let's set the range the angle let's say from 0 to 360 degrees and for the radius 0 to 5. now let's estimate the x coordinate and y coordinate and just like what we just tried using the previous rango node so that was x equals cosine multiplied by the radius and the y was psi multiplied by radius so let's do the exactly the same thing here load x is equal to the sine angle multiplied by the radius and float y is equal to sine angle multiplied by the radius okay now let's set the point position for this point here and at p is equal to set x y zero okay now let's set the radius to at least one and let's also have a circle as a guide to see if the it's if it's really rotating around this circle and let's copy the radius here paste it to this uniform scale now i want to now if i change the radius if i change the rotation of this angle well currently it jumps it seems like it's jumping pretty much that is because i haven't really i haven't converted this degree value into radians yet so i need to do that by using radians functions here now it rotates from 0 to 360 degrees now let's use this point to copy this sphere using copy two points node like this now let's also merge this sphere together with the circle and see if and let's also set the circle as a polygon with the open arc with enough divisions now let's go back to the orbit and change the angle and it does rotate around the circle now you can animate this like accessing to some expressions based on the time using those frame values like f or f f divided by f and ff is the current frame value and f end is this end frame value so this division will create a volume between zero to one and if you multiply this by six and 360 degrees then and when the frame is equal to one then this value is close to zero which in this case the frame starts from one so it is 1.5 degrees if it's 300 if it's 20 if it's at the end of the frame then the degrees become 360 degrees because the calculation here is equal to 1. so as a result if you play it you'll be able to create a loop animation based on the frame which is another essential things you when you want to create some motion graphics uh using cosine and sine and those time framed parameters or expressions now that was to draw circle as an exercise now the another exercise i want to show you is how you can draw a wave using one of the trigonometry functions and actually you can create a continuous wave which you see a lot when you see explanation for sine or cosine called as sine wave a cosine wave so let's try to draw that as well inside houdini now i'm going to again create a attribute wrangle set it as detail let's name it as draw wait okay now first i'm going to create some parameters like a number of points that i want to use and let's also create an integer value called switch to switch between the different waves for sine cosine and tangent to see the difference between those waves when using the different types of functions so i'm going to name this parameter switch okay let's promote okay it's got to be parenthesis now for the switch i want to set the range between zero to two so that we have three options to change cosine sine and tangent for the numbers we can have more points than this one so like set it as hundred so let's go to the jaw edit parameter interface for the switch from 0 to 2 and for the number 0 to say 100 now let's start drawing first i'm going to loop through all the points with the number that i have specified bracket okay first of all as the as we did for the circle we need to specify the angle for each point and if we look at the sketch now what we want to do is to create a wave like this one and to create it to create this kind of um wave we need to specify the point position for each point on a wave and to calculate this one to drill this kind of a wave graph what you need is only the height information for each point meaning the y-coordinate for the x-coordinate it just increments to a positive in uh direction i mean you can also go to the negative coordinate and negative direction but in this case i'm only going to increment the x with the same value like if you set the step value by one then at each point the x will be incremented by one okay for the y value we're going to use this x value as an angle and calculate the height and that could be sine cosine or tangent and each function creates different kind of graphs and the very graph that i have just drawn here is come from coming from the sine wave for the cosine and tangent wave we can see by actually joining on houdini okay now let's go back and first we need to estimate the i calculate the angle it will create the angle values of float angle is equal to in this case we're not going to create a looped like uh like a circle so it doesn't have to be in between zero to two pi on 0 to 360 degrees but it can be it can be expanded to an infinite number of a angle so in this case what i'm going to do is to first create a pi multiplied by 2 so that we have in degrees 360 degrees then do pretty much the same with the circle multiply by i divided by num now this will create the range between 0 to 2 pi for this loop but then i'm going to multiply another value for this let's name this as wave num as a float value so if it's equal to one then you have whole uh one wave which is from zero to 360 degrees if you have if you set this as two then you have 2 waves from 0 to 720 degrees so that you have a so that with this wave num parameter you can control the number of actual waves and it is also at called as a frequency frequency of the wave you can control the number of the waves is equivalent to the frequency of the wave and so we need to set this range more than one i want to set the this range to more than one so let's set it to zero to ten so that as in maximum we have 10 frequencies right let's start with one though now that now that we have an angle we can estimate the x coordinate and y coordinate as i said for the x x can be just the increment value you inside this loop so and i'm just going to set x values as angle so each step the angle incremented by i so i'm just going to say just going to copy this angle value to the x coordinate as an x coordinate for the y coordinate i'm going to use some functions either sine cosine or theta and i'm going i want to switch the values i want to switch the functions based on the switch value here so i'm going to stop it by zero then use if condition with this switch value to switch between these three types of waves so if switch is equal to zero then i'm going to use a sine wave for the angle for the y coordinate else if switch is equal to one then i'm going to use cosine wave else if the switch is equal to 2 then i'm going to use tangent for the y coordinate and let's see the differences i'm going to create a position value vector plus set x y zero and create a point at this point position this all right now now the currently the point number is 10 so i have there's only 10 points here let's increase the point number now we see that uh the one frequency the one the wave with the one frequency have been created and this is actually the sine wave when the switch is equal to zero and if i switch this to one then the wave comes like this starting from a positive one as a coordinate goes to negative one if you look at the geometry spreadsheet you'll be able to see at the point attribute starting from 1 and at some point it goes close to -1 right here and this should be somewhere around here and then go back to a positive one in the end close to positive one when it was sine wave it was starting from zero then goes up to one at some point right so somewhere around here and at some point it goes to negative one which is this one just equivalent to this position here and then go back to zero again close to zero so this is this is how the wave works for sine and sine infinity change this to two i mean not this one but if you change the switch to two then something uh more different wave happens which is this is the tangent wave and when the tangent for the tangent wave when the value when the angle goes from zero to in this case 180 degrees it starts to goes to infinite value the y starts goes to infinite value you cannot see the end right here if you try to see where it is where it is i mean this is not 100 degrees but it actually is 90 degrees sorry so that is somewhere we can check it by showing up the point number so close to 22 so close to 22 23 somewhere around here so you see that at 20.25 the point position goes to infinite or really small really high i mean small value it's a negative value which is pretty far off the end you know really see where it went but somewhere around here it's just disappeared into the display in the screen and if you think about it in the s the equations it's it's easy to understand why it happens if you have a circle and say this is the theta and the calculation for the tangent was say this is b and this is c the tangent of theta was c divided by b and when the theta goes to 90 degrees like this when the seat is close to 90 degrees then b becomes close to zero right so dividing value by zero gives the infinite value so that's the reason why you have this kind of weight so it makes sense now uh computational geometry wise uh for my personal from my personal experience i don't use tangent wipe that much but instead i'm uh tend to use sine or cosine waves a lot than the tangent but tangent is useful when in when it comes to estimate the angle then i'm going to show you that later on using the inverse trigonometry so there are some usage for this as well in terms of um designs as well okay now that we have tried uh showing the waves next thing i would like to do is to again like we did for the circle like to create some animations so that the points run over this wave and a bit more information how you can control the uh frequency and also the the step lengths now one thing i didn't try out is to change this wave number here so let's try that out first and go to the next one now if you change this wave number currently is one and if you increase this you see that the the wave is going to expand to x direction and if you set it to 2 now you have 2 same num exactly the same waves the sine wave when the switch is equal to zero if you set it to three now you have three waves and so on so by having this multiplication weight number parameter here you'll be able to control the number of waves how many waves you want to have like this and making it as a float you'll be able to control the numbers more precisely or with the decimal values so it's pretty useful in some case now just like what we did for the circle let's try to use this sine wave or cosine wave to move around move those points on top of the wave and animate it as a practice okay so start with the creating a sphere set it as 0.1 okay and then i'm going to create a single point starting from zero zero then i'm going to use the point wrangle to move this point on a wave like now i need a two information one is the angle one is the um you could have another values like radius but maybe not let's just go with an angle itself okay and x is can be just the angle and y could be a sine of angle we're gonna just test with the sine wave okay and then at p can be created using x and y okay now let's also promote this angle and while we what i want to do here is to cop use copy two points to move the sphere on top of on the position of this point here and then try to animate this sphere moving like a wave okay to do that we need to change this angle here currently it's from zero to one i want to set it as a degrees so that it's easy to control so let's set it as let's say 360 degrees and since we are crea using this as a degrees we need to change this to radians inside of x so say radians now that we have a point moving like a wave from 0 to 360 degrees now if you want to animate this one we can do the similar stuff we did for the circle animating on the circle ff divided by f end multiply by 360 degrees and as a result you'll be able to create animation of the sphere running on top of the wave for a single wave now the point here is that if you multiply this by 2 you are increasing the range from 000 to 0 degrees to 720 degrees so as a result you'll be able to have two waves so if you say multiply by five you'll be able to have five waves in one sequence from the first frame to the end frame and so this idea is pretty useful when it comes to animate by using a wave function currently in this case the wave using the wave function the point is moving to the x direction continuously but you can multiply this x value by zero meaning this becomes x coordinate becomes zero and as a result you only see this up and down animation and by looking at it you might be able to imagine that this continuous animations going from positive one to negative one can be used for many other purposes and i'll show you other example how you can use this for other purpose before going in let's see why we are having the value in between negative one to positive one for the sine function and that could also be set for the cosine function as well so let's say we have circle like this and when the angle is equal to zero then a value is always the same it's the radius of the circle and the b value here which was the height the coordinate the y-coordinate of this point is zero and the c which was the x-coordinate of this point is equal to a right so in this case the sine theta which means in this case sine 0 degrees is equal to b divided by a and since b is equal to zero then that is equal to zero so it starts from zero right when it's 90 degrees then in this case c is equal to 0 when the point is right here but then the b becomes equal to a right in this case a divide b divided by a means a divided by a and that is equal to one so that's the reason why in 90 degrees the sine wave will give you a positive one now when the line comes here when the points intersected at this point then the angle is 180 degrees and in this case c becomes minus a and b becomes zero since for the sine we're using b again so the value becomes zero again for the sine sine 180 degrees is zero now for this point uh this time the v becomes minus a and c becomes zero and since we're using b here and this is going to be minus a so the result of sine 270 degrees is equal to -1 so you can see that the value goes from 0 one zero minus one and zero back to zero again so this indicates this kind of wave starting from zero becomes one becomes 0 again because negative 1 becomes 0 again and this 0 value and this zero value is equivalent here so when we reach here another same wave starts to happen so this is how the wave works and this is similar to cosine if it's cosine when degrees is equal to zero then cosine theta was c divided by a so c the initial c value here when the theta is equal to zero is eq c is equal to a so in this case a divided by a so becomes one so that's why a sign the wave for the cosine starts from one goes to zero minus 1 0 and 1 back to again so this is one range for the cosine wave so you can see that the cosine wave and sine is pretty similar it's just half pi offset it so if you offset the sine wave just 90 degrees to the left you have this same wave that you have right here as a cosine weight meaning you can also say that um [Music] sine theta plus 90 degrees is equal to cosine theta so that's how it related in terms of the wave functions okay well you don't really need to remember how this related but remember that it's it's a good idea to remember that when you use sine uh when the value always starts from zero when creating a wave from zero to 360 degrees and this cosine starts always starts from one when the angle is from 0 to 360 degrees and the range is always in between 1 to negative 1 when you calculate the sine and cosine functions so that's the essential part essential thing you might want to remember to use it as a tool so having that kind of information let's try to use a animated sine function or cosine function for other purposes like try to control the scale of the geometry like a wave okay so start by creating a sphere and i'm going to make it a polygon let's have like five frequency here then use a point wrangle to control each point of this polygon let's name this wave scale okay and what i'm going to do is to use sine function with the time value as an angle to control the scale of the sphere so that it will grow a bigger and smaller bigger and smaller like a way so first let's create a scale value and what i'm going let's just call this value and i'm going to use sign and inside the sign since i want to go back and forth based on the frame i'm going to reach first retrieve like i did in the expression i'm going first going to retrieve the frame value and divide it with a f end you can access to the frame end value like this dollar fn for the frame you have to type like this at frame so it's a bit different from the expressions but it just it's how it is inside of x okay and also i'm going to multiply with the pi multiplied by two since we are dealing inside of x we cannot use degrees but instead we need to use radians so that's why we're using pi and pi multiplied by 2 is equivalent to 360 degrees so currently we have just created the angle value between 0 to 360 degrees changed by the frame value okay now let's change this value currently the values range is in between -1 to 1 using sine that is because i'm using sine function so to make it but i don't want to use negative scale for negative value for the scale value but i want to set the range something like 0.1 to 1 say in that case we need to remap this value which is in between -1 to 1 to a new range to do that we can use a function like fit which is a functions in effects in order to remap one value from one range to another range so in this case we want to remap this value which is currently inside minus one to one minus one is the minimum and plus one is the maximum value and we can set this to a new range which i want to set the new minimum to 0.1 and new maximum to 1.0 as a result we can use this value as a sql value to you actually use it as a scale we can multiply the point position with this value okay let's see now the point has uh the scale has already been changed and if i play it you can see that the scale is changing over time and it's going from small to big to big to small again and creating like a wave animation so this is one of the way you can use uh sine function or cosine function together with the time to create and essential animations looped animations like this wavy animations and if you want to make this quicker to make this animation quicker you just need to multiply this value into inside the sign like by two you can have you can now have two frequency two wave frequencies within this frame range that is because that is equivalent to 0 to 720 degrees which makes the scale animation faster so if you say 5 you have more faster animations like this so that's one of the uh basic example how you can use wave uh sine wave or sine wave you can also change this to the sine wave just but the overall animation it looks the same because it's just a 90 degrees shifted value the only difference is that it starts from different value so that's how we can use uh as a basic exercise so i hope you understand the basic idea of how this sine and cosine function would work together with a like a time value to create some interesting looping animation and this idea that this very idea could be expanded for many other purposes so which is really useful and powerful so please try to remember how you can use this now that you have a basic understanding of the basic trigonometry i would like to introduce you to some of the other trigonometry functions which is called as secant cosecant and cotangent which is actually a just an inverse functions for the sine cosine and tangent functions so it's pretty much similar to what we have just done but the the wave shape is going to look a bit different and you don't i don't think you're going to use those functions that much so and the vex doesn't really have those inverse trigonometry functions so you don't really need to remember it i mean it's not really necessary to remember it but just want to show you what these are about okay so i'm going to start by creating an attribute wrangle let's name this csc sec and code i'm going to introduce you a three different other trigonometry functions which is an inverse of sine cosine and tangent now let's start by creating a angle and create a parameter like an angle let's set it to set the range from 0 to 360 degrees okay now let's also change this convert this into radians like all we always do in order inside of x now the first thing i like to show is the cosecant cosecant and it is often expressed as csc in programming languages although in vex we don't have this function so i'll just call it cosecant and it is calculated by dividing one by a sine of an angle so this is just this is just this cosecant is just an inverse value of sine value so that's just it and for the other valley it's pretty similar to the value called um secant is a inverse value of cosine and if at cool tangent is the inverse value of tangent value so that's just it it's in some cases these values are useful but most of the cases you just need to remember those sine cosine and tangent because these inverse value cannot can just be calculated just by creating the inverse of this sine cosine and tangent so you don't really need to remember those names but in some cases when people explain some people use these names to express uh this inverse number so it's just for your reference when you see this for first time and you don't know what it is just remember that it's just one of the inverse number of sine and cosine and dungeon it's nothing more than that right and let's look at the detail attribute and see how numbers changes and the difference between the sine cosine and tangent with these cosecant and secant and cotangent is that in for any for any other values here for every values listed here all these values will give you an infinite number because for all those values there is a chance that you get the value zero so all these values will give you at some point an infinite number so we could see that actually by drawing a wave using these values like like we did for the sine cosine and tangent so let's try to do that by just copying the one that we have used to draw the wave which is this one so i'm going to copy this one bring it up right here and for this one we were drawing the wave for the sine cosine and tangent but instead we're going to replace this with an inverse of these values so 1.0 divided by sine which is the cosecant one divided by zero by cosine which is the secant and one divided by uh tangent which is the cotangent and as a result when its switch is equal to zero then that is cosecant you'll have a wave looks like this if it's one it's pretty similar to the cosecant seeking a cosecant it's pretty similar it's still a half 90 degrees shifted wave when it's come to a cotangent it looks a bit different let's set the wave number to one it's pretty similar to the original tangent wave as well if you make it back to the original tangent value it looks like this if you divide it by one if you have an inverse value it looks like this one so that's just it i'm gonna set it to now i don't use these functions that much because see this inverse functions that much i just wanted to show you the name how what these names is for stands for and i just wanted to show that these are just the inverse number of the sine cosine and tangent and in practical in practices for a computational design you don't use these values that much i mean there are chances that you use inverse number of sine cosine and tangent but most of the case you don't use this name that much but it is only to it is only the reference for you to know that these values stands for an inverse when you look at some papers and so on when you see this name now let's go to the last topic and the topic that i want to show you and the last is how you can estimate the angle from the edge length there are chances that you only know the edge lengths and you don't know what the angle is for those edge edge lengths in that case um and there's just a function to get to retrieve those angle value from the edge length of the triangle so let's see what it what that is the first thing i'm going to do is to copy one of the node that we have created previously which is this set where we have created a circle with the triangle where we can control the angle and all those values has been stored inside the detail attribute so i'm going to copy this one as a basic set to estimate the angle from the edge length okay now that we have just copied it and let's name this st angle now what i want to do is to say that we don't know what the angle is well currently we have we do have this parameter here but let's say we don't know that value but we only know the edge lengths for a b and c a is here and b is the height coordinate or the this point coordinate for the y and the c is the x coordinate for this point here or point here okay so those are the value that we know but other than that we we don't know the angle but from those three values we want to estimate this angle value and we can actually do that by using a so-called inverse trigonometry the previous one that i showed you it's not the true inverse trigonometry this is the inverse value of a trigonometry functions but the one that i'm going to show you is called as a inverse trigonometry is a kind of a different stop which which have a different name for the functions and each one is used to estimate the angle from a sine or cosine or tangent function values and you know meaning that using having the value for the sine cosine and tangent you'll be able to estimate an angle from those values for the sine you you can use a function called arc sine to estimate this angle for this out from this output for the cosine you can use one called arc sine and for the tangent you can use so called arc tangent so let's try to see how we can use that now since we already have uh have the value a b and c which is this one right which is this one and we also have we let's say we also have calculated the sine cosine and tangent value with this equations here let's remove those okay so we have three values we have three values for the sine cosine and tangent now what we all you want to do is to estimate the angle from those values and we can use that by using inverse trigonometry functions and if you have a sine value then what you can do is to calculate the angle using a arc or a sine function a sine is same as an arc sine it's also an inverse sine of the argument and inside this parameter you put the sine value calculated by b divided by a and as a result you'll be able to get the angle value used for this sine wave a sine function let's promote this to a attribute and as a result we have got the sine value saying 0.7749 well let's convert this to degrees so that we it's easier to see what the angle is so let's say degrees now it says 50.8 now it looks like it's a bit different from 128.2 but i'm gonna explain why that is later now let's also calculate the cosine angle because degrees a cos so a 108 arc cosine is typed as a cost and use it for a cosine value this one i'll give you a 129.2 which is equivalent to this angle here now let's see another one f at tan ang it is degrees a10 f at tangent value and as a result you'll get minus 15.8 50.8 now let's see what those angles means when we calculated the arc or inverse trigonometry of those sine cosine and tangent here now let's look at the sign angle first this one f at sine angle and let's focus on this value here by changing the base angle and see how this changes you can see if it when it starts from zero the sine angle is also zero and until 90 degrees the value for the original angle for this one and this angle here is the same but after 90 degrees the value gum becomes decreasing the value is decreasing until 180 degrees so that means when we use sine arc sine what we get as an angle is this angle here for the triangle not for this angle but the angle which is in between these edges of one for the the center to the point on the circle and one is the edge which is the projected the from the center to the projected point on the x-axis so that's the act that's the angle that we're going to get when we use sine arc sine and if we go to more than 180 degrees then now the angle becomes negative in this case and go back to from 270 to 360 degrees it still is calculating this angle but multiplying by minus one so when we are you when we use arc sine when the angle is between 180 to 360 degrees the value for this one becomes negative and it only calculates the angle between this projected curve projected edge and the edge on the surface edge on this circle and one of the points of the edge ends on the circle so the value for the angle that we could estimate using this arc sign is pretty a bit limited from the original uh our from the original angle we do have an angle even though we have like a various angle from 0 to 360 degrees just by looking at the arc sine uh we'll get a limited information about this angle if we now if we look at the cosine arc sine arc cosine value which is this value here if you look carefully from 0 to 100 degree 100 at 180 degrees it looks just pretty much the same with this valley here if you go more starts to decrease and go from 180 degrees to zero now this value now this cosine arc cosine doesn't give you a negative value but the range is still limited it's 100 00 to 180 degrees and if you look carefully what it really means it look it uses this x-axis as the base axis and from 0 to 180 degrees the angle is between this x-axis between this angle this line projected to the circle or intersected to the circle so we are always getting this angle here 0 to 100 degrees when it goes more than 180 degrees what we get as an angle is not this angle here but actually angle right here so the angle we get is always in between 0 to 180 degrees so if we wanted to know the angle from 0 to somewhere around here like 208 you cannot use cosine arc cosine as well since this is a bit limited as well as well as the arc sign okay if you look at the arc tangent now which is this one and the attribute tan ang which is this one here and let's see how this changes if it's zero it starts from zero if it's raise up until 90 degrees is still the same as other values now after 90 degrees it becomes minus 90 degrees it flips to minus if it's the negative for the left hand side and starts to decrease and if it goes more than 180 degrees it starts from zero again goes to goes up 90 degrees until 270 then after this goes back to one negative 90 again and goes to zero so honestly speaking this cotangent or i mean arc tangent val result is most uh difficult to read as a result in order to re in order to use it for your practice it's a bit hard to use because it it's not really straightforward value in terms of the value that based on the position of the point so even though i said that those inverse trigonometry functions can be used to estimate the angle the actual angle you get out of this arc sine or cosine or arc tangent is kind of limited but fortunately there's other functions inverse trigonometry functions in order to estimate the angle which is can be used to estimate the angle between 0 to 3 and 360 degrees that's what we really wanted to know so i'm going to show you what that is and that is called as arc tangent 2. using that function you'll be able to calculate the angle between 0 to 360 degrees and that's the most used functions in order to estimate the angle from the edge lengths and i'm going to show you how you can use that okay now to use that you just need a coordinate for this point right here and you also need to know where is the x-axis in this case x-axis is one zero zero so it's pretty straightforward and this coordinate right here currently is expressed as b and c the b is the y coordinate and c is the y x coordinate and can be expressed from positive 1 to negative 1 for both b c value now to use those bc with the arc tangent 2 you use like this so first i'm going to create a tangent angle tan ang 2 and convert the angle that i'm going to estimate to degrees then used a function called a 10 2 for 8 and 2 you need to specify two parameters one is the y value and one is the x value and the y value is in this case b and the x value is in this case c and as a result the value you get tangent 2 can be used to express the angle between 0 to 100 um 0 to 360 degrees now let's see how it works currently the anguism is 60 degrees if let's start from zero so it goes up until 180 degrees now you can see that the tangent angle 2 is raising up until 180 degrees and after 180 degrees it switched to minus 480 degrees but actually this 100 minus 180 degrees is is equivalent to a 180 degrees because that's just the difference between if you calculated angle from counterclockwise or clockwise okay if you raise up more you see that the negative value is increasing but that is also equivalent to this value here this value from 0 to 229 or 240 let's say 245 and currently it says negative 115 but that is equivalent to 245 as well if you uh add this negative value by 360 degrees you get the same value so even though if you it looks like it's the different number from this value it's still the same it the value it's expressing is the same value so you are actually getting the value in between 0 to 360 degrees like this and this function is pretty handy i use this a lot myself to estimate the angle between two vectors even even though if it's in the 3d space and you even though you don't know where the x axis is you can still estimate the angle between two angles two vectors and i'm going to show you how you can do that as a final exercise okay so remember that you can use this um arc or inverse trigonometry functions to estimate the angle most of the cases i use this one but if you only need to know the angle between 0 to 180 degrees then you can use like cos cosine or arc sine or tangent maybe maybe you don't use this arctangent that much so maybe either arc sine or cosine but if you have more information if you need more information arc engine 2 might work better for you okay so let's try to use this as an exercise and let's end this topic or session now let's first create two lines to estimate the angle between so i'm going to create a two line [Music] one is facing the direction or y direction and one is facing x direction let's set this as an x directional line so the currently the angle between those two lines are 90 degrees now some would like to create a transform node so that i can rotate it freely to have a various angle between those two lines okay so one transform here another transform to the another line now i'm going to merge these two lines together and try to control i try to estimate the angle between two lines using some vex coding now i'm going to use a another detail attribute so first i'm going to create a attribute wrangle and set the run over as detail and set angle for the arc now let's first have some parameters in order to control uh the angle for these two lines though uh well what i really want to do is to estimate the angle between those two lines so i don't want to show that up inside the code because that's going to be a cheat all right so i'm going to create a parameter just a parameter which i'm not going to access using the insider code just going to use it in order to control the rotation for this initial rotation so i'm going to create two flow values one is angle one or let's just say it could be a random seed so that we don't actually know what the real angle is right so seed one and the other one is c2 all right apply okay now let's look at those now let's have this as a degrees so i'm going to set the range from 0 to 360 degrees or i mean this is acetone it doesn't need it doesn't really need to be an angle value so i'm going to copy this parameter then go back to the transform and for this for the first rotation let's say i'm going to control the y rotation so rotating this way and using the seed together with the random function and inside random i am going to cop paste what i have just copied which is random seed so as a result you'll be able to create a value between 0 to 1 random value between 0 to 1 so i'm going to multiply this by 360. right i'll do the same thing for the other transform now let's copy this value and bring this to a second transform and for the second transform going to try to rotate it with the x-axis all right now i and let's use the different seed so in this case this this seed one okay so now we have two seed connected to those uh random seed value for the transform the first transform and second transform and if i change this seed value i'll be able to change the angle randomly between those two lines okay so the setup is good we now have a information how we want uh now we have an information now we can try how we can estimate the angle between those two uh lines and to do that i'm going to use the specific a functions the inverse trigonometry functions a what i have just shown you which is an arc tangent function arc tangent two functions okay so to do that uh first we need to know the vectors between two uh lines the vectors for each line and we also need to specify the x-axis in order to calculate the angle here now what i mean is that from now until this point we were only dealing with the two-dimensional plane right so we only had x and y coordinate but the one that we are dealing with here have a additional dimension called z so we are dealing with three dimensions and in this three dimension we have two lines like this and we don't this coordinate for each point could be x y z and this one is x y so the difference is that we have additional coordinate here for the z here which makes a bit difficult which makes a bit um a bit more difficult in order to estimate the angle between these two lines but you can actually do that i mean previously we were using this x-axis for the base in order to calculate the angle but what we can do now is to use one of the vector either this one or this one as the base axis so say you you want to use this axis this vector has the base axis and say this is capital x and using this as a base axis to calculate the s the angle between the vector for the other vector and by doing that you'll be able to estimate any kind of vectors which is on the 3d space using the same function like a tan two and to do that let's say this is the x-axis but and on 3d space so maybe i'll just call it a right and there's a vector that you want to calculate estimate i mean there's a vector that you'll already know what the value is and you want to estimate this theta what you can do now is to know the x and y values for in order to use it with the a tangent two functions right so this is the f this is the parameter for the function y and x and previously when the coordinate was x y coordinate it was pretty easy we were just using this x axis as a base and use the projected point this coordinate as a x coordinate and this height as a y coordinate and trace it this phrase this value into this parameter and as a result you'll be able to get this theta value but in this case you don't actually have i mean this is not on the x y plane so what you can do is to consider this a axis as a virtual x-axis and project this vector onto this a axis like this so that this will be 90 degrees and this is pretty easy to i mean we have done this thing from a previous sessions which is by using a dot product okay using dot product if those if let's say the axis is normalized and you you want to know the length of this size here let's let's call this c or p as a projected length okay this p can be estimated or calculated by p equal dot or b dot a and a is normalized so the length is equal to one as a result you what you get is this projected length of this vector v and if you have this p information the projected length here you'll be able to create this vector as well right here you just need to multiply this a and normalize vector a with p and you'll be able to create this vector and if you have those two vectors you'll be able to estimate the lengths for this height as well which is which can be estimated by calculating the power of p plus h power of 2 where h equals to the length of b multiplied by the same value so the power of 2 which is this is b right so if you if you're if we are looking at the triangle with the one of the angle being 90 degrees then this kind of equation can be used p multiplied by p plus h multiplied by h is equal to the edge length of v multiplied by the edge length of v right so as a result the h can be calculated as p or e minus p [Music] divided by or or square root of those subtraction right and then you'll be able to use this as a y value and this as x value to calculate with eight tangent two and as a result you'll be able to calculate estimate the angle between two angles between two vectors shall we try this if this really works or not the first thing first we need to have we need to know two vector informations right so let's get that and to do that uh we need to access to two primitives uh okay so let's first access this first primitive and for from the first primitive i would like to access to two points of the first primitive so for this one and for this first primitive you have two points obviously because it is just the line so let's try to get those two points using a function called prim points using print points you'll be able to get the points constructing this primitive and at zero so zero means the first primitive and i'm going to call this pts1 and array now let's also get the second primitive by changing this to one let's set the name to two now from each of the array we're going to retrieve two points so let's say for the first one i'm going to call it pt11 which is the first index of from the array pts1 and pt12 is the second point and i'm going to retrieve the point position from each of the point number like this now calculate the vector from the first point to the second point by calculating the subtraction and let's name this direction one and we know that the length of the line is equal to one but just in case i'm going to normalize this so that the length will be forced to be one all right now let's do for the second one i'm just going to copy all these and rename this to 2 1 2 2 pts2 pts 2 and position two one position two two direction two is a subtraction between position two two minus position two one and this should also be two two two one and two two right now we have uh created a two vectors direction one and direction two so one of the direction should it express one of the lines here and one of the the other one express the other lines all right now what we want to do here is first of all um calculate the dot product between those two vectors let's see how we do that so first of all plot dot is equal to dot direction one direction two okay now that we have uh we have uh retrieved the projected lengths uh forward direction one two direction two or direction two to a direction one and we can use this you can use that as a p-value here right here which is the dot product between two axes not two vectors and i want let's say i want to use this direction one as a axis right now next thing i like to do is to calculate the length for the h here right here and to do that we need to know the lengths for the vector the other vectors direction 2 in this case and currently we have normalized this so we the size is equal to one but in this case we shouldn't normalize this so what i'm going to do here is to say the b length is distance between the position one two one and position two two so that just in case um this links uh well although i could just just use the length of direction two as it is because this is also normalized if you don't normalize this then you need to calculate the distance so maybe it's better we don't normalize at here for both direction one and direction two but for when we calculate the dot product only for the direction one i'm going to normalize this so that i want to use this direction one as an axis base axis to calculate the angle right now for the length uh for the direction 2 i can just say lengths of the direction 2 to get the magnitude or the length or the size of the vector now that we have two informations the dot product which is the projected length for direction two to a direction one and the size of the direction two we can estimate the size of and height by first of all calculate the power of two for the lan and dot product and subtract it like this then calculate the square root like we have done here this okay now that we have an h value at a height value we can use this as a y value and we can use this dot product as an x value for a arc tangent 2. so let's try to estimate the angle here so angle is equal to a tangent to and the first parameter will be y so h and second one will be dot okay and let's uh have this as a degrees as in attribute so since we're in detail i'm going to create in a detail attribute so angle is angle okay so let's again split the panel from top to bottom and and the bottom panel i'm going to show up the geometry spreadsheet for the detail and there you go there is an angle here and currently it says one 30 degrees and looks like it is let's change let's try to change some parameters here let's see the changes so currently this one it says 44 and i feel like this it says 87 now we don't really actually know if those values are correct or not so uh let's see it by changing this value to the constant value instead of the random value okay so to do that i'm going to create a switch node or maybe for this one and create another transform node connect it to this line and do the same for the right one create a switch create a new transform node connect it to the switch and currently and also let's copy this parameter and paste it to the switch select which parameter so that those switch values will be linked and change the switch value to 1 for now so that the right hand side transform will be used now going back and currently the angle should be 90 degrees because i haven't rotated anything and if you look at this angle here promoted to the detail attribute says 90 so it looks correct now if i rotate one of the angle here let's say this one to 45 degrees that doesn't seem to change all right okay i think i should rotate for the y maybe for the x and z okay so i have used the z-axis to rotate this first uh line so the angle between those two lines should be 45 degrees let's see if that's true by looking at it and yes it does look like so and also let's try to rotate second one let's rotate this 90 degrees now it becomes 90 again if we look at it it says 90 if we rotate this by 135 the angle should be somewhere around 135 so if we go look back again oh it says 120 i guess that's it's because combining this 45 degrees with 135 degrees the actual angle between those two lines became 120 so i it seems like the degrees to angle that we are getting using those two for those two vectors are correct uh using those method so that's how you can estimate the angle between two vectors even though if it's even though in the 3d space now that we have estimated the angle between two vectors what i want to do as a final exercise is to use this angle information and together with those vectors i would like to create or drill an arc connecting one of the edge to the other edge using these vectors as a plane information and especially without using like transforming functions but only using cosine and sine trigonometry functions it's going to be a bit more advanced things and you don't actually need to use cosine and sine functions to drill that but if you know how you can drill those and draw this arc just by using cosine unsigned and you are really i think you have enough information to use those for many purposes for computational design purpose so let's see how we can actually do that now previously when we were drawing circle or arc we were only dealing with the x y 2 d axis right and that was pretty easy to deal with because the point information can be described using a cosine theta and sine theta multiplied by a radius but when it comes to 3d it's going to be a bit more hotter it's going to be a bit more difficult to express this circle so let's say the axis we have axis x y and z and you have an arbitrary plane here with the two vectors b1 and b2 and what you want to do is to create a arc at this point just by using the angle and cosine and sine how do we do that actually if you try to think this plane as a 2d it starts to become a bit more simple just like what we did in order to calculate the angle between two 3d vectors we can estimate one of the vectors as a virtual x-axis so say this v1 becomes a virtual x-axis and this b2 is there's also a virtual y-axis somewhere around here and this b2 is on top of this x y virtual x y plane there is a virtual circle which can be drawn on top of this virtual plane now it starts to become and more understandable the value that you get out of the cosine and sine is still a x coordinate and y coordinate but in this case for this virtual x y axis x y plane so this let's name this a and this name is b for the x and y so for the cosine value which is used for the x-coordinate can be used together with the virtual x-axis and before previously the when we were dealing with 2d xy the x axis x expressed as 1 0 and y axis was expressed as 0 1 y is 0 1 right and in when we were using the cosine value and sine value to estimate the coordinate for x and y we were actually saying it as 1 zero multiplied by cosine is equal to x coordinate and one zero one multiplied by sine theta was actually was y coordinate and as a result the 0 multiplied by sine is 0 so only the y value is used and only the x value is used for the cosine and as a result the cosine and sine was the coordinate for the circle point position but then if you think like this then if you replace this chord axis value with this virtual x and virtual y then this can be replaced by some more general um function like let's say the virtual x-axis is written like let's say x1 x2 and x3 and y-axis expressed as y1 y2 y3 right and the cosine theta was multiplied by the x-axis so in this case x-axis multiplied by cosine theta is actually going to be the actual x-coordinate and y axis multiplied by sine theta is actually going to be a coordinate for y uh prime which is this coordinate doesn't make sense now it's a bit it sounds a bit too advanced but if you think from a 2d you can easily step into a 3d and the actual equations in order to estimate the 3d positions for the circle is pretty actually pretty easy to do it's pretty easy to estimate that's what i wanted to show you and that's what we're going to try to code here okay and if we are feeling comfortable about this idea then you're good to go with a trigonometry you can do a whole lot of things using trigonometry for all uh so many purposes right so let's see how we can implement this so first of all we need to create a virtual x-axis and that virtual x-axis can be just by using one of the directional uh vectors either like direction one or direction two so let's just use direction one and since this is going to be the virtual axis i'm going to normalize this so the length will be equal to one so i'm going to name this x-axis as a normalized direction one now what we want to know is the y-axis now so that we can estimate we can know uh the virtual y so that where the where this second line is lying on to do that um one of the idea that i could think of is to first calculate the cross vector cross product of those two vectors now if you remember from the previous um sessions or previous tutorial we were talking about the vectors and the cross vector the cross product of two vectors is actually a perpendicular vector of two vectors so in this case we have two vectors like this we could get the cross vectors forwarding to this direction well we don't know which one is direction one so it could go to the other direction though but let's try to see that so if we calculate the cross factor of two vectors we could calculate the cross vector we could calculate the perpendicular vector of two vectors and after we have got this vectors we can actually use it as a virtual z-axis right and by having a z virtual z-axis we could also try to get the virtual y-axis by using the virtual z plus a virtual x to calculate another cross vector another cross product between those two vectors i'm gonna explain that in sketch so which is kind of a trick so let's say this is the 3d vectors e1 and b2 right and there's arbitrary angle here and what we want to know first of all i have set the v1 as a x-axis the virtual x-axis now we don't know yet what the y-axis yet but we can estimate the z-axis using those two vectors by calculating the cross product between the v1 and v2 and then as a result you'll be able to calculate this angle for the z the virtual z which is perpendicular to the v1 and b2 after we have this perpendicular vector for the z-axis and using z and x to calculate another cross product c x and as a result you get another perpendicular vector for this t and x and that is equivalent to this y axis right so you by having two cross vector uh cross product calculations you'll be able to have all the axes you need in order to drill a circle in order to have a virtual plane in this case i only need x and y but in order to create that i needed this z all right i hope it makes sense and let's see how i could do this right so i have just we already have this x-axis let's say this is the x-axis and we can calculate the z-axis by calculating the cross product between the x-axis and the direction two which is this one right which is this another vector here so let's also normalize this just in case twice direction two all right now that we have two vectors x-axis and the perpendicular z-axis now what i can do now is to calculate the y-axis by calculating another cross product between the z-axis and the x-axis now as a result you should be able to create a all those information in order to calculate in order to create a virtual plane which in this case x and y now we can try to create some arc here now we know that the the maximum angle i mean the angle between those two angle two lines are uh calculated as angle here as a ton from a tangent to so i'm going to use that we are going to use that to actually draw a collection of points like an arc from the center here okay so let's do that but first of all i'm going to create uh estimate or set the number of points that i want to create use creating some parameters like num and let's set the maximum 200 this and let's create a for loop just like we did to create a circle wave and we're going to calculate the step angle from 0 to [Music] the maximum angle right here so this will be the maximum angle let's say this is the axis and want to start drawing the points from here then while we what i want to do is to create an arc like this connecting from one edge to another edge and the maximum angle is this angle that i have calculated using a tangent to now i want to divide this angle by some numbers that i have specified here and each angle i'm going i want to plot the point so that it becomes like an arc okay so to do that just like we did for the circle i'm going to a multiply angle by a iteration number i divided by number and as a result you'll be able to get the value in between zero to angle for each iteration maybe you might want to subtract number by one because i ends at number -1 so if you want to have the final angle value to be appeared then this might work well okay now next thing what you can do is to calculate the the length for the virtual x direction and length for the virtual y direction using cosine and sine so the x lengths will be or x coordinate will be cosine angle or sand road y will be sine right now these are the coordinate on the virtual x and y now the final position can be retrieved by multiplying this value together with the x-axis and this value together with the y-axis and that's if that is going to be the final point position for the arc should be now let's name this like tx for the x coordinate and should be vector and i'm going to multiply x axis with a cosine value here which is currently x and vector t y for the virtual y position i'm going to use y axis multiplied by y right now that we have two values we can add those two vectors to create a combined uh two vectors four of two virtual axis and to calculate the final point position so the final vector position t plus is equal to t x plus p y it's just a simple vector addition and finally we could add the point to this in position and we gotta set the number of points here now seems like something is okay i need to change this to y axis sorry for that and okay well seems like the point position is a bit off from the second line let's see why did i change the lengths for the line nope okay the reason why this has a bit of offset here is because i didn't normalize this y-axis here after calculating the cross product okay so yeah i should do that and i also would like to normalize the z-axis which i can just do it right here and also for this one normalize this so that the length will be equal to one and as and as a result you'll be able to connect those two edges of the point to edge for the primitive and create a arc like this all right looks good now let's try to change those angles i mean switch to the random and see if this still works okay now let's try changing the seed and even if i change to any seed it still creates these arcs maybe i should move the um an angle for the this one to here should create a bit more randomized angle all right so something like this the last part might be a bit too hard to understand for first look but if you follow carefully what i have just talked about you can you'll be able to do it by yourself as well and if you are comfortable enough to use cosine and psi in this way then there's nothing to fear about using trigonometry after this and you can use this as a powerful tool for many purposes and after this sessions i'm going to use like this trigonometry as a basic tool to deal with other functions so if you are not sure how this trigonometry could work or could be used try to please try to look back and understand how this works this is it for this session for trigonometry i hope you get the glimpse of what trigonometry is and how you can actually use it with for design purpose and the next topic that i would like to talk about is quaternion and use quaternions for a rotational transform okay and thank you for watching and if you found this video interesting or useful um i would love to have your comment also a like and subscribe if you want to look for other videos as well and i have also started the patreon myself so if you are kind enough to support me i would really appreciate it okay so thank you for watching and see you next time goodbye
Info
Channel: Junichiro Horikawa
Views: 5,504
Rating: 5 out of 5
Keywords: houdini, vex, programming, visual programming, tips, tutorial, beginner, howto, modeling, design, procedural modeling, algorithmic design, algorithm, array, basics, basic, introduction, scripting, procedural, variable, language, coding, attribute, function, cg, computer graphics, graphics, computer, computer science, mathematics, math, game, game design, vfx, simulation, sim, tutorials, container, dictionary
Id: gLOd_FFL58Y
Channel Id: undefined
Length: 165min 40sec (9940 seconds)
Published: Sat Dec 05 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.