i want to create lines on a surface using bunch of points, those lines must be in 5deg incremental
(In Catia using VBA)
here are the steps
Step:1 - first i will create lines using normal to surface option
Step:2 - then i measure the angle between normaltosurface line and xyPlane if the angle is near to 5deg mutiples number for ex if angle is 81.23deg
Step:3 - then i should create a line using point-direction option which is 80deg and if angle more than 82.5 and less than 87.5 then i should create a line using point-direction option which is 85deg to XYPlane
i need to get the X Y Z direction components (unit vectors in catia) which makes the angle between point-direction line and xyplane 5deg multiples like 80,85,90,95,100deg
the surface in the image is not actual surface
x y z components are unit vectors of line that i need to create
i know the angle, for that angle i need to find out the X Y Z unit vector values using VECTOR ROTATION IN 3D SPACE FORMULA
here is the image of that formula
here we know the value of theta using that we need to calculate X Y Z unit vector values
i need to this in VBA
I don't want to sound rude but are you looking for help with your code or are you giving assignment in hoping someone will give you solution for free ?
Anyway to get the direction vectors you can use something like this
Dim TempVariant As Variant
Dim aOrigin(2) As Variant
Dim aDirection(2) As Variant
Dim NewLine As HybridShapeLineNormal
Set NewLine = ShapeFactory.AddNewLineNormal(RefSurface, PointReference, 0, 1, VectorOrient)
Set TempVariant = NewLine
Call TempVariant.GetOrigin(aOrigin) 'get starting point x y z
Call TempVariant.GetDirection(aDirection) 'get vectors x y z
EDIT
If you want to deal with 3D rotation you can take a look at this excel.
It took me a while myself (about week) and I found this excel somewhere years ago which helped me ... therefore I'm unable to give credits for this.
Excel Euler angles
Related
Say you have the matrix given by three arrays, being:
x = N-dimensional array.
y = M-dimensional array.
And z is a set of "somewhat random" values from -0.3 to 0.3 in a NxM shape. I need to create a plot in which the x values are in the x-axis, y values are in the y-axis and using z as the source to indicate the intensity of each pixel with a color map.
So far, I have tried using
plt.contourf(x,y,z)
and the resulting plot is very nice for me (attached at the end of this paragraph), but a smoothing is automatically applied to the plot! I need to be able to distinguish the pixels and I cannot find a way to do it.
contourf result
I have also studied the possibility of using
ax.matshow(z)
in order to sucesfully see the pixels... but then I am struggling trying to personalize the x and y axis, since only the index of the pixel is shown (see below).
matshow result
Would you please give me some ideas? Thank you.
Without more information on your x,y data it's hard to know, but I would guess you are looking for pcolormesh.
plt.pcolormesh(x,y,z)
This would take the x and y data as input and hence shows the z data at the appropriate coordinates.
You can use imshow with the keyword interpolation='nearest'.
plt.imshow(z, interpolation='nearest')
The application I'm currently working on will provide the ability to take unknown values based on known values from a line graph. Here's the problem. The line graph will not exist theoretically. But the information provided and past data will be used to be able to find that unknown.
For example
x axis: known
y axis: unknown
plotted line graph: partially known
So in actuality we can draw a graph with the x, y axis and plot the line graph with what we actually know. So say our knowns are:
x axis: 10; y axis: 15; plot: 160 line
x axis: 12.7; y axis: 18; plot: 160 line
x axis: 15; y axis: 22; plot: 160 line
so if we drew this, anything between 10-15 we could detect the y axis by straight line up to the 160 line and then accross to the y axis to find the answer. Thus, more inputted information would eventually lead to every possibility between 1-100 to be answerable.
However, my issue is that in the sense of programatical logic I can't think of where to start. For instance, I'll have my known values such as;
x = 10; plot = 160; therefore y = 15
And could be said for the other examples, though how can I manipulate them numbers to find unknowns which I would find on the graph with a simple ruler?
So programatically it would look like
x = 13; plot = 160; therefore y = ?;
If anyone has much experience with line graphs or at least with the formulae to unknowns it would be great if you could provide me with some starting information or point me in the right direction. As of right now, I have no idea where to start.
edit;
I'm coming to the conclusion that I will have to interpolate between the two y known values for a ratio of x difference?
so for instance, an input of 13 would show as
input: 13; find closest less-than to that; find closest greater-than to that;
returns 12.7 and 15
now find a ratio difference between them
take their known y values
lowest: 18; highest: 22
now lerp(double lowest, double highest, double ratio of difference between xs
Do I appear to be taking the right path?
Polynomial Interpolation
y = y0+(y1+y0)*((x-x0)/(x1+x0));
I'm making a program in which many weird shapes are drawn onto a canvas. Right now i'm trying to implement the last, and possebly hardest, one.
In this particular shape i need a way to find the location (on a 2d canvas) where the line hits the shape. The following image is an example of what i have right now.
The black dots are the points that a known to me (i also have the location of the center of the three open circles and the radius of these circles). Each of the three outer lines needs a line towards the center dot, ending at the point that it hits the circle. This shape can be turned 90, 180 or 270 degrees.
The shape should look something like the following:
If you need any other information, please ask me in the comments. I'm not very good at math so please be gentle, thanks!
If A and B are points forming a line, then you can describe any point on that line using coordinates:
x = t·Ax + (1−t)·Bx
y = t·Ay + (1−t)·By
0 ≤ t ≤ 1
You can also describe the circle with center M and radius r as
(x − Mx)2 + (y − My)2 = r2
So take the x and y from the equations of the line, and plug them into the equation of the circle. You obtain a quadratic equation in t. Its two solutions describe the two points of intersection between the line and circle. In your example, only one of them lies on the line segment, i.e. satisfies 0 ≤ t ≤ 1. The other describes a point on the extension of the segment past its endpoint. Take the correct value for t back to the equations of the line, and you obtain the x and y coordinates of the point of intersection.
If you don't know up front which circle you want to intersect with a given line, then intersect all three and choose the most appropriate point afterwards. Probably that is the point closest to the outside starting point of the line segment. The same goes in cases where both points of intersection lie on the segment.
I am trying to plot a matrix in Gnuplot as I would using imshow in Matplotlib. That means I just want to plot the actual matrix values, not the interpolation between values. I have been able to do this by trying
splot "file.dat" u 1:2:3 ps 5 pt 5 palette
This way we are telling the program to use columns 1,2 and 3 in the file, use squares of size 5 and space the points with very narrow gaps. However the points in my dataset are not evenly spaced and hence I get discontinuities.
Anyone a method of plotting matrix values in gnuplot regardless of not evenly spaced in Xa and y axes?
Gnuplot doesn't need to have evenly space X and Y axes. ( see another one of my answers: https://stackoverflow.com/a/10690041/748858 ). I frequently deal with grids that look like x[i] = f_x(i) and y[j] = f_y(j). This is quite trivial to plot, the datafile just looks like:
#datafile.dat
x1 y1 z11
x1 y2 z12
...
x1 yN z1N
#<--- blank line (leave these comments out of your datafile ;)
x2 y1 z21
x2 y2 z22
...
x2 yN z2N
#<--- blank line
...
...
#<--- blank line
xN y1 zN1
...
xN yN zNN
(note the blank lines)
A datafile like that can be plotted as:
set view map
splot "datafile.dat" u 1:2:3 w pm3d
the option set pm3d corners2color can be used to fine tune which corner you want to color the rectangle created.
Also note that you could make essentially the same plot doing this:
set view map
plot "datafile.dat" u 1:2:3 w image
Although I don't use this one myself, so it might fail with a non-equally spaced rectangular grid (you'll need to try it).
Response to your comment
Yes, pm3d does generate (M-1)x(N-1) quadrilaterals as you've alluded to in your comment -- It takes the 4 corners and (by default) averages their value to assign a color. You seem to dislike this -- although (in most cases) I doubt you'd be able to tell a difference in the plot for reasonably large M and N (larger than 20). So, before we go on, you may want to ask yourself if it is really necessary to plot EVERY POINT.
That being said, with a little work, gnuplot can still do what you want. The solution is to specify that a particular corner is to be used to assign the color to the entire quadrilateral.
#specify that the first corner should be used for coloring the quadrilateral
set pm3d corners2color c1 #could also be c2,c3, or c4.
Then simply append the last row and last column of your matrix to plot it twice (making up an extra gridpoint to accommodate the larger dataset. You're not quite there yet, you still need to shift your grid values by half a cell so that your quadrilaterals are centered on the point in question -- which way you shift the cells depends on your choice of corner (c1,c2,c3,c4) -- You'll need to play around with it to figure out which one you want.
Note that the problem here isn't gnuplot. It's that there isn't enough information in the datafile to construct an MxN surface given MxN triples. At each point, you need to know it's position (x,y) it's value (z) and also the size of the quadrilateral to be draw there -- which is more information than you've packed into the file. Of course, you can guess the size in the interior points (just meet halfway), but there's no guessing on the exterior points. but why not just use the size of the next interior point?. That's a good question, and it would (typically) work well for rectangular grids, but that is only a special case (although a common one) -- which would (likely) fail miserably for many other grids. The point is that gnuplot decided that averaging the corners is typically "close enough", but then gives you the option to change it.
See the explanation for the input data here. You may have to change your data file's format accordingly.
I'm creating simple game and reached the point where I feel helpless. I was good in geometry but it was long time back in school, now trying to refresh my mind.
Let's say i have iPad screen. Object's xy position at one given point of time and xy position at another point of time stored in 2 variables .
Question:
how to find the third position of the object at the end of the screen being given previous 2 position, considering the object moves in the same direction (line) from point 1 to point 2.
Thanks in advance.
Let us have that v1 and v2 are the vectors representing the two points. Let t0 be the time between the two points. Let t be the current time.
Then our location vector v3 is given by v3 = v1 + (v2 - v1)t/t0
If the object is moving in the same direction and you have an horizontal line, the next position given x and y would be
x+1, y
If the object is moving in the same direction in a vertical line it would be
x, y+1
If the object is moving in a diagonal up-right
x+1,y+1
diagonal down-right
x+1, y+1
diagonal down-left
x-1, y-1
diagonal up-left
x-1, y+1
So something general would be :
newPosition = (x+1,y) //if you wish to move forward to the right, try to handle all
cases
All the cases above work if the object is moving forward, if it is moving backwards just change the + by - . Basically think of the object as moving in a cartesian coordinate system, where x is horizontal and y is vertical.
I think you can get the idea out of this three cases ;)