trigonometry

Trigonometric identities

删除回忆录丶 提交于 2019-12-04 06:09:18
I have an expression which has both sines and cosines and would like to write it using only sines (or cosines), possibly using the power-reduction formula . I tried to use SymPy but I cannot make it to "rewrite" to the desired output: angle = symbols('angle') print (sin(angle)**2).rewrite(sin, cos) # (1 - cos(2*angle))/2 print ((1 - cos(2*angle))/2).rewrite(cos, sin) # sin(angle)**2 Is there any way to tell Sympy to rewrite such expression using only sines (or cosines)? unutbu The sympy.simplify.fu module defines a number of transformations based on trig identities: TR0 - simplify expression

Trig functions and square root in native batch?

点点圈 提交于 2019-12-04 05:37:27
问题 I am making a tool where the user is shown this triangle throughout the process: :draw echo ^|\ echo ^|a\ echo ^| \ echo ^| \ echo ^| \ C echo A^| \ echo ^| \ echo ^| \ echo ^|c b\ echo ^|---------\ echo B GOTO:EOF Where any letters are, there are variables. First the users chooses which angle value they have. Then they choose a side value. After that, all of the values will automatically be filled in. In my source code I just have sin(a) or something similar as a placeholder until I can find

Using Sin-1 or inverse sin in python

霸气de小男生 提交于 2019-12-04 04:47:55
问题 Here is my code: # point of intersection between opposite and hypotenuse x,y = pygame.mouse.get_pos() # using formula for length of line lenline1 = (x-x)**2 + (300-y)**2 lenline2 = (x-700)**2 + (y-300)**2 opposite = math.sqrt(lenline1) adjacent = math.sqrt(lenline2) # Converting length of lines to angle PQ = opposite/adjacent k = math.sin(PQ) j = math.asin(k) print(j) I'm not getting the results I expected, although after messing around with it I got close but it wasn't quite right. Could

Inconsistency with Math.Round()

我只是一个虾纸丫 提交于 2019-12-04 04:44:03
问题 I have two functions that are intended to contain angles between (-180,180] and (-π,π]. The intent is that given any angle from -inf to +inf it will retain the equivalent angle in the intervals specified. For example the angle for 1550° is 110°. public double WrapBetween180(double angle) { return angle - 360d * Math.Round(angle / 360d, MidpointRounding.AwayFromZero); } public double WrapBetweenPI(double angle) { const double twopi = 2d * Math.PI; return angle - twopi * Math.Round(angle /

Calculate center of SVG arc

删除回忆录丶 提交于 2019-12-04 03:40:18
I have the following information: radiusX (rx) radiusY (ry) x1 y1 x2 y2 The SVG spec allows you to define an arc by specifying its radius, and start and end points. There are other options such as large-arc-flag and sweep-flag which help to define how you want the start-point to reach the end-point. More details here . I am not mathematically inclined, so understanding all of this is near impossible. I guess I am looking for a simple equation that results in me knowing the centerX and centerY values given all the arguments accepted by SVG's arc command. Any help is appreciated. I've search

How can i make the php cos function return the correct value?

僤鯓⒐⒋嵵緔 提交于 2019-12-04 03:28:47
问题 I've tried $x = cos(deg2rad($angle)); but it returns 6.12323399574E-17 when the angle is 90 degrees instead of 0. I read that this is a floating point problem, but is there a workaround? 回答1: 6.1E-17 is almost zero anyway[*]. If you need to actually compare the result to zero, in floating point math you should check that it's within a certain tolerance of the desired value, since most numbers can't be represented correctly. $x = cos(deg2rad($angle)); $is_zero = (abs($x) < 1e-10); Strictly

C: Improving performance of function with heavy sin() usage

﹥>﹥吖頭↗ 提交于 2019-12-04 02:47:00
I have a C function that computes the values of 4 sines based on time elapsed. Using gprof, I figured that this function uses 100% (100.7% to be exact lol) of the CPU time. void update_sines(void) { clock_gettime(CLOCK_MONOTONIC, &spec); s = spec.tv_sec; ms = spec.tv_nsec * 0.0000001; etime = concatenate((long)s, ms); int k; for (k = 0; k < 799; ++k) { double A1 = 145 * sin((RAND1 * k + etime) * 0.00333) + RAND5; // Amplitude double A2 = 100 * sin((RAND2 * k + etime) * 0.00333) + RAND4; // Amplitude double A3 = 168 * sin((RAND3 * k + etime) * 0.00333) + RAND3; // Amplitude double A4 = 136 *

Getting angle back from a sin/cos conversion

非 Y 不嫁゛ 提交于 2019-12-04 00:22:52
I want to reverse a sin / cos operation to get back an angle, but I can't figure out what I should be doing. I have used sin and cos on an angle in radians to get the x/y vector as such: double angle = 90.0 * M_PI / 180.0; // 90 deg. to rad. double s_x = cos( angle ); double s_y = sin( angle ); Given s_x and s_y , is it possible to get back the angle? I thought atan2 was the function to use, but I'm not getting the expected results. atan2(s_y, s_x) should give you the correct angle. Maybe you have reversed the order of s_x and s_y . Also, you can use the acos and asin functions directly on s_x

LLVM insert intrinsic function Cos

徘徊边缘 提交于 2019-12-03 21:19:55
问题 I am trying to insert intrinsic cos() function call to LLVM pass. My code in a FunctionPass: std::vector<Type *> arg_type; arg_type.push_back(Type::getFloatTy(getGlobalContext())); Function *fun = Intrinsic::getDeclaration(F.getParent(), Intrinsic::cos, arg_type); CallInst* callInst = CallInst::Create(fun, args, Twine("cos"), (Instruction *)&I); When I leave out last line generated IR is: define i32 @main() nounwind uwtable { entry: ... } declare float @llvm.cos.f32(float) nounwind readonly ,

Find the rotation angles of a triangle in 3D, given the coordinates of its vertices

我们两清 提交于 2019-12-03 21:11:59
I try to rotate and translate an equilateral triangle in 3D until his vertices reach some coordinates. The vertices coordinates F,G,H and F',G',H' are known : I was able to find the new centroid c' coordinates like this : c'.x = ( F'.x + G'.x + H'.x ) / 3 c'.y = ( F'.y + G'.y + H'.y ) / 3 c'.z = ( F'.z + G'.z + H'.z ) / 3 So no problem to translate the triangle. But I can't find a way to calculate the rotations needed to put F'G'H' triangle in the right position... I have to know by how much the triangle F'G'H' has to be rotated in degrees, around each axis (x,y,z), knowing that the rotations