trigonometry

Calculating degrees between 2 points with inverse Y axis

我的未来我决定 提交于 2019-12-02 18:33:56
I'm creating a simple 2D game in javascript/canvas. I need to figure out the angle of a certain object relative to my position. So: say I'm at (10,10) and the object is at (10,5) - that would result in 90 degrees (as positive Y is down, negative Y is up) (10,10) vs (10,15) would be 270 degrees. How would I go about this? Suppose you're at (a, b) and the object is at (c, d). Then the relative position of the object to you is (x, y) = (c - a, d - b). Then you could use the Math.atan2() function to get the angle in radians. var theta = Math.atan2(-y, x); note that the result is in the range [-π,

Scale rotated image to fill HTML5 Canvas using JavaScript trigonometry?

守給你的承諾、 提交于 2019-12-02 13:26:32
问题 Below is the code I am currently using. With 0 rotation, the image is correctly scaled to fill the canvas. (similar to background-size: cover , except using JavaScript on a Canvas) I'm trying to add a rotate feature, with the following features. Keep image centered while rotating. I tried using width / 2 in translate , and then the opposite in drawImage , but as you can see the image did not stay centered. I'm not sure if this is a conflict with my earlier x and y centering code, or if

Custom math functions vs. supplied Math functions?

半世苍凉 提交于 2019-12-02 10:15:54
I am basically making a Java program that will have to run a lot of calculations pretty quickly(each frame, aiming for at least 30 f/s). These will mostly be trigonometric and power functions. The question I'm asking is: Which is faster: using the already-supplied-by-Java Math functions? Or writing my own functions to run? The built-in Math functions will be extremely difficult to beat, given that most of them have special JVM magic that makes them use hardware intrinsics. You could conceivably beat some of them by trading away accuracy with a lot of work, but you're very unlikely to beat the

Determine rotation direction /toward/ variable point on a circle

℡╲_俬逩灬. 提交于 2019-12-02 08:27:35
Given circle centre: vectorA and another Vector on the circle's perimeter:vectorB, how can you determine the shorter route for vectorB to translate to another point on the circle's perimeter that is variable:vectorC? Will the shorter route be clockwise or counter clockwise rotation? If it helps think of a clock. If the times is a random point on the clock's perimeter eg. 6, and the minute hand position is known, eg. 4. Does the hand need to rotate around the clock's centre point clockwise or counter clockwise to reach the random point (6)? See also: Vec1 = Circle centre, Vec2 = mousepos, find

Scale rotated image to fill HTML5 Canvas using JavaScript trigonometry?

℡╲_俬逩灬. 提交于 2019-12-02 07:04:50
Below is the code I am currently using. With 0 rotation, the image is correctly scaled to fill the canvas. (similar to background-size: cover , except using JavaScript on a Canvas) I'm trying to add a rotate feature, with the following features. Keep image centered while rotating. I tried using width / 2 in translate , and then the opposite in drawImage , but as you can see the image did not stay centered. I'm not sure if this is a conflict with my earlier x and y centering code, or if trigonometry is required here? Automatically scale the image further to cover the canvas. These are arbitrary

Atan2 in C# (or similar lanaguge)

ぃ、小莉子 提交于 2019-12-02 06:22:01
问题 Can anyone point me to a good example of Atan2 defined in C# (or something vaguely close to C#) that doesn't use any internal math methods? This is on .NET Microframework, so there is no such thing as an internal math library. I have already defined Sin()/Cos(), but I am having a lot of trouble with Atain2. There are a few scatter shot math libraries in NETMF, but I have found them all to be flawed or broken. One of the major ones didn't even define PI correctly! 回答1: An implementation should

How to find out if the angle between two vectors is external or internal?

旧街凉风 提交于 2019-12-02 05:00:51
问题 I know how to find out angle between 2 vectors, but it always gives me internal angle, but I want it to give me always the angle in anticlockwise direction, even if it is greater then 180. I'm using C++ but it is not really important because I need to get the theory. This is what I am using now 回答1: You're looking for the atan2(y,x) function (http://en.wikipedia.org/wiki/Atan2). If you give it the two components of a 2D vector, it will give you the angle of the vector from the x axis, in the

c++ Sorting 2D Points clockwise

元气小坏坏 提交于 2019-12-02 04:28:55
问题 i wrote a program to arrange points on a graph in clockwise manner from 12 o'clock such that, a vector containing these points is sorted in that order. I am using atan2 to get the angle from 12 o'clock and then making adjustments based on the quadrant. i am trying to figure out where the bug is coming from as it is not ordering them correctly. So given 4 random points like those in the photo, it should order then in the containing vector as P1,P2,P3,P4 Here is my code: //sort_points.cpp

Finding Third Points of triangle using other two points with known distances [closed]

狂风中的少年 提交于 2019-12-02 04:20:37
问题 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 2 years ago . In the above image, I have three points (x1,y1) (x2,y2) (x3,y3) . I know the values of x1,y1 and x2,y2 .I know the euclidean distances of (x1,y1)->(x3,y3) and (x2,y2)->(x3,y3) . Having these information how can I find the (x3,y3) ? I expect anything like a code snippet or the logic will be useful... I have tried

Calculating the coordinates of the third point of a triangle

≯℡__Kan透↙ 提交于 2019-12-02 03:24:08
问题 OK, I know this sounds like it should be asked on math.stackoverflow.com, but this is embarrassingly simple maths that I've forgotten from high-school, rather than advanced post-graduate stuff! I'm doing some graphics programming, and I have a triangle. Incidentally, two of this triangle's sides are equal, but I'm not sure if that's relevant. I have the coordinates of two of the corners (vertices), but not the third (these coordinates are pixels on the screen, in case that's relevant). I know