Ray tracing triangle intersection in cylindrical coordinates - coordinates

I am using a finite difference Navier Stokes code that supports both cartesian and cylindrical coordinates. There is a task where we have a geometry given by a STL file (in cartesian coordinates) and we need to find intersections of rays that we shoot along the grid coordinates. Is there an algorithm to find intersection of ray with triangle in cylindrical coordinates? For example a ray along the azimuthal direction, where the radius is constant but the azimuthal coordinate changes.

Related

How to rotate a 3D plane?

I have a 3d plane (made up of number of points) which is rotated at weird angle. I want to make it flat i.e lie on xy-plane. I have plane equation but I think my calculated angles are not correct or might be using wrong rotation matrix. By wrong rotation matrix is that I meant that I am not sure about which axis should I rotate. attached is the picture of my plane:
I tried to calculate by using following formulas:
theta=-acosd((dot(n1,n2))/(norm(n1)*norm(n2)));
Calculate spherical angles: theta and phi;
both methods are giving same angle, I rotated my plane first about z-axis and then about y-axis. The resulted plane is almost flat but it still has some anlge.
I tried both rotation matrix and Rodrigues' rotation matrix. It would be really helpful if someone could suggest how to rotate this plane to make it flat.
When a plane is not parallel to the xy-plane, then it's normal vector will not be parallel to the z-axis. So the cross product of the normal vector and the z-axis (unit) vector will be non-zero. This vector is in the plane and parallel to the xy-plane. Take it as rotation axis. The rotation angle to make the plane parallel to the xy-plane is the same as the angle between the normal vector and the z-axis.

How can I calculate a tangent vector at a point in 3D dimensions?

On the z=0 plane, I have a point A(a1,b1,0). And there is another point B(a2,b2,0) which I consider it as the center of a circle. I connect AB together and then draw a circle with radius AB. There is another point C(a3,b3,c3) in the 3D zone.
How can I find the tangent vector of AC on the circle with radius AB?Ie means that I need to calculate the tangent vector of AC at point A.
If you mean tangent to the circle at point A, then it is unique vector perpendicular to vector AB and is NOT dependent on any other point in 3D like point C. It should be easy to calculate.
On other hand project of AC on the plane is easy to calculate but it is NOT guaranteed to be tangent vector that you are looking for.

Distance between two point along the cylinder surface

How to find out distance between point along the surface from one point to all other point on the cylinder surface.
XYZ coordinates of points are known
e.g
suppose 4 points are there on the surface of the cylinder here i want to find out following data i.e distance between point(1-2),point(1-3),point(1-4),point(2-3),point(2-4),point(3,4) along the surface.H
What you are looking for is the geodesic of a cylinder. Since you mentioned Matlab in the tag, you can use this tool

Contour triangulation

I write my study and is stuck when i try triangulate the contour of surface. When it is in 2D its ok. When it in 3D a have trouble with triangle angle detection, i tried with:
Triange have 3 Vertices v1,v2,v3
I create 2 vectors(vec21, vec23) from v2v1 and v2v3
then vec21 x vec23 and obtain a det of matrix
on the stand which I define Span angle
I also check if edges do not crossing and if any point isnt in area of triangle.
But when it in 3D i choose point around polygon then this metod didn't work
Points of contour i want triangulate to flat polygon: https://docs.google.com/open?id=0Bw5-VXnqutXBckRJMGNJMW9JaXc
Bad resoult: https://docs.google.com/open?id=0Bw5-VXnqutXBMzV5elIxX1FaeDQ
In 2d:
Points on 2D :https://docs.google.com/open?id=0Bw5-VXnqutXBWVE4bWJsZ09mOVk
Good resoults:https://docs.google.com/open?id=0Bw5-VXnqutXBdGFKM2Z4UnFRdXc
Where i made mistake? Can u explain me this?
Greetings!
PS. Im interested in algoithm at 2 last case:http://www.cosy.sbg.ac.at/~held/projects/triang/triang.html
Typically one would use a Delaunay Triangulation for the 2D case. For the 3D case you can project the points to 2D, triangulate and project the triangles back to 3D. This will of course only work if the patch to be triangulated can be projected to 2D (without selfintersections).

Cylindrical projection to sphere

I have a 2d array (lat*long) containing height information. I want to map this cylindrical projection to a actual sphere with radius r and plot it.
How would I do that? Sorry it so little info, but I'm completely lost right now ...
Longitude and latitude are not cylindrical coordinates; rather, they are equivalent to azimuth and elevation in spherical coordinates. At each latitude and longitude, you have a height (which may need to have the mean radius of the sphere added to it if it isn't the true height from the center already).
Check out the sph2cart function, which converts from spherical to cartesian coordinates. You'll have to convert from degrees to radians first.
Steps to take:
Create matrix (same size as original) with just longitudes.
Do the same for just latitudes (after this you should have 3 matrices of the same size as your original - latitude, longitude, height).
Make sure those latitude and longitude matrices are in
radians, not degrees
Make sure your height info is from the
center of the sphere
Use sph2cart to get x,y,z matrices.
Use surf(x,y,z) to plot the results
Notes on sph2cart from the documentation:
[x,y,z] = sph2cart(azimuth,elevation,r) transforms the corresponding
elements of spherical coordinate arrays to Cartesian, or xyz,
coordinates. azimuth, elevation, and r must all be the same size (or
any of them can be scalar). azimuth and elevation are angular
displacements in radians from the positive x-axis and from the x-y
plane, respectively.