trigonometry

Draw Cosx with specific period width

天大地大妈咪最大 提交于 2019-12-25 01:14:57
问题 how can i draw a period of Cosx with width =100 and height 50? my recent code is very hard to control them :( // this to find y with each x to draw Cos for (int i = 0, j = 0; i < 50; i += 1, j++) { int y = (int)((Math.Cos((double)i * height/10F * Math.PI / cy) + 1.0) * (cx - 1) / widtd/10F); poi.SetValue(new Point(i, y),j); // poi is an aray of point } 回答1: Based on OP's last comment I assume "width" means a single period. Therefore to calculate the points of a cosine function with amplitude

Drawing Sin and Cosine graphs in Javafx

…衆ロ難τιáo~ 提交于 2019-12-24 21:55:57
问题 I need to draw a Sine wave and a Cosine wave separately, which I will then use as class objects for a larger program. (these lines are just for plotting a path) The problem I am running into is simply that - while I know how to draw basic shapes like a circle, an arc, or a polygon - I don't know how to arrange these into a graph. I tried looking up tutorials and examples, but the only javafx examples I can find use depreciated features or don't use javafx at all. I thought about just drawing

How do I offset a sector of circle from its origin based on the current angle

守給你的承諾、 提交于 2019-12-24 20:34:15
问题 I'm trying to work out how to create a new vector position or destination vector position to represent an extracted section of a circle (or piece of pie) given the current angle. Specifically I need to work out the total float value needed to reach the destination vector from the current vector by incrementing x and y per frame for my animation - (this part is already done just some background info). I have already determined the following bits of information in my program...here's a sample:

How to get x, y distance from a circle

大憨熊 提交于 2019-12-24 19:33:54
问题 I've drawn a square shape whose width & length 20x, or 20y then I have drawn a circle inside the square whose radius 10x. Now a ray from the center of the circle went through the boundary of the circle at 45-degree angle (it can be 38 degrees or anything). Now how can i get x & y distance of connection ground of ray & circle from the square shape? I've tried this code: var radius = 10 //radius, x = Math.cos(Math.PI * 45 / 180) * radius y = Math.sin(Math.PI * 45 / 180) * radius I'm not getting

Robotics Square Grid Intersection Point

谁说胖子不能爱 提交于 2019-12-24 16:42:39
问题 I'm trying to determine the point at which my robot will intersect with a wall given its location in a map and an angle its pointing at in radians. So to sum the problem up, given a square grid of any size [1-infinity], a object within that grid, and the angle at which that object is facing (radians), find the point of intersection with the border of the grid. For instance you have a 10 x 10 grid, your object is at position (5,5), and it is facing at an angle of pi/8 radians (Northeast

Slowly change one angle to another

余生颓废 提交于 2019-12-24 14:19:02
问题 Skip to JSFiddle I'm creating one of these fun scripts that interact with mouse. I decided I want an object to folow mouse slowly. I made such object, that has these properties: speed - current speed of the object speed change ratio - derivative of the speed function: "How's the speed changing now?" direction - radian angle upon which the object is moving direction change - same as for speed, this is used to change the direction Change ratios are randomly generated and added to speed and

Approximation of arcsin in C

寵の児 提交于 2019-12-24 12:12:08
问题 I've got a program that calculates the approximation of an arcsin value based on Taylor's series. My friend and I have come up with an algorithm which has been able to return the almost "right" values, but I don't think we've done it very crisply. Take a look: double my_asin(double x) { double a = 0; int i = 0; double sum = 0; a = x; for(i = 1; i < 23500; i++) { sum += a; a = next(a, x, i); } } double next(double a, double x, int i) { return a*((my_pow(2*i-1, 2)) / ((2*i)*(2*i+1)*my_pow(x, 2)

Find corners of a rotated rectangle given its center point and rotation

百般思念 提交于 2019-12-24 10:57:34
问题 Can someone give me an algorithm that finds the position of all four corners of a rectangle if I know its center point(in global coordinate space), width and height, and its rotation around that center point? clarification edit: The width and height I am referring to is the length of the sides of the rectangle. 回答1: Top right corner has coordinates w/2, h/2 relative to the center. After rotation its absolute coordinates are x = cx + w/2 * Cos(Phi) - h/2 * Sin(Phi) y = cy + w/2 * Sin(Phi) + h

Arduino I2S sine wave

对着背影说爱祢 提交于 2019-12-24 08:24:03
问题 I'm working on a project where I want to generate (simple) sound by combining different sine waves. I'm using an arduino mkrZero, as it has I2S interface built in and it seems to have enough processing power for what I want. I have wired my system exactly like in the tutorial for arduino I2S simpleTone: And the tutorial code works just fine, and I get a simple square wave tone from the speaker. Now I have modified the code to generate sine wave, there is a lookup table for the sin function to

Python sin and cosine giving incorrect values

人走茶凉 提交于 2019-12-24 07:38:16
问题 I have code that draws a line from 2 points; One on the middle bottom of the screen, and the other to the mouse pointer. I am trying to constrain the point by not exceeding a length parameter that I set. Heres the code: import pygame import Resources as r import math as m pygame.init() class Segment(): def __init__(self, _screen, _id, _start_pos, _length): self.screen = _screen self.id = _id self.start_pos = _start_pos self.length = _length def update(self): if self.id == 1: mouse_pos =