trigonometry

How to calculate the angle of a vector from the vertical?

Hey, Im trying to find out the angle (in degrees) between two 2D vectors. I know I need to use trig but I'm not too good with it. This is what I'm trying to work out (the Y axis increases downward): I'm trying to use this code at the moment, but it's not working at all (calculates random angles for some reason): private float calcAng...

Angle between 3 points?

Given points ABC, how could I find angle ABC? I'm making a feehand tool for a vector drawing application and to minimize the number of points it generates, I wont add a points unless the angle of the mouse position and the last 2 points is greater than a certain threshold. Thanks what I had: int CGlEngineFunctions::GetAngleABC( POINTFL...

Why is cosine used to calculate the x values and sine the y values for an arc?

I'm trying to understand the math on this raphael.js demo: http://raphaeljs.com/pie.js Checkout the sector method: function sector(cx, cy, r, startAngle, endAngle, params) { var x1 = cx + r * Math.cos(-startAngle * rad), x2 = cx + r * Math.cos(-endAngle * rad), y1 = cy + r * Math.sin(-startAngle * rad), y2 ...

Draw a line at a specific angle in Java

I feel stupid for asking this question (my trig is rusty), but I'm having a tough time. Lets say I have an (x,y) that is always the same for the start point of a line and an (x,y) that changes for the end point of that same line. The line is also always 40px long. At the start of the program the line originates in a vertical orientati...

Find the coordinates in an isosceles triangle

Given: (x1,y1) = (0,0) (x2,y2) = (0,-10) Using the angle to C, how are the coordinates at C calculated? ...

Rotate a circle around another circle

Short question: Given a point P and a line segment L, how do I find the point (or points) on L that are exactly X distance from P, if it guaranteed that there is such a point? The longer way to ask this question is with an image. Given two circles, one static and one dynamic, if you move the dynamic one towards the static one in a str...

Image distortion with sine/cosine

Is it possible to distort an image using trigonometric functions like sine and cosine so that it comes out wavy. If so, how. PHP is the preferred language but it can be any... ...

Determine whether two sectors of a given circle intersect?

Anybody know how to determine whether two sectors of the same circle intersect? Let's say I have a sector A, expressed by starting and ending angles A1 and A2, and a sector B, expressed by starting angle B1 and ending angle B2. All angles ranges from 0..2*PI radians (or 0..360 degrees). How to determine whether angle A intersects wit...

Frame by frame animation using an NSTimer following a circular path

Hi, I'm using an NSTimer to animate an array of objects across the screen. Currently they move from left to right. However, I would like them to move in a circular fashion instead. How can I do this? scrollItems = [NSTimer scheduledTimerWithTimeInterval:1.0/30.0 target:self ...

Image rotation & tracking locations

I am rotating an image around it center point but need to track a location on the image as it rotates. Given: Origin at 0,0 Image width and height of 100, 100 Rotation point at C(50,50) Angle of "a" (say 90 degrees in this example) Point P starts at (25,25) and after the rotation it is at Pnew(75,25) I haven't touched trig in 20 y...

AS3 / Java - find point of triangle by knowing other two points and segment lengths

Sorry if this doesn't make sense... I know the length of the triangle segments and the xy coordinates of two points. How do I figure out the xy of the 3rd point? ...

How to handle ball to ball collision with trigonometry instead of vectors?

I am making a simplified version of the ball physics app found at this SO question. I gained a lot from reading through the code and links provided at that question, but in my program I do not use vectors, I just update the coordinates of my balls (each of which has a random angle and speed) with trigonometry functions when they hit the...

Making Asteroids Game In C#

So I am currently trying to make the game Asteroids for a class. The problem is, I haven't done any coding for about 3/4ths of a year since the last time I had the class and forgot almost everything I learned. I need to move the ship using thrust/acceleration but also cap it, and have friction so that when the thrust stops, the ship slow...

Drawing lat/lng points on an image

I have the following: An image - a hand drawn map - of an area of roughly 600x400 meters. The image is drawn on top of Google Maps tiles. The latitude/longitude (from Google Maps) of the corners of this image. Or put differently, I have the north and south latitude and the east and west longitude of the image. A latitude/longitude coor...

Computing an angle from x,y coordinates

I'm trying to do collision testing between a finite line segment, and an arc segment. I have a collision test which does line segment vs. line segment, so I was going to approximate these arc segments with line segments and run my existing test. The data I have defining the arc segment(s) are three points. Two of which are endpoints th...

Calculate point and circle segment collision

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 w...

benchmarking trig lookup tables performance gains vs cpp implementation

We are developing a real-time system that will be performing sin/cos calculations during a time critical period of operation. We're considering using a lookup table to help with performance, and I'm trying to benchmark the benefit/cost of implementing a table. Unfortunately we don't yet know what degree of accuracy we will need, but pro...

How can I reproduce a scribbly pattern like this in code?

I made this graph in wolfram alpha by accident: Can you write code to produce a larger version of this pattern? Can you make similar looking patterns? Readable code in any language is good, but something that can be run in a browser would be best (i.e. JavaScript / Canvas). If you write code in other languages, please include a scr...

Stable Cotangent

Hello, Is there a more stable implementation for the cotangent function than return 1.0/tan(x);? ...

Calculate 3D rotation of a point

How do I calculate the pitch, yaw, and roll angles for a point in 3D space? I'm working on a game where the player character must face towards an object that's flying around. ...