Problem in Z coordinators in Holistic detection - artificial-intelligence

When extracting coordinates X, Y and Z I get positive and negative numbers in the Z, any explication?
For example:
[X1=0.409132 Y1=0.764077 Z1=-0.008088 X2=0.468663 Y2=0.747041 Z2=0.010161]
Why Z1 ==>Negative and Z2==> Positive

Related

Working out 3d destination based on angles and distance

I want to work out if I have an object in space, and I know how fast it will travel in a second and at what angle it is going, where it will end up on the x y and z.
`I have already tried using the same equation for x, and y, but neither quite come out right, and I think it is a logic error.
Idealy, I'd want to know: 1, how to calculate it. I'd expect a result of: {x, y, z} where x y and z are finishing coordinates.
Additional code:
dx=distance traveled on x
dy=distance traveled on y
dz=distance traveled on z:
xb = dx * sin(angle1);
y= dy * cos(angle1);
z= dz * cos(angle2);

how to increase the possibility of getting a specific random object from an array

Generally, I know that I can get a random element of an array in the following way:
var myArray = [x, y, z]
let myArrayLength = UInt32(myArray.count)
let myArrayIndex = Int(arc4random_uniform(myArrayLength))
let randomElement = myArray[myArrayIndex]
But how can I make the possibility of y being the random element twice the possibility of x and z being the random element thrice the possibility of y?
UPDATE
NB: Where x, y and z are CGPoints
An easy way is to rewrite your array like this: [x,x,y,z]. Then, the probability of getting x becomes 0.5, the probability of y becomes 0.25 and the probability of z becomes 0.25. Just repeat the symbols with high probability as much as you want, for example [x, y, y, z, z, z, z] is good for what you asked for.

Little bit confused about the math behind this function

So I've been looking at this function that converts Cartesian coordinates to polar and the if statement that says if x == 0 and y>0 then theta == pi/2.
However, if one wants to calculate theta it simply follows the form:
theta = atan(y/x).
What is confusing me is that if x == 0 this function is immediately undefined? since you are dividing by 0 this should tend to infinity right?
So how is it that in this function it states that if x ==0 and y>0 it always equals pi/2?
It's probably so basic and I'm just complicating way to much...
Thanks in advance.
void carttopolar(float x, float y, double *radptr, double *thetaptr){
float theta;
*radptr = sqrt(x * x + y * y);
if(x==0){
if(y==0){
theta = 0.0;
}
else if(y>0){
theta = M_PI_2;
}
else{
theta = -M_PI_2;
}
}
else{
theta = atan(y/x);
}
*thetaptr = theta;
}
The point is that atan is the inverse of tan and tan does actually generate infinite values at some points, here's a picture:
The code is catching the cases where you would feed an infinite argument into atan and returning the angle that would give infinity (+/- pi/2 gives positive or negative infinity respectively).
The generally accepted way to do this is to just use the atan2 function instead.
This code is assuming that any positive number divided by zero is positive infinity, and any negative number divided by zero is negative infinity. It special cases these because dividing by zero doesn't do anything useful in C. The arctangent of positive and negative infinity are π/2 and -π/2, respectively.
The reason behind being always pi/2 or -pi/2 is because of the definition of Polar coordinates. A polar point is described by P(r, Phi). So, if X is 0 (and y != 0) the only possibilities are 90° and 270° => PI/2 and -PI/2
The distance on the Y axis is defined by 'r'
See also:
http://en.wikipedia.org/wiki/File:Polar_graph_paper.svg
::edit::
added: "and y != 0", ty chux

MATLAB, interpolation of 3D curve crossing xy plane

In Matlab, I have a 3D-curve (array with 3 coordinates) that crosses the xy-plane in a 3 dimensional coordinate system. The "curve" is just a bunch of x,y,z points and its shape is elliptical that spans across the 3D space and spirals towards the origin. It crosses the xy plane several times and I would like to interpolate the x and y coordinates when the curve intersects the xy plane (i.e. when z=0). How do I do so?
Assuming you have 3 vectors x, y, and z with coordinates,
crossidx = find(diff(sign(z)) ~= 0); % z(zcross) and z(zcross+1) have different signs
z1 = z(crossidx);
z2 = z(crossidx+1);
dz = z2 - z1;
alpha = -z1;
beta = z2;
xcross = (beta*x(crossidx) + alpha*x(crossidx+1))./dz;
ycross = (beta*y(crossidx) + alpha*y(crossidx+1))./dz;
zcross = 0;
hold on; plot3(xcross, ycross, zcross, '*');
It should work for either positive to negative or negative to positive crossing. I wrote the code assuming only 1 zero crossing, but I think it would also work for any number of crossings.

Intersection of two lines defined in (rho/theta ) parameterization

Have created a c++ implementation of the Hough transform for detecting lines in images. Found lines are represented using rho, theta, as described on wikipedia:
"The parameter r represents the distance between the line and the origin, while θ is the angle of the vector from the origin to this closest point "
How can i find the intersection point in x, y space for two lines described using r, θ?
For reference here are my current functions for converting in and out of hough space:
//get 'r' (length of a line from pole (corner, 0,0, distance from center) perpendicular to a line intersecting point x,y at a given angle) given the point and the angle (in radians)
inline float point2Hough(int x, int y, float theta) {
return((((float)x)*cosf(theta))+((float)y)*sinf(theta));
}
//get point y for a line at angle theta with a distance from the pole of r intersecting x? bad explanation! >_<
inline float hough2Point(int x, int r, float theta) {
float y;
if(theta!=0) {
y=(-cosf(theta)/sinf(theta))*x+((float)r/sinf(theta));
} else {
y=(float)r; //wth theta may == 0?!
}
return(y);
}
sorry in advance if this is something obvious..
Looking at the Wikipedia page, I see that the equation of a straight line corresponding to a given given r, θ pair is
r = x cosθ + y sinθ
Thus, if I understand, given two pairs r1, θ1 and r2, θ2, to find the intersection you must solve for the unknowns x,y the following linear 2x2 system:
x cos θ1 + y sin θ1 = r1
x cos θ2 + y sin θ2 = r2
that is AX = b, where
A = [cos θ1 sin θ1] b = |r1| X = |x|
[cos θ2 sin θ2] |r2| |y|
Had never encountered matrix maths before, so took a bit of research and experimentation to work out the proceedure for Fredrico's answer. Thanks, needed to learn about matrices anyway. ^^
function to find where two parameterized lines intersect:
//Find point (x,y) where two parameterized lines intersect :p Returns 0 if lines are parallel
int parametricIntersect(float r1, float t1, float r2, float t2, int *x, int *y) {
float ct1=cosf(t1); //matrix element a
float st1=sinf(t1); //b
float ct2=cosf(t2); //c
float st2=sinf(t2); //d
float d=ct1*st2-st1*ct2; //determinative (rearranged matrix for inverse)
if(d!=0.0f) {
*x=(int)((st2*r1-st1*r2)/d);
*y=(int)((-ct2*r1+ct1*r2)/d);
return(1);
} else { //lines are parallel and will NEVER intersect!
return(0);
}
}

Resources