Is there any way to include a vector of numerics within the angle parameter of the element_text() function in R. It appears that in a new version of ggplot2, the angle parameter only accepts a single number.
Related
I understand how to do this using right triangles: the length of my desired vector will be the magnitude of vector a divided by the cosine of the angle between vector a and the given unit vector. Once I find this value, I can simply scale the unit vector by this length.
Assuming that the dot product of the normalized vector a and the given unit vector is greater than 0, how can I find this length using only vector math? Below is a picture to help illustrate what I'm trying to do. I want the red vector, which will be a unit vector, to be scaled until it meets the white line that is perpendicular with vector a.
We start with the green vector a and the red unit vector r.
Normalize a to get a unit vector we'll call k:
k = a/|a|
Now project r onto k to get the component of r in the direction of a, call it x (which is equal to the cosine of the angle between r and a).
x = r · k = (1/|a|)(r · a)
Now we use similar triangles:
|R|/|a| = |r|/x = 1/x
|R| = |a|/x
R = |R|r = (|a|/x)r = (|a|2/(r · a))r
E.g., when processing the set of plane contours:
each one consists of N nodes and may be described by the matrix N*2
(x, y coordinates of every node).
The number of nodes in the contour is changed during processing.
What is the simplest recommended object (data type) in Julia for such set of contours?
Simplest possible in what way? See GeometryTypes.jl. The "simplest" object, by some definitions of simple, is a vector of 3D points, with (x, y) the node coordinates and z the contour height value. You could use Point3f0 with Float32 or Point3d{T} for Int or Float64. Here you could index with ranges, as Matt suggested above.
If there is a desire for "simple" here to mean keep the contour value in a different category altogether than the (x, y) points, perhaps to save memory, then a Dict{Float32, Vector{Point2f0}}() would do that. The Dict keys would represent the contour numbers. This allows quick indexing by contour but terrible indexing by X and Y ranges as a price for the better memory usage.
If the contour indexes are so regular and predefined that storing them with the points does not matter, you could use Vector{Vector{Point2f0}}, a vector of vectors of Point2f0, with one vector of Point2f0 per contour in your vector of vectors.
I'm given a problem set with data for all the x coordinates in one vector and all the y coordinates in a second vector and I'm able to plot them fine with a single call function. But now I'm asked to run the same code, but now, plot it using a For Loop. I've never done for loops over 2 vectors before, so I'm a bit lost here.
Here's the exact breakdown of the question:
Write a for loop that iterates over the two vectors, taking corresponding values of the problem.8.x.data vector and the problem.8.y.data and plotting a single point at that location:
* Then graph the sequence of points by iterating over the two vectors. (Hint: you can do this by iterating with an index, and then using positive integer indexing to select the elements from the two vectors.)- In the first iteration of the for loop, plot a point at the location where the $x$-coordinate is the first value of the problem.8.x.data vector and the $y$-coordinate is the first value of the problem.8.y.data` vector. - In the second iteration of the `for` loop, plot a point at the location where the $x$-coordinate is the second value of the `problem.8.x.data` vector and the $y$-coordinate is the second value of theproblem.8.y.datavector. - In the third iteration of theforloop, plot a point at the location where the $x$-coordinate is the third value of theproblem.8.x.datavector and the $y$-coordinate is the third value of the ``problem.8.y.data vector. Your for loop should iterate over all the points, so make sure you get the upper limit right. (Hint: the $x$ and $y$ data vectors must have the same number of values, so you can just calculate the length of one of them to find the number of points.)
The length of each vector is 36 values so they match up. Originally I thought I had to be using two separate loops but it looks like they are keen on it being iterated over one loop to plot the points. My current code runs fine and gets the correct answer, but I don't think it's utilizing the for loop in any regard:
plot(
x = NULL,
xlim = c(-3, 3),
ylim = c(0, 4),
main = "Smile.8",
xlab = "",
ylab = "",
las = 1
)
for (index.8b in 1:length(problem.8.x.data)) {
points( problem.8.x.data, problem.8.y.data,
pch = 19,
cex = 2,
col = "royalblue3"
)
}
Any advice on how to go about solving this problem?
How can we use vector and scalar in games? What benefit from that.
Could someone please indicate precisely the difference between a scalar and a vector in games field ? I find no matter how many times I try to understand but I maybe need examples for that.
A scalar is just another word for a number. The distinction is that a scalar is a number that is part of a vector. There is nothing special about a scalar.
A vector is a set of numbers (one or more) that define something, in the most common case you have 2 numbers representing a 2D vector or 3 numbers representing a 3D vector. The abstract notion for a vector is simply an arrow.
Take a piece of graph paper. Select any point on that paper and call it the origin. Its coordinate will be x = 0, y = 0. Now draw a straight line from that point in any direction and any length. To describe that arrow you need to define the vector. Count how far across the page the end of the arrow is from the start (origin) and that is the x component. Then how far up the page and that is the y component.
You have just created a vector that has two numbers (x,y) that completely describe the arrow on the paper. This type of vector always starts at zero. You can also describe the vector by its direction (ie north, east, south...) and length.
In 3D you need 3 numbers to describe any arrow. (x,y,z)
Vectors are very handy. You can use a vector to describe how fast something is moving and in what direction. The vector represents a little arrow that starts where the object is now and ends where the object will be in the next time unit.
Thus an object at coordinate x,y has a vector velocity(0.2,0.3). To calculate the position of the object in the next time unit just add the vector to the coordinate
newXPos = currentXPos + velocityVectorX
newYPos = currentYPos + velocityVectorY
If you want to slow the speed by half you can multiply the vector by 0.5
velocityVectorX = velocityVectorX * 0.5
velocityVectorY = velocityVectorY * 0.5
You do the same to increase the speed.
velocityVectorX = velocityVectorX * 2
velocityVectorY = velocityVectorY * 2
You may have an object in 3D space that has many forces acting on it. There is gravity a vector (arrow) pointing down (G). The force of the air resistance pointing up (R). The current velocity another arrow pointing in the direction it is traveling (V). You can have as many as you like (need) to describe all the forces that push and pull at the object. When you need to calculate the position of the object for the next instance in time (say one second) you just add all the force vectors together to get the total force as a vector and add that to the objects position
Object.x = Object.x + G.x + R.x + V.x;
Object.y = Object.y + G.y + R.y + V.y;
Object.z = Object.z + G.y + R.z + V.z;
If you just want the velocity
V.x = V.x + G.x + R.x;
V.y = V.y + G.y + R.y;
V.z = V.z + G.y + R.z;
That is the new velocity in one second.
There are many things that can be done with a vector. A vector can be used to point away from a surface in 3D, this vector is called a surface normal. The you create a vector from a point on that surface pointing to a light. The cosine of the angle between the two vectors is how much light the surface will reflect.
You can use a vector to represent the three direction in space an object has. Say a box, there is a 3D vector pointing along the width, another along the height and the last along the depth. The length of each vector represents the length of each side. You can make another vector to represent how far the corner of the box is from the origin (any known point) In 3D these 4 vectors are used to represent the object and is called a transformation matrix (just another type of vector made up of vectors)
The list of things vectors can do is endless.
The basics is just like number, you can add, subtract, multiply and divide and vector.
Then there are a host of special functions for vectors, normalize, transform, dot product and cross product to name but a few. For these things people normally use a library that does all this for you. My view is that if you really want to learn about vectors and how they are used write your own vector library at some point until then use a library.
Hope that cleared the mud a little bit for you, it is always difficult to describe something you have used for a long time to someone that is new to it so feel free to ask questions in the comments if you need.
I have 3d line(unit direction vector) which allways originate in (0,0,0) and 3d vector which allways points in one of two directions(negative or positive) on this 3d line.
The question is how do I check on which side my vector is ?
Your unit vector is of form (x,y,z) and your other vector is of form (a,b,c).
It's now enough to find any component x,y,z that is not zero and test that the corresponding component in a,b,c has the same sign. If it does, they are on the same side.
The operation of 'dot product' does this automatically:
if (a*x + b*y + c*z) >0 the vectors are on the same side.
Your vector is the unit direction vector multiplied by some non-zero scalar a. If a > 0, it's in the same direction, otherwise it's in the opposite direction.