trigonometry

Number of Sides Required to draw a circle in OpenGL

馋奶兔 提交于 2019-12-06 08:14:10
Does anyone know some algorithm to calculate the number of sides required to approximate a circle using polygon, if radius, r of the circle and maximum departure of the polygon from circularity, D is given? I really need to find the number of sides as I need to draw the approximated circle in OpenGL. Also, we have the resolution of the screen in NDC coordinates per pixel given by P and solving D = P/2, we could guarantee that our circle is within half-pixel of accuracy. What you're describing here is effectively a quality factor, which often goes hand-in-hand with error estimates. A common way

How to move point along circle?

耗尽温柔 提交于 2019-12-06 07:19:31
I want to move a sprite in a circular motion by using a circle radius and movingangle. I know for instance that the sprite is moving in a circle with the radius 10 and It's current position is (387,38) and angle is 28 degrees. Now I wann't move it say, 100px along the circle perimeter. p1 = x&y coordinate, known (387,38) in example with movingangle 28 degrees r = radius, known (10 in example) l = distance to move along bend, known (100px in example) p2 = new point, what is this x and y value? I have a solution that works but I dont quite like it. It kind of don't make sense to me and it

Calculate point and circle segment collision

拟墨画扇 提交于 2019-12-06 06:16:43
If I have calculated an intersection point between a line segment and a circle, how can I tell whether or not this intersection point lies on a segment of the circle? I have the equations to tell whether or not a line segment intersects with the circle, and I also have the intersection point on that circle, but what I need to know is whether or not this collision point on the circle lies within the bounds of a specific arg segment of that circle. I have the end points of the arc segment, the circle's center & radius, and the point of collision. Transform the intersection point into polar

ThreeJS oribital camera short rotation

喜夏-厌秋 提交于 2019-12-06 06:07:51
I have an orbital camera that orbits are a globe. There are several markers on the globe that the user can click on, and the camera will move to that point. Using TweenMax for the animation like this - TweenMax.to(currentPos, 3, { theta:targetPos.theta, phi:targetPos.phi, radius:targetPos.radius, ease:Circ.easeIn, onComplete:btnZoomComplete, onUpdateParams:["{self}"], onComplete:SataliteTweenComplete, onUpdate: function(tween) { controls.setThetaPhi(tween.target.theta, tween.target.phi, tween.target.radius); } }); This works great, however is doesn't take into consideration the shortest route

Finding point on sphere

元气小坏坏 提交于 2019-12-06 04:23:19
问题 So I need to find the point on a sphere's surface using the radius, the center of the circle and the rotation vector. I have this equation right now: x = position.x + radius * Math.cos(rotation.x) * Math.sin(rotation.y) y = position.y + radius * Math.sin(rotation.x) * Math.sin(rotation.y) z = position.z + radius * Math.sin(rotation.y) This formula produces crazy results that are totally not what I need at all. I quite honestly have no idea what I've done wrong, I tried to use the formula I

Calculate 3D point coordinates using horizontal and vertical angles and slope distance

吃可爱长大的小学妹 提交于 2019-12-06 03:05:52
I am trying to learn how to calculate the XYZ coordinates of a point using the XYZ coordinates of an origin point, a horizontal and vertical angle, and 3d distance. I can make the calculations simply by projecting the points onto 2D planes, but is there a more straightforward way to do this in 3D? I am trying to understand how a surveying total station calculates new point locations based on it's measured location, the 3d (slope) distance that it measures to a new point, and the measured horizontal and vertical angles that sight onto the new point location. Thanks, E Brett Hale Just a note on

Trigonometric identities

ぐ巨炮叔叔 提交于 2019-12-06 02:09:23
问题 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)? 回答1: The sympy.simplify

JavaScript sine wave

时间秒杀一切 提交于 2019-12-05 21:36:53
track : function(x, y, top, ampl) { return { top : top + 2, x : x + ampl * Math.sin(top / 20), y : (top / this.screenHeight < 0.65) ? y + 2 : 1 + y + ampl * Math.cos(top / 25) }; } This routine sends snowflakes flying in sine wave manner. But how does it do that? Please explain. It uses Math.sin for x ; and Math.cos for y , but other snippets I've seen use them in the opposite way. Why? Why exactly top/20 and top/25 ? The whole code: <script type="text/javascript"> var snowflakes = { // Namespace /* Settings */ pics : [ ['snow.gif' , 24, 24], ['snow2.gif', 24, 24], ['snow3.gif', 24, 24] ],

Calculating cosine values for an array in Python

风流意气都作罢 提交于 2019-12-05 18:33:08
I have this array named a of 1242 numbers. I need to get the cosine value for all the numbers in Python. When I use : cos_ra = math.cos(a) I get an error stating: TypeError: only length-1 arrays can be converted to Python scalars How can I solve this problem?? Thanks in advance Problem is you're using numpy.math.cos here, which expects you to pass a scalar. Use numpy.cos if you want to apply cos to an iterable. In [30]: import numpy as np In [31]: np.cos(np.array([1, 2, 3])) Out[31]: array([ 0.54030231, -0.41614684, -0.9899925 ]) Error: In [32]: np.math.cos(np.array([1, 2, 3])) ---------------

Fast sine and cosine function in java

折月煮酒 提交于 2019-12-05 17:18:45
I know about the Math.sin() and Math.cos() functions, but I'm wondering if there's a way I can create (or use an already-existing) a faster function, given that I don't care about pinpoint accuracy. I'm looking to execute a basic sin or cos calculation, and have it perform essentially as fast as possible. Would simply iterating the sigma a few times be any faster than Math.sin() ? Since you don't care much about accuracy store it in a table that is precomputed or only computed once, this is what I do when I want to avoid calls to Math which can be expensive when done alot. Roughly public class