math

Move a point toward the mouse

ぃ、小莉子 提交于 2021-01-28 06:11:16
问题 (I'm using processing for this but it is not necessarily relevant.) I'm looking for an algorithm that would take the point A and the point B (B being the mouse cursor position) and use them so that every frame the point A moves a little bit towards B (from -1px to 1px left/right up/down) I tried x1 += cos(atan((mouseY-y1)/(mouseX-x1))) and the same with sin for y1, but I doesn't seem to work. If someone has an idea I would appreciate it. I'm not looking for a built-in function that would do

Math.pow with Command line arguments

拥有回忆 提交于 2021-01-28 05:58:56
问题 I need to get the power value of a given number by user (as a command line argument) This is my code and it has comes up with a compilation error. Can anyone please help me ? class SquareRoot{ public static void main(String args []){ double power = Math.pow(args[0]); System.out.println("Your squared value is " + power); } } 回答1: This is because Math.pow needs two arguments. Something like: double power = Math.pow(Double.parseDouble(args[0]),2.0); See the javadoc. 回答2: Math.pow takes in two

update coordinates based on angle and speed

≯℡__Kan透↙ 提交于 2021-01-28 02:03:13
问题 I see plenty of answers to this riddle on here, but every time I try and implement the answers, they don't seem to work. I wanted to reply to some of the answers, but couldn't. Perhaps it's because of my 'reputation' level? Anyway, it's a simple coordinates problem for a game. Simple for most, but not for me. (suck at math.. hardcore) I've got a spaceship in the middle of the screen. It does not move apart from rotation (user.fAngle). It does have velocity (user.dVelocity) that is used purely

Subset sum algorithm with multiple attributes

懵懂的女人 提交于 2021-01-27 21:20:42
问题 I have what I believe is a subset sum problem that I could use some help with. I have N sets with an X amount of objects in them. Each object has 5 integer attributes a,b,c,d and e. Now I would like to find 1 or more (probably not all because X can become rather large) combinations of objects where the sum of all a's approximates a variable A (so e.g. approximates 100 I would say 110 > sum(a) > 90), the sum of all b's approximates variable B, etc. I could use some pointers on where to start

Exponential Moving Average in php

喜你入骨 提交于 2021-01-27 18:54:10
问题 I want to calculate the EMA (Exponential Moving Average) value in PHP. I've tried with following code but it's giving me 500 error. $real = array(12,15,17,19,21,25,28,12,15,16); $timePeriod = 3; $data = trader_ema($real,$timePeriod); var_dump($data); PHP: EMA calculation function trader-ema Tried with long time Googling but not getting any help on this in PHP. So, I've no clue what needs to be done to calculate the EMA value. Edit-1: Installed extensions I've installed all the necessary

how to make particles follow my mouse in pygame

≡放荡痞女 提交于 2021-01-27 18:10:30
问题 I'm trying to make sure that the particles that arise when I click my mouse follow my mouse. For some reason, the particles just follow me to the top left. Can anyone tell me what I am doing wrong? Here is my code: import pygame import sys import random import math from pygame.locals import * pygame.init() clock = pygame.time.Clock() screen = pygame.display.set_mode((500,500)) particles = [] while True: screen.fill((0,0,0)) for event in pygame.event.get(): if event.type == MOUSEBUTTONDOWN: mx

How do you transform Adjacency matrices to Incidence matrices and vice-versa?

与世无争的帅哥 提交于 2021-01-27 18:00:32
问题 Let's say the matrices are the following: (N = 4) Adjacency: 0110 1001 1001 0110 Incidence: 1100 1010 0101 0011 How can you get the Incidence matrix from having just the Adjacency one, and vice-versa? P.S: The Adjacency Matrix I'm getting from a .txt document, which I've read into an array and got it by the following algorithm: int read(){ ifstream graf("graf.txt"); if(graf.is_open()){ graf >> n; for (int i=0; i < n; i++) { for(int j = 0; j<2; j++) graf >> Graf[i][j]; } } graf.close(); return

Javascript function to find third point of triangle when all sides, angles and first two points are known

霸气de小男生 提交于 2021-01-27 17:46:14
问题 This has been asked before however I've found no satisfactory answers so I'm going to try and makes sure this is on topic and generates some good responses. This question should not be on maths.stackexchange because it's about the Javascript code required to complete the function I started below. Imagine the following triangle. Each point A, B and C have x and y coordinates and we know what these coordinates are for Ax, Ay, Cx and Cy. We also know the length of a, b and c and the angle of A,

Insert space after every one or two characters in string

时光毁灭记忆、已成空白 提交于 2021-01-27 17:24:49
问题 I need to write code to correct user input. The input is a mathematical expression in infix form. In order for my calculations to be correct, i need each operand spaced away from the operator. Can you please help me write a method that will provide the following expected results. Expected input: 13*21-5+33 Expected Output: 13 * 21 - 5 + 33 Research I have done: I could only find out how to add spaces between every character in the string and that will not work for calculating expressions with

Insert space after every one or two characters in string

余生长醉 提交于 2021-01-27 17:15:12
问题 I need to write code to correct user input. The input is a mathematical expression in infix form. In order for my calculations to be correct, i need each operand spaced away from the operator. Can you please help me write a method that will provide the following expected results. Expected input: 13*21-5+33 Expected Output: 13 * 21 - 5 + 33 Research I have done: I could only find out how to add spaces between every character in the string and that will not work for calculating expressions with