I'm starting my adventure with java3d.
I'm getting unexpected results when creating my own Shape3D. I set geometry with following points (exactly in this order):
1 - (0.0, 0.5, 0.0),
2 - (0.0, 0.25, 0.4330127018922193),
3 - (0.0, -0.25, 0.43301270189221935),
4 - (0.0, -0.5, 0.0),
5 - (0.411819551773166, -0.25, 0.13380828366490874),
6 - (0.4118195517731659, 0.25, 0.13380828366490874)
There are more, but it's enough to present the situation. If you draw/imagine it you will have points 1 and 4 in one Y line, and 2,3,5,6 creating a rectangle.
What I need to achieve is to have a plane connecting:
Point 1
Line from 2 to 6
Line from 3 to 5
Point 4
I got almost this, it's hard to explain so I'll attach a picture:
As you can see, the plane goes through line connecting 4-2 and 5-2 instead of 5-3.
Anybody have an idea how to fix it? I can provide more code if necessary, but I didn't want to put everything and didn't know which part might interest you.
It's not what I wanted, but I've found a workaround.
I put points in following order (numbers taken from question):
1,2,6,6,2,3,5,5,3,4
And I set stripCounts filled like this:
3,4,3
It produces more smaller particles but it's working and after additional work can be generic.
If no better answer appears, I'll accept my own.
Related
I have a parametric surface in 3D. I would like to observe parts of this surface, specifically, the part with z > 0 and the part with x2 + y2 + z2 < c.
A few methods that I tried:
Naïvely throwing away the rest of the data, for instance setting X[Z<0] = nan etc. Since this does not line up with the parametrization that I chose, it would create ragged edges. Is there some sort of "antialiasing" interpolation options that I can choose? I would be grateful for a pointer to the docs for numpy or plotly.
Trying to set the alpha of the color scale. This sort of works, it seems to introduce some incorrect rendering. In the picture below, the dark green lump should be at the front of the light green disk. Is there something that I did wrong?
On the other hand, I couldn't locate in the manual a way to set "two dimensional" color scales, so that I can simultaneously set the opacity according to the z value and the hue according to some other quantity of interest. Is this possible?
Is there a convenient method to achieve my goal? Or can I improve my attempts above? Any help is appreciated!
I have a question about how to remove some "unnecessary" coordinates from a "maps.txt" file using segment line, projection vector or other method.
Path Created on Google Maps:
Map1
Total of 275 coordinates, extracted from the ".KML" file of Google Maps.
Map1_2
Map2
When I do it manually it stays that way (Map2), with 9 coordinates.
I have a file called "maps.txt" where its lines, with coordinates, are in this format:
Obs: A coordinate on each line: latitude, longitude.
-37.2012600, -59.8404600
-37.2000200, -59.8419600
-37.1985300, -59.8439200
-37.1970600, -59.8458500
-37.1959100, -59.8473500
-37.1957800, -59.8475200
-37.1948600, -59.8486900
-37.1939500, -59.8498600
-37.1931400, -59.8509400
-37.1928400, -59.8513100
-37.1926700, -59.8515000
-37.1924600, -59.8517200
-37.1922600, -59.8519200
Is there any way for a code to read my file "maps.txt" and do the line segment, vector projection, point distance calculation using a radius of 100 meters?
In case the code would "remove the line / unnecessary coordinate" from the file "maps.txt", leaving it this way (just an example):
-37.2012600, -59.8404600
-37.1948600, -59.8486900
-37.1922600, -59.8519200
In Python, C, C ++ or another language.
I hope I have been clear and thank you in advance for any help.
Thank you (:
I'll try to explain better.
In the following figure I have 3 coordinates (1, 2 and 3).
The coordinate "1" has a radius within 100m with respect to the "2" coordinate, but from "1" to "3" I have a value greater than 100m, ie in this case the coordinate "1", "2" "and" 3 "in my text file" maps.txt ".
Example1
In the following figure from example 2, I would need only the coordinates "1" and "3" in the file "maps.txt".
Example2
Update:
Here's a script that converts KML to GPX: https://gist.github.com/timabell/8791116
And here's a Python script that seems like it'll do what you want (for GPX files): https://wiki.openstreetmap.org/wiki/User:Travelling_salesman/gpx_reduce
Previous answer:
I don't know how far you're asking us to take our answers; this problem is slightly complex, so here's some pseudocode for starters:
Overall algorithm:
Vector from point 1 to 3. Check distance of point 2 from this vector. (Assuming threshold is okay)
Vector from point 1 to 4. Check distance of points 2 and 3 from this vector. (Assuming threshold is okay)
Vector from point 1 to 5. Check distance of points 2, 3, and 4 from this vector. (Assuming threshold is bad)
First vector is determined: it's from point 1 to 4. Second vector starts at point 4.
Vector from point 4 to 6. Check distance of point 5 from this vector.
Vector from point 4 to 7. Check distance of points 5 and 6 from this vector.
...
Distance of point from vector:
At this point, we need to make a decision:
If we want this to be (quite) exact, we have to find a line that is perpendicular to our line and goes through this point, and find the intersection of these two lines. Then, we calculate the distance using the haversine formula between the intersection and the point. (Unless we sometimes have longer distances between coordinates, I don't think we need this.)
If we don't care too much about exactness, we use the following formula to calculate the "distance", and then "experimentally" find a good threshold value that works for us. (This threshold value is just some float number that we use when checking the distance. If it's above the threshold value, we start a new line.)
https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line#Line_defined_by_two_points
(Where (x0, y0) is the point we're investigating, and the line goes through (x1, y1) and (x2, y2).)
Without getting into too many details - I'm getting parameters (x1,x2,y1,y2,a,b,α) from a web tool and I need to generate a PDF document, by using Zend_PDF library which contains green image rotated and positioned properly on the exact coordinates.
Now, what confuses me is that Zend does not allow elements to be rotated, but instead rotates paper. So, I assume the rotation needs to be done like this
$page->rotate($x1 + ($x2 - $x1) / 2, $y1 + ($y2 - $y1) / 2, - deg2rad($rotation));
because we want the center of the image to be the rotation point, and we rotate it in the reverse orientation so the resulting image will get proper rotation.
The tricky part I'm having trouble with is drawing it. With the simple call
$page->drawImage($image, $x1, $y1, $x2, $y2);
I'm getting the result as displayed on the diagram - the resulting image needs to be translated as well, since (x1,y1) and (x2,y2) are not exact coordinates anymore, but I'm not sure how to calculate them? Any ideas?
The OP confirmed in a comment that he used the same values for (x1,y1) and (X2,y2) in his rotate and his drawImage calls. It is pretty obvious from his sketches, though, that the coordinates for the latter call must differ.
Fortunately we know from the way the green rectangle is inscribed in the rectangle from (x1,y1) to (X2,y2) that it has the same center point as that rectangle. Furthermore, we have the dimensions a and b of the green rectangle.
Thus, the drawImage parameters must be changed to:
$page->drawImage($image, $x1 + ($x2 - $x1) / 2 - $a / 2
, $y1 + ($y2 - $y1) / 2 - $b / 2
, $x1 + ($x2 - $x1) / 2 + $a / 2
, $y1 + ($y2 - $y1) / 2 + $b / 2);
I have searched extensively online and I have the PDF specification in which I have looked, yet I still can't figure out how to draw a simple black line on a PDF page from the content object's instructions (stream).
Let's say I just want to draw a 1-pixel thickness (assuming 72 dpi) black line at x 400, y 100-300.
This should in theory be a very simple operation, but the PDF spec goes on and on about all kinds of fancy things and appears to forget to explain how I would go about performing this simple operation.
Please can someone point me in the right direction?
In the PDF specification, have a look at chapter 8 (Graphics) and in there section 8.5, Path Construction and Painting.
To draw a simple straight path, you need a "move to" operation followed by a "line to" operation:
400 100 m
400 300 l
You can then stroke the path using the S operator so your code becomes
400 100 m
400 300 l
S
By default the color is black so you've already gotten a black line :-) But if you want to make sure you have to set some parameters in the graphics state.
0 G
1 w
400 100 m
400 300 l
S
The first line now sets the color space to "gray" and puts the shade of grey to 0 (black). The following line sets the line width of your stroked line to 1 user unit (what this comes out as is dependent on your current transformation matrix.
You can apply a neat trick if you really want 1 pixel (please don't for production files though!) and that is to set the width to zero:
0 w
This gives you "the thinnest line that can be rendered at device resolution: 1 device pixel wide".
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.