trigonometry

Best way to approach using sincos() in CUDA

别来无恙 提交于 2020-01-06 15:20:50
问题 I am not clear on what should be the best way to implement sincos(). I've looked up everywhere but it seems the consensus is simply that it is better than doing separate computation of sin and cos. Below is essentially what I have in my kernel for using sincos. However, when I clock it against just doing sin and cos separately it comes out slower. I think it has to do with how I'm using my cPtr and sPtr. Is there a better way? int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx <

Draw reversed circle arc changes circle center coordinates

你离开我真会死。 提交于 2020-01-06 09:04:24
问题 I'm using this piece of code to draw arcs and so far it's been great, however I've encountered an issue with textPath that I cannot figure out. Please run the following snippet. function polarToCartesian(centerX, centerY, radius, angleInDegrees) { var angleInRadians = (angleInDegrees-90) * Math.PI / 180.0; return { x: centerX + (radius * Math.cos(angleInRadians)), y: centerY + (radius * Math.sin(angleInRadians)) }; } function describeArc(x, y, radius, startAngle, endAngle){ var start =

Draw reversed circle arc changes circle center coordinates

杀马特。学长 韩版系。学妹 提交于 2020-01-06 09:04:17
问题 I'm using this piece of code to draw arcs and so far it's been great, however I've encountered an issue with textPath that I cannot figure out. Please run the following snippet. function polarToCartesian(centerX, centerY, radius, angleInDegrees) { var angleInRadians = (angleInDegrees-90) * Math.PI / 180.0; return { x: centerX + (radius * Math.cos(angleInRadians)), y: centerY + (radius * Math.sin(angleInRadians)) }; } function describeArc(x, y, radius, startAngle, endAngle){ var start =

How can I account for round-off errors in floating-point arithmetic for inverse trig (and sqrt) functions (in C)?

南楼画角 提交于 2020-01-06 02:46:09
问题 I have a fairly complicated function that takes several double values that represent two vectors in 3-space of the form (magnitude, latitude, longitude) where latitude and longitude are in radians, and an angle. The purpose of the function is to rotate the first vector around the second by the angle specified and return the resultant vector. I have already verified that the code is logically correct and works. The expected purpose of the function is for graphics, so double precision is not

How can I account for round-off errors in floating-point arithmetic for inverse trig (and sqrt) functions (in C)?

不羁的心 提交于 2020-01-06 02:46:04
问题 I have a fairly complicated function that takes several double values that represent two vectors in 3-space of the form (magnitude, latitude, longitude) where latitude and longitude are in radians, and an angle. The purpose of the function is to rotate the first vector around the second by the angle specified and return the resultant vector. I have already verified that the code is logically correct and works. The expected purpose of the function is for graphics, so double precision is not

Find intersecting area of two trapezoids in OpenCV

左心房为你撑大大i 提交于 2020-01-05 06:53:12
问题 I'm writing a function that evaluates how many pixels overlap between two non-isosceles trapezoids. In my application, a trapezoid is always defined as : typedef std::array<cv::Point, 4> Trapezoid; //[0] - bottom left //[1] - bottom right //[2] - top right //[3] - top left Additionally, these trapezoids will have the properties that indexes [0] and [1] will always have the same Y as will [2] and [3] (Always parallel to Y axis). So, let's say I have two trapezoids: //300 high, 100 top, 200

Python cosine function precision [duplicate]

南笙酒味 提交于 2020-01-04 04:22:07
问题 This question already has answers here : Is floating point math broken? (31 answers) Closed 3 years ago . From mathematics we know that the cosine of a 90 degree angle is 0 but Python says it's a bit more than that. import math math.cos(math.radians(90)) 6.123233995736766e-17 What's the matter between Python and the number "0"? 回答1: Repeat after me: Computers cannot process real numbers. Python uses double precision IEEE floats, which round to 53 binary digits of precision and have limits on

When calcuating distance between points on earth why are my Haversine vs. Geodesic calculations diverging?

拈花ヽ惹草 提交于 2020-01-04 02:39:11
问题 I am getting wildly diverging distances using two approximations to calculate distance between points on Earth's surface. I am using the Haversine (vectorized) approximation and the more precise (presumably) geopy.distance.geodesic . As you can see I am off by five percent as the distances between points becomes large. Is this divergence due to rounding error in Haversine? Do I indeed trust the Geodesic? Here is code: import numpy as np lat = np.linspace(35,45,100) lon = np.linspace(-120,-110

Using the Cosine law to calculate distance between 2 points in Objective C?

烈酒焚心 提交于 2020-01-04 02:31:32
问题 I get some GPS coordinates from Google Maps and I need to find the distance between them using Objective C. I have implemented the formula but I get results that are way to big. I have tested the values from Google Maps by passing them back into Google Earth and a Geocoding service on the internet and everything checks out. Im now beginning to suspect that the cosine law demands I do some sort of conversion with the coordinates before I pass them in. I did a similar implementation of the

moving CGPoint a certain distance along a certain heading…iphone

倾然丶 夕夏残阳落幕 提交于 2020-01-04 02:17:13
问题 this seems like such a simple problem but I have been unable to find an answer (and im no good at math). I am trying to move a UIView to a new CGPoint X distance away along a certain heading. What is the formula for determining the new coordinates? (i do no want this to be animated, just an instantaneous move) something like: x = 100; (current x value) y = 150; (current y value) d = 25; (distance to move the point) h = 90; (west) \\\ insert formula to determine new x,y coords self.car.center