How to determine if point is inside skewed conical frustum - vector

I'm trying to work out whether a point is inside an ellipsoid cone formed between a point and a circle in 3D space. The cone is ellipsoid because the point is not perpendicular to the centre of the circle. See diagram below:
So I know:
The position of the point forming the apex of the cone: x
The location of the centre of the circle: c
The radius of the circle: r
The locations of various points I want to determine if they are inside the cone: y, z
Here is a top view of the same diagram:
I do not care about the base of the cone - I want points contained within the cone stretched effectively to infinity.
I've found formulae for working out whether a point is within an ellipsoid cone given the major/minor axis, but having difficulty working out how to do it when the ellipsoid cone is formed from a circle at an angle.
Thanks for any help!

With a conic you could probably determine distance from the axis and a semi major and minor and compute it directly.
Harder is some arbitrary shape.
If the cone has the point in the Z Axis direction, and you know a point in XYZ... then you should be able to draw an ellipse at that particular Z level. Maybe draw it with 360 segments.
Once you have your point and your ellipse, then you can test ellipse segment to see if there is an intersection in X & Y.
Imaging a circle at 0,0,0 with radius 1. And a point at 0,0,0 there are 2Y intersections at +/- 90 degrees and 2 X intersections happening at 0 and 180
If the point is at 2,0,0 you still have 2 intersections in X but they are to the left, and you want one to the left and one to the right.
Zero intersections mean. That you are outside the hoop.
Repeat across the 360 segments and determine how to handle points "on a line" and how close "on" is.

Related

Calculate radius of curve/arc formed by line segments (approximate)

The calculation is for games so a approximation is better than a computational intense correct calculation. What i need to find is the radius of the given arc.
In this case the "curve" can be thought of a arc as this approximation is good enough. So the situation look like this:
I know:
the length the green lines (which are equal)
the length of the blue arc
the value of α in degrees
What i need to know:
the radius r
Background - Actually i need the radius for two things:
To calculate the length of a arc B with offset of x from the center arc. So that r of B would be r + x
To calculate the centrifugal force of a vehicle driving on that curve
What i tried:
I know how to calculate the radius if i have the circumference and the inner angle of the arc. But i am completely stuck with the given information though i am sure it should not be too complicated ..
If you think a triangle with right angle at the middle of the green line and another point at the center of the circle, then the angle at the intersection of the green segments in that triangle is α/2 and the cosine ratio for that angle is
cos(α/2)*r = g/2
g the length of a green segment.
The angle at the top of a pie slice is π-α so that for the length b of the blue curve segments you should get
b = (π-α)*r
The radius values you get from both formulas should not differ more than the measurement errors let expect.
Alternatively, you could use Catmull-Rom (https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline), Hermite (https://en.wikipedia.org/wiki/Cubic_Hermite_spline), or natural (https://en.wikipedia.org/wiki/Spline_interpolation) cubic spline interpolation to calculate the path between the points.
This will give you cubic polynomials for the (x,y) coordinates, and it's easy to take their 2nd derivatives to get the direction and magnitude of acceleration.

how to get cordinates of points drawn on ractangle perimeter using circular function?

I have rectangle with known base and height. I need coordinates of points on rectangle perimeter which is obtained by drawing lines from the center of base after every known degree (Say 1 degree) for the range of 0 -180 degree.
To get my question clearly i have attached image below. Kindly have a look.
Clues for a possible approach:
Find x-coordinate of intersection of ray with angle Theta and top edge of rectangle (note special cases Theta = 0, Theta = Pi)
If this coordinate lies outside of rectangle, find y-coordinate of intersection of ray and vertical edge (choose right one depending on angle)

How can I compute normal on the surface of a cylinder?

I am working on a ray tracer and I got around to adding cylinders to the scene. The point I am stuck at is finding the surface normal vector in the point the ray hits. I need this to be able to do the diffuse lighting. What I have at this point is the 3d point where the camera ray hits the cylinder and the actual cylinder which is defined with a point on the central axis, the vector representing the direction of the axis and the radius. So to sum up my question, how do I find the normal vector in a point having the cylinder hit point, the radius, a point on its axis and the direction vector of the axis?
The cylinder normal vector starts at the centerline of the cylinder at the same z-height of the point where the ray intersects the cylinder, ends at the radial point of intersection. Normalize it and you have your unit normal vector.
If the cylinder centerline is not along the global z-direction of the scene you'll have to transform to cylinder coordinates, calculate the normal vector, and transform that back to global coordinates.
There are three possible situations:
the hit_pt is on the TOP CAP of the cylinder:
if (length(hit_pt - cy.top_center) < cy.radius)
surface_normal = cy.ori;
the hit_pt is on the BOTTOM CAP of the cylinder:
if (length(hit_pt - cy.bottom_center) < cy.radius)
surface_normal = -1 * cy.ori;
the hit_pt is on the SIDE of the cylinder. We can use dot product to find the point 'pt' on the center line of the cylinder, so that the vector (hit_pt - pt) is orthogonal to the cylinder's orientation.
t = dot((hit_pt - cy.bottom_center), cy.ori); // cy.ori should be normalized and so has the length of 1.
pt = cy.bottom_center + t * cy.ori;
surface_normal = normalize(hit_pt - pt)));

