trigonometry

Math.cos, sin and tan returning inaccurate values in Java

99封情书 提交于 2019-12-31 05:12:10
问题 I am working on a calculator with a GUI in Java. The project is done, however the trigonometric functions do not work properly. This is the method for the cos function: public void actionPerformed(ActionEvent evt) { input = Double.valueOf(Display.getText()); ans = Math.cos(Math.toRadians(input)); Display.setText(String.valueOf(ans)); } Where "Display" is the text area. The problem is that the functions return inaccurate values. For example, when I enter 90 and click the cos button, the number

Coordinate trigonometry - calculate midpoint in arc for flightpath

こ雲淡風輕ζ 提交于 2019-12-30 07:50:11
问题 I am trying to draw flightpaths on a map using SVGs. I'm using d3 on top of Leaflet, but the frameworks used shouldn't make a difference to my problem - it's trig. http://fiddle.jshell.net/zw8TR/26 The way I'm trying to do this is by creating a quadratic bezier curve (I'm open to other/easier ways if you know of any). What I need to calculate is 1 control point, perpendicular to the midpoint of each line. This point should always bias to a higher y value / latitude than the midpoint, to

Python: Calculate sine/cosine with a precision of up to 1 million digits

旧城冷巷雨未停 提交于 2019-12-29 07:58:28
问题 Question is pretty self-explanatory. I've seen a couple of examples for pi but not for trigo functions. Maybe one could use a Taylor series as done here but I'm not entirely sure how to implement that in python. Especially how to store so many digits. I should mention: this ideally would run on vanilla python i.e. no numpy etc. Thanks! Edit: as said, I know the question has been asked before but it's in java and I was looking for a python implementation :) Edit 2: wow I wasn't aware people

HTML5 Canvas: Calculating a x,y point when rotated

安稳与你 提交于 2019-12-29 03:40:06
问题 I developing a HTML5 Canvas App and it involves reading a xml file that describes the position of arrows, rectanges and other shapes I need to to draw on the canvas. Example of the XML layout: <arrow left="10" top="20" width="100" height="200" rotation="-40" background-color="red"/> <rect left="10" top="20" width="100" height="200" rotation="300" background-color="red"/> If the object is rotated it involves calculating the position of a point(called P the new position of the object after

How do I fit a sine curve to my data with pylab and numpy?

亡梦爱人 提交于 2019-12-27 19:14:45
问题 For a school project I am trying to show that economies follow a relatively sinusoidal growth pattern. Beyond the economics of it, which are admittedly dodgy, I am building a python simulation to show that even when we let some degree of randomness take hold, we can still produce something relatively sinusoidal. I am happy with my data that I'm producing but now Id like to find some way to get a sine graph that pretty closely matches the data. I know you can do polynomial fit, but can you do

How do I fit a sine curve to my data with pylab and numpy?

為{幸葍}努か 提交于 2019-12-27 19:13:51
问题 For a school project I am trying to show that economies follow a relatively sinusoidal growth pattern. Beyond the economics of it, which are admittedly dodgy, I am building a python simulation to show that even when we let some degree of randomness take hold, we can still produce something relatively sinusoidal. I am happy with my data that I'm producing but now Id like to find some way to get a sine graph that pretty closely matches the data. I know you can do polynomial fit, but can you do

Changing the direction of a ball on collision base on speed

给你一囗甜甜゛ 提交于 2019-12-25 06:19:20
问题 I am creating a ping pong game. And I want to create the ability to control the direction of the ball based on the impact on the paddle. If the ball is coming down at vy = 4; vx = 4; and the paddle is moving to the left at vx = -5; I want the ball to slightly change its course depending on how fast the paddle is moving. It would probably reduce the balls vx speed on collision, therefore making the ball move more straight (close to the Y axis) when it is moving back up. But before I go on a

Basic trigonometry isn't working correctly in python

落爺英雄遲暮 提交于 2019-12-25 05:48:06
问题 For a bit of background, this is the game I'm trying to draw in an isometric style. I'm just trying to get the correct calculations instead of doing it in a hacky way, but one part isn't working, and I'm not quite sure about the other part (I'll save that for another question later on). So, forgetting the little squares inbetween, the board is made up of n lenels. I'd like to be able to calculate the coordinates for these so I can do further calculations on them, but the trig isn't working,

3d coordinate from point and angles

丶灬走出姿态 提交于 2019-12-25 03:56:31
问题 I'm working on a simple OpenGL world- and so far I've got a bunch of cubes randomly placed about and it's pretty fun to go zooming about. However I'm ready to move on. I would like to drop blocks in front of my camera, but I'm having trouble with the 3d angles. I'm used to 2d stuff where to find an end point we simply do something along the lines of: endy = y + (sin(theta)*power); endx = x + (cos(theta)*power); However when I add the third dimension I'm not sure what to do! It seems to me

Find x and y coordinates where a perpendicular point crosses a straight line [closed]

不打扰是莪最后的温柔 提交于 2019-12-25 01:25:33
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 9 months ago . This is a follow-up question to this question. Taking the following image as an example: What I know: x and y coordinates of points D , E , and P . Therefore, I also know slope and intercept of D-E line What I want to know: x and y coordinates of point Q . (This is the point which crosses the D-E line). 回答1: