Generate a cone with a point and angle

17 vues (au cours des 30 derniers jours)
ibabinaca
ibabinaca le 4 Fév 2019
Commenté : John D'Errico le 5 Fév 2019
Hello,
I want to know how to easily generate a cone ecuation with a point and a given angle and parallel to the z axis. The height of the cone can be any.

Réponse acceptée

John D'Errico
John D'Errico le 4 Fév 2019
Modifié(e) : John D'Errico le 4 Fév 2019
This question initially has absolutely nothing to do with MATLAB, because you have no idea how to solve it. Until you understand the mathematics of a problem, writing code is never possible. But I have a few minutes, so I might as well go through the thinking for you.
When you have a problem like this, break it down. If necessary, think in terms of other coordinate systems. Here, cylindrical coordinates would make sense, since a cone is just a rotationally symmetric surface, rotated around the z-axis.
So you want to create a function, z(x,y) that defines the cone. Since we will start out by working in cylindrical coordinates, I'll create things as z(r,theta). Then the conversion back to cartesian coordinates is trivial.
Assume the vertex of the cone will be at some value z0. And you want the angle at the point to be phi. Since the problem is rotationally symmetric cone, we can ignore theta completely. Just assume we have a line in the plane (r,z) plane, that intersects the z axis at z==z0. You want the angle that the line crosses the z axis to be phi/2, with the line going down for increasing r.
So the result in the plane (r,z) will be two lines , intersecting the z axis. The total angle between the lines will be phi, but the slope of either line will be -cotd(phi/2). (Think about it. I won't do all your thinking for you. Basic trig here. Consider the angle the line makes with the z-axis.) I've used cotd so we can use degrees for the angle.
So we can represent the cone in the (r,z) plane as
z = z0 - abs( r )*cotd(phi/2)
Now, convert to cartesian coordinates.
We should know that r=the equation of a circle of radius r is simply
r^2= x^2 + y^2
So then
abs( r ) = sqrt(x^2 + y^2)
thus the positive branch of the sqrt. This gives you the surface equation as desired.
z(x,y) = z0 - sqrt(x.^2 + y.^2)*cotd(phi/2)
So a rotationally symmetric surface arpund the z-axis. The radius of the circle increases linearly as z decreases. The peak of the cone is at (x,y,z) = (0,0,z0), again as desired. The angle of the cone is clearly phi.
Note that I used .^ in that equation to make sure you understand to use that operator. This will allow vectorized computations to be done.
For example...
conefun = @(x,y,z0,phi) z0 - sqrt(x.^2 + y.^2)*cotd(phi/2);
fsurf(@(x,y) conefun(x,y,10,90))
axis equal
So a conical surface, here passing through z0 = 10, with an angle of 90 degrees. You can see the surface is clearly rotationally symmetric, and we see the conic surface decreases linearly with distance from the axis.
To convince you the surface is rotationally symmetric around the z axis, look at contours of the surface.
fcontour(@(x,y) conefun(x,y,10,90))
axis equal
grid on
So perfectly circular contours, centered around the origin, (x,y) = (0,0). A cone. The conic surface extends to -inf as (x,y) go away from the origin.
  2 commentaires
Matt J
Matt J le 5 Fév 2019
Why? You have the equation for the cone, so there is no need for delaunayn or tsearchn.
John D'Errico
John D'Errico le 5 Fév 2019
Inside or outside the cone? That is trivial. If you have a point (x,y,z), then just compare z to conefun(x,y). If z is smaller, then the point is inside the cone.

Connectez-vous pour commenter.

Plus de réponses (1)

Matt J
Matt J le 4 Fév 2019
Modifié(e) : Matt J le 4 Fév 2019

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by