Calculating rectangle 3D coordinate with coordinate its shadow?

Sometimes was a problem what is the rectangle 3D rotated and be perspective transition (for example in CSS) draw as the tetragon. But we want obtain the rectangle (width, length, Euler angle, perspective) transformed via rotate and perspective draw as the tetragon.
figure
fig.1 points a,c diagonal rectangle(yellow) points A,C diagonal tetragon(shadow) (red)
fig.2 a,b,c,d rectangle points(yellow) A,B,C,D shadow(tetragon) (red)
Solve:
Coordinate system:
The origin of the coordinate system is coincident with diagonals intersection point. Axe Z normal to the tetragon. Axe X crosses point A
a,b,c,d;- ;- rectangular with coordinates
a(x1,y1,z1);
b(x2,y2,z2);
c(x3,y3,z3);
a(x4,y4,z4);
A,B,C,D-shadow. Corner points A(q1,p1,0);
B(q2,p2,0); C(q3,p3,0);
D(q4,p4,0);
k perspective.
In that system of coordinate y1=y3=0.
Fig1.
From similarity transformation triangles is:
x1=1-z1/kq1;
x3=1-z3/kq3
From statement of problem was that diagonal cross is in the origin of the coordinate thus:
z3=-z1 и x3=-x1
Substituting in expression above and equating to each other was :
x1=2*q1*q3/(q3-q1);
z1=(q1+q3)/(q1-q3)*k.
To simplify other calculation imagine that second rectangle diagonal (bd) lie in coordinate system in that Y coordinate of diagonal points is equal zero. In this coordinate system coordinate points b and d was the same as point a and c but we must change z1 to z2, z3 to z4, x1 to x2, x3 to x4,q1 to q2, q3 to q4. To translate from imagine system to real system use rotation coordinate formula (Z axe is the same, z coordinate is equals)
Fig.2
x=x'*cos(a); y=y'*sin(a); The result was:
x2=-x4=2*q2*q4/(q4-q2);
y2=-y4=x2*tan(a);
z2=-z4=(q2+q4)/(q2-q4)k;
tan(a)=(p2-p4)/(q2-q4)
abcd was parallelogram. Diagonal cross point divide diagonal to half. We need to one more expression to make rectangular. Use angle equal 90 degrees. Make scalar multiplication vector of two side in abcd. In coordinate it was:
(a-b)(d-a)=y4y2+(x1-x4)(x1-x2)+(z1-z4)*(z1-z2)=0;
f=(q1*q2-q3q4)(q1*q4-q2*q3)
g=-tan2(a)*q42q22(q1-q3)2+(-q1q2(q3+q4)+q3q4(q1+q2))*(q1q2(q4-q3)+q3q4(q1-q2))
We receive equation to k(perspective): f*k2-g=0, solve it
k=sqrt(g/f).
Collect all formula we get all coordinates of point abcd.
From coordinate of corner is simple to calculate side of rectangular.
Calculating quaternion, rotation matrix, angles see calculate quaternion by coordinate 2 points of object in two positions

Translation coordinates for a circle under a certain angle

I have 2 circles that collide in a certain collision point and under a certain collision angle which I calculate using this formula :
C1(x1,y1) C2(x2,y2)
and the angle between the line uniting their centre and the x axis is
X = arctg (|y2 - y1| / |x2 - x1|)
and what I want is to translate the circle on top under the same angle that collided with the other circle. I mean with the angle X and I don't know what translation coordinates should I give for a proper and a straight translation!
For what I think you mean, here's how to do it cleanly.
Think in vectors.
Suppose the centre of the bottom circle has coordinates (x1,y1), and the centre of the top circle has coordinates (x2,y2). Then define two vectors
support = (x1,y1)
direction = (x2,y2) - (x1,y1)
now, the line between the two centres is fully described by the parametric representation
line = support + k*direction
with k any value in (-inf,+inf). At the initial time, substituting k=1 in the equation above indeed give the coordinates of the top circle. On some later time t, the value of k will have increased, and substituting that new value of k in the equation will give the new coordinates of the centre of the top circle.
How much k increases at value t is equal to the speed of the circle, and I leave that entirely up to you :)
Doing it this way, you never need to mess around with any angles and/or coordinate transformations etc. It even works in 3D (provided you add in z-coordinates everywhere).

Resources