I have an image and I'm trying to store the pixel colors for a set of points along a line into an array.
The endpoints of the line and the distance between points is given. I know that the command line(x1,y1,x2,y2) draws a line between (x1,y1) and (x2,y2). I also know that .get() applied to an image returns the pixel color at the specified location.
I am unsure how to put it all together.
Essentially the problem is in two parts:
working out which pixel of the image you are over at each point along the line
Reading out that pixel value and storing it in an array
The second is fairly simple: https://processing.org/reference/PImage_get_.html will give you all the info you need about getting the pixel values at a certain coordinate.
The first is a maths problem essentially.
The line you draw will have the equation: Y = m * X + C where C is the intercept of the X axis and M is its gradient.
(One thing to remember is that the origin (0,0) for a processing sketch is at the top left)
https://www.mathsisfun.com/algebra/line-equation-2points.html is a good resource for this. The basic methodology is to calculate the gradient M and then set Y to 0 and equate m * X = -C
I have two arrays of strings: these two arrays contain the labels that are to be inserted on the x and y axis (these labels will be those of a heatmap).
nutsNames corresponds to the x axis (left to right) and the yearsNames corresponds to the y axis (top to bottom).
As the data may vary, I would like to create a way that fits the data.
So the problem is the positioning of the elements on the axes and the svg size.
What I would like to get is something like this:
The image shows two examples of different data.
(I don't want to show axes, I put them only to understand what is their direction).
Here is the plunker.
I thought about finding the longest string in nutsNames and multiplying it by a constant (which I don't know how to define) to create the minimum necessary width of the svg.
A similar thing I did it for years.
Obviously the code doesn't work.
What you can do is input some dummy numbers for the width,height and margins and let it draw the elements first. Now since all your axis labels are in a g , you can get the width of gs for x and y labels.
The group<g> tag wraps the contents inside it so getting its width/height will automatically give you the width/height of the largest text inside it.
Now you have the width and height of those gs, all that's left is to change the dimensions of the svg accordingly.
Try adding or removing labels in your data. Here's your Plunker
I know that I can vary marker position using mlabv() and creating a position variable for individual points on my twoway scatter plot.
Is there a way to do a similar thing for mlabgap()?
I am trying to have certain points' labels a little further away from the rest to avoid overprinting.
http://www.stata.com/help.cgi?marker_label_options implies that the gap is constant in each graph call.
That does not rule out e.g.
scatter y x if group == 1. mlabel(foo) mlabgap(1) ///
|| scatter y x if group == 2, mlabel(foo) mlabgap(2)
Another trick is adding spaces as prefix or suffix to the marker label variable in various observations as needed.
I have these two parameters, (parameter 1 and parameter 2) that I want to compare them through time and examine the effect of them on each other. I am using objects of class cOutVector (using record() method)
I want to put the values of these two parameters in one graph as Y axis and time as X axis.
The second type of graph is comprised of parameter 1 on X axis and parameter 2 on Y axis. Is it possible to do this type of graph?
Thanks for your help!
Have You tried to use R? It is the perfect thing for statistical computing and plotting Your data.
Try it - You'll solve Your problem with this. OMNeT provides a extra packet for the R environment, which helps You to analyse the cOutVector structure.
A tutorial can be found here
Given a group of 3D models spatially arranged in a specific formation, how do I scale them while preserving the relative distances between each other?
Case in point: I have 10 meshes. Six of them are arranged to form a closed square room. The remaining 4 are pieces of furniture placed at appropriate locations inside it. All meshes have a scale of 1.0. I wish to increase it to, say 2.0.
I am not a mathematician, so I'm going to use the most basic terminology I know how to explain the procedure. You may even find the simplicity of the terminology I use easier to understand than mathematic "jargon"
You need to use the nominal centre points of all objects in the formation to determine the exact Formation Centre (this will be, of course, a 3D Vector consisting of an X, Y and Z value)...
Object Total = The total number of objects within your "formation"
Cycle through all objects in your formation
For each object (to calculate Axis Total)
Add the X co-ordinates together (gives us Axis Total X)
Add the Y co-ordinates together (gives us Axis Total Y)
Add the Z co-ordinates together (gives us Axis Total Z)
For each Axis Total axis (to calculate Formation Centre)
Formation Centre X = Axis Total X divided by Object Total
Formation Centre Y = Axis Total Y divided by Object Total
Formation Centre Z = Axis Total Z divided by Object Total
The three values you now have constitute the Formation Centre (as a 3D vector).
NOTE: If you are arranging your objects based on a pre-defined fixed point in 3D space (0, 0, 0 for example) you don't need to do the above calculation, as your Formation Centre will be that fixed point.
for each object
Calculate the Distance of each axis (Distance X, Distance Y and Distance Z) of the Object Centre from the according axis of Formation Centre...
Distance X = Formation Centre X - Object Position X
Distance Y = Formation Centre Y - Object Position Y
Distance Z = Formation Centre Z - Object Position Z
Scale the object by your desired Scale Factor
Set the X, Y and Z Position values to their current value plus the distance value of the same axis multiplied by the scale...
Position X = Position X + (Distance X * Scale Factor)
Position Y = Position Y + (Distance Y * Scale Factor)
Position Z = Position Z + (Distance Z * Scale Factor)
If you've done this correctly, your objects have now been scaled, still retain their formation, but have moved relative to the Formation Centre and Scale Factor. Simply put: occlusion between these objects can no longer occur as their Positions have scaled along with their Dimensions.
To really answer this, we still need a bit more information about the format of your data and how you're applying transformations. But here's a guess:
Your objects are most likely represented as collection of polygons which are themselves represented as a collection of points relative to some 'root point' such as the center of the object or a bottom corner. When you place the object somewhere, like a room, you can do so by applying a sequence of matrix multiplications to the points that represent the object. A single matrix multiply can usually do the whole transformation, but it makes more sense to us if we compose a sequence of transformations that do intuitive things. For example, you would usually
Scale the object to be the size you want.
Rotate the object to be oriented the way you want.
Translate the object to be where you want.
All of these transformations happen relative to the 'root point' of the object and their order makes a big difference. If you translate and then scale or rotate, the scale and rotate will happen relative to the newly translated center.
So, if you have placed objects in a room, and [0,0,0] of your coordinate system happens to be in the center of the room, if you scale all of the transformed points of those objects, they will all grow/shrink and push outward/inward from [0,0,0]. Since that's not what you want, you must first change the origin by translating the object, then scale, then change the origin back to where it was.
If I have two points: [3,0,0] and [4,0,0] and I want to scale them so that the distance between them is 2 instead of 1, if I just multiply (scale) by 2, I get [6,0,0] and [8,0,0]. There's a distance of 2 between them now, but they both moved. If I want the first point to stay put, then I first translate by [-3,0,0], then I scale by 2, then I translate by [3,0,0] and I have what I wanted. If, instead, I want the center of those two points to remain the same, then I translate by [(+/-)3.5,0,0].
It falls on you to decide which points of the objects should not move. Then you move that point to the origin before scaling. Then you move it back afterward. Since you don't want your objects to push through the floor, you'll probably pick a point on the ground (or whatever surface they're attached to). If you have one object resting on another (books on a desk) then those objects should probably use the same reference point.