ac.tomo Posted June 23, 2021 Share Posted June 23, 2021 (edited) On the 8-bit Atari's there are very few subjects that I don't understand and for 2 reasons: 1. I never got round to it, and 2. They are quite often too complicated for me to understand. Algorythms is one (of which I will be looking into soon) and 1 of the others is math formula's: Take for instance, the basic circle using COS and SIN: 10 GRAPHICS 8:DEG :COLOR 1 12 SZ=50 20 FOR D=0 TO 359 30 X=(COS(D)*SZ)+160 40 Y=(SIN(D)*SZ)+96 50 PLOT X,Y 60 NEXT D This is fine, I understand COS and SIN, but what about other formulas such like: COSH(x) = (EXP(x)+EXP(-x))/2 - exactly how would I implement this in practice (in a program)? What does COSHH(x) do exactly? There is a lot of formulas (that I wrote) in the Compete & Essential MAP part II, page 235. I understand the syntax but dont have a clue as to implementing them into a BASIC program. Some other formulas include: TAN(x) = SIN(x)/COS(x) SEC(x)=1/COS(x) LOG(base a)(x) = LOG(x)/LOG(a) Any help would be most appreciated, thankyou. Edited June 23, 2021 by ac.tomo Quote Link to comment Share on other sites More sharing options...
ivop Posted June 23, 2021 Share Posted June 23, 2021 (edited) These are not assignments, but equations. It means that the left hand side is the same as the right hand side. Similar to how 2 = 1 + 1 tells us that two is equal to one plus one, tan(x) = sin(x) / cos(x) tells us that the tangent of x is equal to dividing the sinus of x by the cosinus of x. Edited June 23, 2021 by ivop Quote Link to comment Share on other sites More sharing options...
devwebcl Posted June 23, 2021 Share Posted June 23, 2021 You can see them as a function (or method/procedure), and COSH is the name and X the passing parameter. PROC ENDPROC from Turbo basic XL with global variables could be something similar. Quote Link to comment Share on other sites More sharing options...
thorfdbg Posted June 23, 2021 Share Posted June 23, 2021 2 hours ago, ac.tomo said: On the 8-bit Atari's there are very few subjects that I don't understand and for 2 reasons: 1. I never got round to it, and 2. They are quite often too complicated for me to understand. Algorythms is one (of which I will be looking into soon) and 1 of the others s math formula's This is fine, I understand COS and SIN, but what about other formulas such like: COSH(x) = (EXP(x)+EXP(-x))/2 - exactly how would I implement this in practice (in a program)? What does COSHH(x) do exactly? There is a lot of formulas (that I wrote) in the Compete & Essential MAP part II, page 235. I understand the syntax but dont have a clue as to implementing them into a BASIC program. Some other formulas include: TAN(x) = SIN(x)/COS(x) SEC(x)=1/COS(x) LOG(base a)(x) = LOG(x)/LOG(a) Any help would be most appreciated, thankyou. Formulae, or formulas. (no apostroph here). EXP(X) = E^X, where E=2.7181... Thus, cosh(X)=0.5*(E^X+E^-X). COSH(x) is the line a chain (or string) forms if supported on its two ends, just to name one popular example. Cosh is related to cos in the complex plane. (cosh(ix) = cos(x) where i is the complex unit, i.e. i^2=-1). I'm unclear where the problem of implementing tan is. It is actually written there. Y=SIN(X)/COS(X) computes the tangent of the argument. Ditto for the secant. As far as the log goes: This computes the logarithm to an arbitrary base. For example log_2(x) = LOG(X)/LOG(2). Concerning its use, y=log_2(x) is the unique number such that 2^y=x, i.e. b^(log_b(x))=x, or B^(LOG(X)/LOG(B))=X. Quote Link to comment Share on other sites More sharing options...
ivop Posted June 23, 2021 Share Posted June 23, 2021 17 minutes ago, thorfdbg said: I'm unclear where the problem of implementing tan is. I think the problem is ac.tomo thought it were assignments, like COSH(X) is an array index by X, and then assigned the result of an expression. Quote Link to comment Share on other sites More sharing options...
ac.tomo Posted June 24, 2021 Author Share Posted June 24, 2021 17 hours ago, ivop said: These are not assignments, but equations. It means that the left hand side is the same as the right hand side. Similar to how 2 = 1 + 1 tells us that two is equal to one plus one, tan(x) = sin(x) / cos(x) tells us that the tangent of x is equal to dividing the sinus of x by the cosinus of x. I understand this, but be it tan(x) or sin(x)/cos(x) I still can't make use of them like I do with cos and sin in my program. Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted June 24, 2021 Share Posted June 24, 2021 tan(x) is just another way to calculate an angle given certain parameters. e.g. say for example you have a triangle with side lengths 3(opposite),4(adjacent),5(hypotenuse) sin of an angle (between 4 and 5) is length of opposite side/hypotenuse cos of the same angle is adjacent side/hypotenuse tan of the same angle is opposite/adjacent So knowing only that you can calculate the angle, same can be done for other angles. Quote Link to comment Share on other sites More sharing options...
+Stephen Posted June 24, 2021 Share Posted June 24, 2021 1 hour ago, ac.tomo said: I understand this, but be it tan(x) or sin(x)/cos(x) I still can't make use of them like I do with cos and sin in my program. Sure you can: 10 DEG 20 X = 45 30 A = SIN(X) 40 B = COS(X) 50 C = A/B 60 D = SIN(X) / COS(X) Both C and D are equal to TAN(X). 1 Quote Link to comment Share on other sites More sharing options...
ivop Posted June 24, 2021 Share Posted June 24, 2021 (edited) 4 hours ago, ac.tomo said: I still can't make use of them like I do with cos and sin in my program. Or perhaps you mean that it doesn't result in nice images? Here's what the function looks like: (sourced and linked from britannica) Note how the values go to plus or minus infinity. 2*pi radians equals 360 degrees. pi/2 radians equals 90 degrees. Edited June 24, 2021 by ivop Quote Link to comment Share on other sites More sharing options...
ivop Posted June 24, 2021 Share Posted June 24, 2021 (edited) Stephen's code, X nearing 90 degrees: Note that when X equals 90 you'll get a divide by zero error. Edited June 24, 2021 by ivop 1 Quote Link to comment Share on other sites More sharing options...
+Stephen Posted June 24, 2021 Share Posted June 24, 2021 24 minutes ago, ivop said: Stephen's code, X nearing 90 degrees: Note that when X equals 90 you'll get a divide by zero error. Right - I didn't put any error checking in, just a quick example of how to use substitution rather than defining a function. I think maybe ac was wanting to do what you could in ? public float tan(float x) { if (x !=0) { return sin(x)/cos(x); } else { return 0; } } I don't think any BASIC variants on the 8-bit allow for user defined functions. As mentioned, TBXL can do PROCS, Quote Link to comment Share on other sites More sharing options...
ac.tomo Posted June 24, 2021 Author Share Posted June 24, 2021 1 hour ago, ivop said: Or perhaps you mean that it doesn't result in nice images? Here's what the function looks like: (sourced and linked from britannica) Note how the values go to plus or minus infinity. 2*pi radians equals 360 degrees. pi/2 radians equals 90 degrees. This is more what I'm looking for, take for example my 1st prog: 10 GRAPHICS 8:DEG:COLOR 1 20 FOR I=0 TO 359 30 X=COS(I)*SIZE+X_OFFSET 40 Y=SIN(I)*SIZE+Y_OFFSET 50 PLOT X,Y 60 NEXT I I know what will happen with this, a circle will be drawn, but what if I change line 30 to: 30 X=1/COS(I) - (which is affectively X=SEC(I)) - the secant (but I don't know what the secant is) I'm trying to create different poly shapes or patterns (other than a circle) with some of these equations (if that's what you call them) that I don't understand. Quote Link to comment Share on other sites More sharing options...
ivop Posted June 24, 2021 Share Posted June 24, 2021 The secant function is the reciprocal of the cosine, hence 1/cos. The secant line is a line that intersects another function/curve at at least two points. Quote Link to comment Share on other sites More sharing options...
thorfdbg Posted June 24, 2021 Share Posted June 24, 2021 1 hour ago, ivop said: The secant function is the reciprocal of the cosine, hence 1/cos. The secant line is a line that intersects another function/curve at at least two points. Well, but that's not related to the definition of these functions (or barely so). Draw a circle of unit radius. Add a line with an angle of alpha to the horizonal that goes through the middle of the circle. Draw a line parallel to the horizontal that is tangential to the circle. The length of the line segment between the touching point with the circle and the intersection of the radius with angle alpha is the secant of alpha. 1 Quote Link to comment Share on other sites More sharing options...
ivop Posted June 24, 2021 Share Posted June 24, 2021 (edited) Before getting too mathematical, here's an example that ac might like: It shows how to plot tan(x) by calculating sin(x)/cos(x), but only if cos(x) is non-zero. And it clips the Y value to being on screen. Edit: there's a small bug. IF (B=0) you should not plot a pixel (+/- infinity), hence the double pixel at the bottom, because it replots the previous pixel. Edited June 24, 2021 by ivop 1 Quote Link to comment Share on other sites More sharing options...
Irgendwer Posted June 24, 2021 Share Posted June 24, 2021 4 hours ago, ac.tomo said: I'm trying to create different poly shapes or patterns (other than a circle) with some of these equations (if that's what you call them) that I don't understand. You don't need to understand this: ...but still can have lots of fun while discovering several, astonishing shapes, by tweaking a,b,m,n1,n2 and n3: see Superformula 3 Quote Link to comment Share on other sites More sharing options...
ac.tomo Posted June 28, 2021 Author Share Posted June 28, 2021 On 6/24/2021 at 11:23 PM, Irgendwer said: You don't need to understand this: ...but still can have lots of fun while discovering several, astonishing shapes, by tweaking a,b,m,n1,n2 and n3: see Superformula This is just what I'm looking for, but how on earth would I implement that equation/formula in BASIC? I can do a bit of it, but thats about it. Quote Link to comment Share on other sites More sharing options...
ivop Posted June 28, 2021 Share Posted June 28, 2021 (edited) 1 hour ago, ac.tomo said: This is just what I'm looking for, but how on earth would I implement that equation/formula in BASIC? I can do a bit of it, but thats about it. That is about it First calculate mφ/4 (i.e. m times angle divided by four, your outer FOR loop will run through all angles). Then calculate both the cos and sin of the result. Calculate cos result divided by a, calculate sin result divided by b. Apply abs() on both. Raise the first term to the power of n2, the second term to the power of n3, and add both together. Then calculate -1/n1. Raise your previous result to the power of the just calculated -1/n1. There's your radius with parameters a,b,m,n1,n2 and n3, at angle φ (phi). Edited June 28, 2021 by ivop Quote Link to comment Share on other sites More sharing options...
ac.tomo Posted June 28, 2021 Author Share Posted June 28, 2021 40 minutes ago, ivop said: That is about it First calculate mφ/4 (i.e. m times angle divided by four, your outer FOR loop will run through all angles). Then calculate both the cos and sin of the result. Calculate cos result divided by a, calculate sin result divided by b. Apply abs() on both. Raise the first term to the power of n2, the second term to the power of n3, and add both together. Then calculate -1/n1. Raise your previous result to the power of the just calculated -1/n1. There's your radius with parameters a,b,m,n1,n2 and n3, at angle φ (phi). Ok, are you ready for a laugh! Here's what I think the formula converts to (in BASIC style): r(phi)=(ABS((COS(m*phi)/4)/a)~n2+ABS((SIN(m*phi)/4)/b))~-1/n1 Would that be about right? I assume the 'phi' in r(phi) is omitted when entered in BASIC? Quote Link to comment Share on other sites More sharing options...
ivop Posted June 28, 2021 Share Posted June 28, 2021 (edited) Your parenthesis are off. Now you take the cosine of m*phi, and then divide by 4, and divde by a. Similar to the sinus part. FOR phi loop full circle radius = ( ( ABS( COS(m*phi/4) / a ) ~n2) + ( ABS( SIN(m*phi/4) / b ) ~n3) ) ~ (-1/n1) edit: I used your notation for to-the-power-of n (~n). It should be ^ in Atari Basic. Edited June 28, 2021 by ivop Quote Link to comment Share on other sites More sharing options...
ac.tomo Posted June 28, 2021 Author Share Posted June 28, 2021 4 hours ago, ivop said: Your parenthesis are off. Now you take the cosine of m*phi, and then divide by 4, and divde by a. Similar to the sinus part. FOR phi loop full circle radius = ( ( ABS( COS(m*phi/4) / a ) ~n2) + ( ABS( SIN(m*phi/4) / b ) ~n3) ) ~ (-1/n1) edit: I used your notation for to-the-power-of n (~n). It should be ^ in Atari Basic. Many thanks for that, I think thats the 1st time I've ever done a conversion like that, I'm too busy tomorrow, but will be trying it out soon, thanks again. Quote Link to comment Share on other sites More sharing options...
ivop Posted June 28, 2021 Share Posted June 28, 2021 (edited) 45 minutes ago, ac.tomo said: Many thanks for that, I think thats the 1st time I've ever done a conversion like that, I'm too busy tomorrow, but will be trying it out soon, thanks again. It is possible in less than a screen full of Atari Basic. It is pretty slow though. I won't ruin your journey to finding out how it works by publishing the source. Just some images: Note that a and b are scale factors. Better keep them equal, and equal to one (1), and use the scale factor below to keep the points within the drawing area. Sadly, plot and drawto don't clip automatically. Polar coordinates (radius, angle) to cartesian (x,y) is done by: x = scale * calculated_radius * cos(angle) + centerpoint_x y = scale * calculated_radius * sin(angle) + centerpoint_y Have fun! Edited June 28, 2021 by ivop 3 Quote Link to comment Share on other sites More sharing options...
ac.tomo Posted July 2, 2021 Author Share Posted July 2, 2021 (edited) Many thanks for that ivop, 1 last question: How do you get the to-the-power symbol in Altirra? nb* no worries, I found it. Edited July 2, 2021 by ac.tomo 1 Quote Link to comment Share on other sites More sharing options...
ivop Posted July 2, 2021 Share Posted July 2, 2021 (edited) Yep, it's the circumflex (^). Note that when you keep a and b equal to 1, you can remove them from the equation. Dividing by 1 is useless, but Atari Basic will happily do it for you Use the scale factor to keep your plotted or drawn-to pixel within the visibile area. Final tip, at first use a step size in your outer loop and try a simple shape, like the square, triangle or circle. FOR PHI=0 to 359 STEP 4, and if it looks good, go down to 3, 2, or even 1. Edit: the numbers on the 2D plot on Wikipedia refer to m, n1, n2 and n3. 3,4.5,10,10 is the sort-of triangle, 2,2,2,2 is a circle, et cetera. Be prepared to change the scale factor each time you change shape. Basic will error out with Error Code 141: Cursor Out of Range My sample images used a STEP size of 2. Edited July 2, 2021 by ivop Quote Link to comment Share on other sites More sharing options...
ac.tomo Posted July 6, 2021 Author Share Posted July 6, 2021 On 7/2/2021 at 6:56 PM, ivop said: Yep, it's the circumflex (^). Note that when you keep a and b equal to 1, you can remove them from the equation. Dividing by 1 is useless, but Atari Basic will happily do it for you Use the scale factor to keep your plotted or drawn-to pixel within the visibile area. Final tip, at first use a step size in your outer loop and try a simple shape, like the square, triangle or circle. FOR PHI=0 to 359 STEP 4, and if it looks good, go down to 3, 2, or even 1. Edit: the numbers on the 2D plot on Wikipedia refer to m, n1, n2 and n3. 3,4.5,10,10 is the sort-of triangle, 2,2,2,2 is a circle, et cetera. Be prepared to change the scale factor each time you change shape. Basic will error out with Error Code 141: Cursor Out of Range My sample images used a STEP size of 2. Many thanks for that ivop. I think I'll be looking for more help from you when I decide to try to understand algorythms (mainly for) rotating 3d solid objects. I've got a couple of programs to rotate 3d wire graphics. This is another subject I don't understand but want to (the algorythms to do the filling). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.