Draw a graph in using latex - text

I used \includegraphics[height=1.91in,width=5in]{L1F2.jpg} to insert in the latex. but I would like to draw similar picture in latex and add my own text on it similar to what included and change the little in the arrows. What is the best way to do so.

You'll want to \usepackage{tikz}. Examples of graphics made with TikZ and PGF can be found at texample.net/tikz.
A quick example:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[-] (0,0) -- (0,4) node[below left] {$y$}; % Draw the y-axis
\draw[-] (0,0) -- (4,0) node[below left] {$x$}; % Draw the x-axis
\foreach \x in {1,2,3} % Iterate through {1,2,3} to assist the next line
\draw[shift={(\x,0)}] (0,3pt) -- (0,0pt) node[below] {$x_\x$}; % Mark the intervals
\clip (0,0) rectangle (4,4); % Limit the domain and range of the graph
\draw (0,0) plot ({\x},{\x^2}); % Draw a function of \x
\end{tikzpicture}
\end{document}
(I recognize that this is a simple linear regression model, but having just begun college calculus, I don't yet understand how to write this function in gnuplot without knowing the values of $beta_0$ and $beta_1$.)

Related

How do I rotate a point on the surface of a sphere given 3 degrees of rotation?

I have a point on a sphere that needs to be rotated. I have 3 different degrees of rotation (roll, pitch, yaw). Are there any formulas I could use to calculate where the point would end up after applying each rotation? For simplicity sake, the sphere can be centered on the origin if that helps.
I've tried looking at different ways of rotation, but nothing quite matches what I am looking for. If I needed to just rotate the sphere, I could do that, but I need to know the position of a point based on the rotation of the sphere.
Using Unity for an example, this is outside of unity in a separate project so using their library is not possible:
If the original point is at (1, 0, 0)
And the sphere then gets rotated by [45, 30, 15]:
What is the new (x, y, z) of the point?
If you have a given rotation as a Quaternion q, then you can rotate your point (Vector3) p like this:
Vector3 pRotated = q * p;
And if you have your rotation in Euler Angles then you can always convert it to a Quaternion like this (where x, y and z are the rotations in degrees around those axes):
Quaternion q = Quaternion.Euler(x,y,z);
Note that Unity's euler angles are defined so that first the object is rotated around the z axis, then around the x axis and finally around the y axis - and that these axes are all the in the space of the parent transform, if any (not the object's local axes, which will move with each rotation).
So I suppose that the z-axis would be roll, the x-axis would be pitch and the y axis would be yaw.You might have to switch the signs on some axes to match the expected result - for example, a positive x rotation will tilt the object downwards (assuming that the object's notion of forward is in its positive z direction and that up is in its positive y direction).

Numerically finding the projected area of a bullet

Suppose I have a bullet as shown below where the measurements are in units of bullet diameters (this thing is 3 dimensional, so imagine rotating it about the x axis here)
If this bullet were to be tilted upwards by an angle θ, how could I numerically find its projected area?
I'm trying to find the area that such a bullet would present to the air as it moves through it and so if it is not tilted away from the direction of motion this area is simply a circle. I know for small tilts, it will simply present the projected area of a cylinder but I am unsure about how to deal with tilts large enough that one needs to care about the tip of the bullet for purposes of finding the area. Anyone have ideas about how to deal with this?
Hint:
The boundary curves of the bullet are the apparent outline of the inner surface of a self-intersecting torus. They can be found by expressing that the normal vector is parallel to the projection plane.
With z being the axis of the bullet, the parametric equation of the surface is
x= (R + r sinφ) cosΘ
y= (R + r sinφ) sinΘ
z= r cosφ
and the normal is obtained by setting R=0,
x= r sinφ cosΘ
y= r sinφ sinΘ
z= r cosφ
Now for some projection plane with a normal in direction (cosα, 0, sinα), the outline is such that
r sinφ cosΘ cosα + r cosφ sinα = 0.
From this you can draw Θ as a function of φ or conversely and construct points along the curve.
When α increases, the tip of the bullet starts entering the ellipse resulting from the projection of the basis of the cylindre. This ellipse corresponds to the angle φ such that z=0.
The surface is known as a lemon shape: http://mathworld.wolfram.com/Lemon.html

How to plot contour maps and display average of the mark(associated with x,y) for each contour level

I have a contour map in spatstat generated from the intensity function of a point pattern X (like "location of the trees"). Each x,y coordinates in this point pattern is marked with a corresponding third vector (like "diameter of the tree").
-->cf image (of course the vertical lines representing the tree can be omitted)
I would like to display the average of the mark (diameter) in each level of the contour with different colors. Suggestions?
Thanks!
You are effectively asking for a kind of nonparametric regression.
Here is a quick-and-dirty calculation using the function rhohat and demonstrated on the longleaf dataset.
First calculate the intensity estimate: Z <- density(longleaf) yielding an image Z. Next treat Z as a covariate in calls to the rhohat command:
f <- rhohat(unmark(longleaf), Z)
and
g <- rhohat(unmark(longleaf), Z, weights=marks(longleaf)).
Now take the ratio, h <- eval.fv(g/f) and plot it, plot(h). This shows the estimated average tree diameter as a function of the forest density. To apply this function h to the original contours of Z you would first convert h to a true function by H <- as.function(h) then evaluate hZ <- eval.im(H(Z)) and finally plot(hZ).

Radial gradient equation

Given:
A point P, circle 1 and circle 2's positions and radii
What is:
The equation for T, the 'mix level' between color 1 and 2 (a value between 0 to 1)
Many radial gradient equations only apply to concentric circles or circles that share a position. I'm looking for something that matches the image below, created using Quartz (Core Graphics). I am writing a GLSL shader, but I need to understand the math first.
If this is in 2D, then you can write the parameters of the circle that your point lies on as:
x3=T*x1+(1-T)*x2
y3=T*y1+(1-T)*y2
r3=T*r1+(1-T)*r2
EDIT: Of course, that circle can be represented as:
(x3-xP)^2+(y3-yP)^2=r3^2
You can substitute the first 3 equations into the last (and remember that (xP, yP) is your point) to get 1 equation with only T as a variable that is quadratic in T, so it is easy to solve for T. Doing so gives us:
T=(-r2*(r1-r2)+(x1-x2)*(x2-xP)+(y1-y2)(y2-yP)
{+-}sqrt(r2^2*((x1-xP)^2+(y1-yP)^2)-2*r1*r2*((x1-xP)*(x2-xP)
+(y1-yP)*(y2-yP))+r1^2*((x2-xP)^2+(y2-yP)^2)
-(x2*y1-xP*y1-x1*y2+xP*y2+x1*yP-x2*yP)^2))
/((r1-r2)^2-(x1-x2)^2-(y1-y2)^2)
I know that that is a bit hard to read, but it is not actually that bad mathematically. It is just addition, multiplication, and squaring (which is really just multiplication).

Texturing a sphere in a Cg shader

So I need to map a texture to a sphere from within a pixel/fragment shader in Cg.
What I have as "input" in every pass are the Cartesian coordinates x, y, z for the point on the sphere where I want the texture to be sampled. I then transform those coordinates into Spherical coordinates and use the angles Phi and Theta as U and V coordinates, respectively, like this:
u = atan2(y, z)
v = acos(x/sqrt(x*x + y*y + z*z))
I know that this simple mapping will produce seams at the poles of the sphere but at the moment, my problem is that the texture repeats several times across the sphere. What I want and need is that the whole texture gets wrapped around the sphere exactly once.
I've fiddled with the shader and searched around for hours but I can't find a solution. I think I need to apply some sort of scaling somewhere but where? Or maybe I'm totally on the wrong track, I'm very new to Cg and shader programming in general... Thanks for any help!
Since the results of inverse trigonometric functions are angles, they will be in [-Pi, Pi] for u and [0, Pi] for v (though you can't have searched for hours with at least basic knowledge of trigonometrics, as acquired from school). So you just have to scale them appropriately. u /= 2*Pi and v /= Pi should do, assuming you have GL_REPEAT (or the D3D equivalent) as texture coordinate wrapping mode (which your description sounds like).

Resources