Im trying to create a + sign as an SVG path for a google maps project. The plus symbol will be plotted along a polyline using the Icon path property. So far I've manage to get close, my plus symbol currently looks like a horizontal line with the vertical set at one end "-|". I need it to appear in the middle of the horizontal line to make it look like a plus.
My current path is set using the following path command:
path: 'M 0,-1 0,1 H -1,1 0,1'
How should I alter this to achieve my plus symbol? I can find lots of examples for much more complex shapes, curves, gradient fills and such forth but with my limited knowledge Im struggling to find the correct coordinates to express my shape!
I think what you want is:
path: 'M0,-1 V1 M-1,0 H1'
Which translates as start at (0, -1), draw vertically 1 unit, then move to (-1, 0) and draw horizontally 1 unit.
Whilst Im fairly sure this isn't the most succinct way to describe this path Ive managed to construct a plus sign using the following path statement [More by trial and error and some very fuzzy memories of Turtle]:
path: 'M 0,0 H 0.5,0.5 1,1 M 0,0 V 0.5,0.5 1,1 M 0,0 H -0.5,-0.5 -1,-1 M 0,0 V -0.5,-0.5 -1,-1',
Related
I am migrating from gnuplot to R plotting.
In gnuplot when a 3d is rotated the front and back of the view line up, making the appearance of 2d plot.
In plot3d() the back plane appears narrower than the front plane of the view. So , it appears like there is a distance view (tunnel vision).
R plot3d showing narrowing of view:
gnuplot showing a 3d rotated so the front and back are one:
In my plot3d() the xyz axis are all set to 30 - a cube.
The question becomes: does plot3d() have way to not have a narrowing of the perspective ?
If the answer is 'no' - OK.
If the answer is 'yes' - just point me to a link or the documentation.
I suspect you are looking for an isometric perspective; try par3d(FOV=0). From ?par3d:
‘FOV’ real. The field of view, from 0 to 179 degrees. This
controls the degree of parallax in the perspective view.
Isometric perspective corresponds to ‘FOV = 0’.
As per title.
I'm using the rgl package to plot a 3d surface.
At some point I want to clip out part of the plot, and so I use rgl::clipplanes3d. It works, but clips out the wrong side, leaving in the window just what I wanted to remove (and remove the part I was interested in).
The plane I'm using to clip is defined by:
h <- planes3d(a=0.2,b=1,c=0,d=-450)
I know it divides the surface into two parts and I want to get rid of one. But if I call
h <- clipplanes3d(a=0.2,b=1,c=0,d=-450)
the good part disappears and the wrong part stays. Is there some workaround to this, or some transformation I can apply to a, b, c, d so that clipping gets inverted?
This was a real question but I got inspired while writing it and I just found a solution.
You just have to apply, pseudocoding, (a,b,c,d) -> (-a,-b,-c,-d).
In other words, as the plane is defined by ax + by + cz + d = 0, you can multiply the equation by -1 and get the exact same plane.
However, using -a,-b,-c,-d you'll invert the half-space stripped out by rgl::clipplanes3d.
I'm looking a way to draw shapes in a Region (JavaFX8)
I've seen some examples that set the region style like this:
-fx-shape : "M 3.0313 0 L 0 74 L 7.9688 74 L 4.9375 0 L 3.0313 0 Z";
Can anyone give an explanation of the meaning of this string?
Is there any way to create this type of string using Visual Software?
The shape string is an SVG Path.
Note the shape string for a region is the shape of the region, not a shape in a region. If you want to create shapes based on paths to put in a region, then use an SVGPath and not a Region.
You can use an SVG editor to create SVG paths.
Recommending particular SVG editors is off topic for StackOverflow, try Google and you may find Inkscape (and it's option Path | Object to Path).
Problem (psuedo)
How to find the outline of a set of tiles? Let's assume we have three tiles, at the x/y coordinates A[20,20], B[20,30] and C[30,30] (this will make a simple L-shape).
Those points represent the centers of the tiles.
Each tile has 4 vertexes: TL (top left), TR, BL (bottom left) and BR.
Together, the 3 tiles have 8 unique (non-overlapping) vertexes.
We want the red line (path), defined by green dots (vertexes):
http://img7.imageshack.us/img7/2469/lshapetiles.png
Needed solution The output of the algorithm should be a path that forms the outline shape of the tiles, consisting out of these vertexes - in this order:
A TL, A TR, A BR, C TR, C BR, C BL, B BL, B TL (and optional, A TL again, to close).
See the red line.
Possible solution(s)
One option is to iterate over all the tiles, and for each tile check:
+ does it have a neighbor above? If not, at TL and TR to path
+ does it have a neighbor on the right? If not, at TR and BR to path
+ does it have a neighbor underneath? If not, at BL and BR to path
+ does it have a neighbor on the left? If not, at TL and BL to path
If you only add the found vertexes to the path if they're not added already yet, you've succesfully collected the unique vertexes for the path.
However, they might be in the wrong order. This is a (the) problem.
Does someone know of a good solution (algorithm) for this?
First, build a data structure to represent the tile structure.
Algorithm:
1 find the top-left point.
2 start from this point, iteratively find the next point by using the up, right,down,left order (in the data structure, each point contains these 4 links)
3 stop when go back the initial point.
if the graph contains separated structures, run the above algorithm for each connected component.
You can try something like this:
You iteratively build a graph representing the tiles, except for a small change -when an edge is doubled, you remove it.
So you add the first tile to the graph G, all its edges will be added. For the next tile, you add all its edges to G, but if any of its edges overlap with an edge in G, you remove that edge from G. You continue this process for all tiles.
At the end, you will only be left with "outside" edges, so you just traverse the path you have left.
I have a complicated problem and it involves an understanding of Maths I'm not confident with.
Some slight context may help. I'm building a 3D train simulator for children and it will run in the browser using WebGL. I'm trying to create a network of points to place the track assets (see image) and provide reference for the train to move along.
To help explain my problem I have created a visual representation as I am a designer who can script and not really a programmer or a mathematician:
Basically, I have 3 shapes (Figs. A, B & C) and although they have width, can be represented as a straight line for A and curves (B & C). Curves B & C are derived (bend modified) from A so are all the same length (l) which is 112. The curves (B & C) each have a radius (r) of 285.5 and the (a) angle they were bent at was 22.5°.
Each shape (A, B & C) has a registration point (start point) illustrated by the centre of the green boxes attached to each of them.
What I am trying to do is create a network of "track" starting at 0, 0 (using standard Cartesian coordinates).
My problem is where to place the next element after a curve. If it were straight track then there is no problem as I can use the length as a constant offset along the y axis but that would be boring so I need to add curves.
Fig. D. demonstrates an example of a possible track layout but please understand that I am not looking for a static answer (based on where everything is positioned in the image), I need a formula that can be applied no matter how I configure the track.
Using Fig. D. I tried to work out where to place the second curved element after the first one. I used the formula for plotting a point of the circumference of a circle given its centre coordinates and radius (Fig. E.).
I had point 1 as that was simply a case of setting the length (y position) of the straight line. I could easily work out the centre of the circle because that's just the offset y position, the offset of the radius (r) (x position) and the angle (a) which is always 22.5° (which, incidentally, was converted to Radians as per formula requirements).
After passing the values through the formula I didn't get the correct result because the formula assumed I was working anti-clockwise starting at 3 o'clock so I had to deduct 180 from (a) and convert that to Radians to get the expected result.
That did work and if I wanted to create a 180° track curve I could use the same centre point and simply deducted 22.5° from the angle each time. Great. But I want a more dynamic track layout like in Figs. D & E.
So, how would I go about working point 5 in Fig. E. because that represents the centre point for that curve segment? I simply have no idea.
Also, as a bonus question, is this the correct way to be doing this or am I over-complicating things?
This problem is the only issue stopping me from building my game and, as you can appreciate, it is a bit of a biggie so I thank anyone for their contribution in advance.
As you build up the track, the position of the next piece of track to be placed needs to be relative to location and direction of the current end of the track.
I would store an (x,y) position and an angle a to indicate the current point (with x,y starting at 0, and a starting at pi/2 radians, which corresponds to straight up in the "anticlockwise from 3-o'clock" system).
Then construct
fx = cos(a);
fy = sin(a);
lx = -sin(a);
ly = cos(a);
which correspond to the x and y components of 'forward' and 'left' vectors relative to the direction we are currently facing. If we wanted to move our position one unit forward, we would increment (x,y) by (fx, fy).
In your case, the rule for placing a straight section of track is then:
x=x+112*fx
y=y+112*fy
The rule for placing a curve is slightly more complex. For a curve turning right, we need to move forward 112*sin(22.5°), then side-step right 112*(1-cos(22.5°), then turn clockwise by 22.5°. In code,
x=x+285.206*sin(22.5*pi/180)*fx // Move forward
y=y+285.206*sin(22.5*pi/180)*fy
x=x+285.206*(1-cos(22.5*pi/180))*(-lx) // Side-step right
y=y+285.206*(1-cos(22.5*pi/180))*(-ly)
a=a-22.5*pi/180 // Turn to face new direction
Turning left is just like turning right, but with a negative angle.
To place the subsequent pieces, just run this procedure again, calculating fx,fy, lx and ly with the now-updated value of a, and then incrementing x and y depending on what type of track piece is next.
There is one other point that you might consider; in my experience, building tracks which form closed loops with these sort of pieces usually works if you stick to making 90° turns or rather symmetric layouts. However, it's quite easy to make tracks which don't quite join up, and it's not obvious to see how they should be modified to allow them to join. Something to bear in mind perhaps if your program allows children to design their own layouts.
Point 5 is equidistant from 3 as 2, but in the opposite direction.