Problem importing Bezier curve coordinates in Matlab from .svg - matlab

I'm trying to draw Bezier curves from an .svg file using Matlab.
I've opened the .svg in a text editor. One of the lines I'm trying to draw is this one: <path fill="none" stroke="#000000" stroke-miterlimit="10" d="M117.125,310.375c0-77.729,80.738-140.625,180.515-140.625"/>
If I understand things correctly, the start point is (x , y) (117.125 , 310.375), the first control point is (0 , -77.729), the second control point is (80.738 , -140.625) and the end point is (180.515 , -140.625). However this doesn't seem to be correct as the output I get is far from the actual curve.
How it looks:
How it's supposed to look:
The start and end points are all right, but the control points seem wrong... Matlab draws the correct points, I've checked them (the axis may look a bit weird but it's correct)
I'm using the code from Mathworks (https://blogs.mathworks.com/graphics/2014/10/13/bezier-curves/). It needs the start point pt1, the control points pt2 and pt3 and the end point pt4.
The code works, the problem seems to lie with the coordinates of the points.
I've tried entering the coordinates above in an online .svg editor (it only supports integers so every coordinate is positive here, the control points shouldn't 'pull' the curve that much but the output is the same as the one obtained with MatLab): http://www.useragentman.com/tests/textpath/bezier-curve-construction-set.html#path=M%20297%2C%20169%20C%2058%2C%200%2C%2098%2C%2077%2C%2098%2C%20192&imageURL=http://www.useragentman.com/tests/textpath/images/grid.png
Here is the entire file, created with Illustrator CS6:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.4, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="595.28px" height="841.89px" viewBox="0 0 595.28 841.89" enable-background="new 0 0 595.28 841.89" xml:space="preserve">
<line fill="none" stroke="#000000" stroke-miterlimit="10" x1="116.083" y1="608.292" x2="117.125" y2="310.375"/>
<path fill="none" stroke="#000000" stroke-miterlimit="10" d="M117.125,310.375c0-77.729,80.738-140.625,180.515-140.625"/>
<path fill="none" stroke="#000000" stroke-miterlimit="10" d="M297.64,169.75c58.959,0,98.652,77.535,98.652,192.708"/>
<line fill="none" stroke="#000000" stroke-miterlimit="10" x1="396.292" y1="362.458" x2="387.958" y2="653.083"/>
</svg>
I'm really hoping someone can help me with this. I'm new to .svg

Thanks to #Paul LeBeau for the link. It turns out ".svg"s are case sensitive and that a C is not a c... You learn things every day. The website I looked at for help before I posted didn't mention this.
2, 3 and 4 are all relative to 1 in this case. I added a few lines of code to my script so that 2 = 1 + 2relative, 3 = 1 + 3relative and 4 = 1 + 4relative, and it works!
Now I can finally clean up my code to do both the lines and the paths at the same time and draw my racing line.
NB: I know the points are reversed for the purple curve. This is due to Illustrator not being able to do a curve "the other way round" without switching the points...

Related

SVG generation using ST_AsSVG - Transform (EPSG: 4326) to (EPSG: 3857)

I have a Django model which contains the coordinates for a polygon:
geometria = models.PolygonField(srid=4326, null=True, geography=True)
I manually took the lat-long coordinates for a polygon from the Google maps web interface and entered them into the database. I believe the gps coordinates Google maps provide are 4326.
I plotted these coordinates on google maps using #react-google-maps/api and it matches what I expected. (See below image)
Next I tried to replicate the polygon shape using Postgis, and create an SVG of it, but this is where I had problems. As you can see below the green polygon has the same basic shape, but has been stretched horizontally when compared to the output from google maps.
I believe the problem is that the svg is using the 4326 projection, instead of 3857 which is used by google maps? I have tried to transform the data in postgis, but nothing I do seems to make any difference. Note that when I create the svg without the ST_Transform, it is the same shape as below. Any ideas how I can solve this?
I am using the following SQL in Django to pull the data from the database:
cursor.execute("SELECT ST_AsSVG(ST_AsEWKT(ST_Transform(ST_AsEWKT(geometria),3857))) FROM public.locations_locationdata WHERE id= %s", [self.id])
Where geometria is the database field which contains the polygon.
I use the following python to build the svg file:
svg_string = []
svg_string.append('<svg viewBox="')
svg_string.append(calculated_view_box)
svg_string.append('" xmlns="http://www.w3.org/2000/svg" width="512" height="512" version="1.1" transform="scale(1 -1) rotate(90)" transform-origin="256 256">')
svg_string.append('<path fill="green" stroke="blue" stroke-width="1" d="')
svg_string.append(reconstruct_path_string)
svg_string.append('"/></svg>')
<svg viewBox="5735636.0 75092.0 419.0 619.0" xmlns="http://www.w3.org/2000/svg" width="512" height="512" version="1.1" transform="scale(1 -1) rotate(90)" transform-origin="256 256"><path fill="green" stroke="blue" stroke-width="1" d="M 5736044.89547394 75658.7303669334 L 5735771.38348506 75102.09404005 5735654.72065871 75164.2146256582 5735646.59433588 75700.4781146285 5735842.07136171 75663.4061145318 Z"/></svg>
Any ideas how I can fix the svg so that it matches the google maps shapes?
The problem was that I incorrectly transposed the lat and lng values when creating the GEOSGeometry object. I later fixed the transposition when passing the the lat and lng back to Google maps, which hid the problem.
See below:
#polygon = GEOSGeometry('POLYGON ((51.527768 -0.679638,51.525311 -0.674638,51.524263 -0.675196,51.524190 -0.680013,51.525946 -0.679680,51.527768 -0.679638))', srid=4326)
polygon = GEOSGeometry('POLYGON ((-0.679638 51.527768, -0.674638 51.525311, -0.675196 51.524263, -0.680013 51.524190, -0.679680 51.525946, -0.679638 51.527768))', srid=4326)
Coordinates should be (longitude latitude) pairs

Unicode character to represent "fullscreen"?

I'm sort of surprised that this doesn't exist given the sheer number of arrow-like symbols in Unicode. Have I missed something? Or is there a character that looks similar to a fullscreen icon?
There is also U+26F6 "SQUARE FOUR CORNERS" ⛶ that looks somewhat similar to this image
that you've linked. No idea what the symbol was originally supposed to stand for, though... I'm also not sure that it actually does look like four corners in all fonts, maybe it's just the font of my particular browser.
If you search for expand from the link Hans Passant commented above you'll get the below
⛶ like what Youtube uses does appear among the result
Another suggestion:
U+21F1 ⇱ North West Arrow to Corner
U+21F2 ⇲ South East Arrow to Corner
The North East and South West versions don't exist but you can rotate or mirror the available ones to create the remaining two corners. But two corners are already enough to represent a fullscreen action, you don't need to fill all four corners
Other alternatives
U+2725 ✥ FOUR CLUB-SPOKED ASTERISK
U+21F9 ⇹ LEFT RIGHT ARROW WITH VERTICAL STROKE
U+21FC ⇼ LEFT RIGHT ARROW WITH DOUBLE VERTICAL STROKE
U+2921 ⤡ NORTH WEST AND SOUTH EAST ARROW
U+1F542 🕂 CROSS POMMEE (needs some modification or a special font to make the heads more arrow-like)
↔↕ (use alone or drawn onto each other to get a cross with arrows)
⤡⤢
⇳
⤄
🡤🡥🡦🡧
🡴🡵🡶🡷
🢄🢅🢆🢇
🢔🢕🢖🢗
Some examples with arrows
Here is another variation used by the player in vtvgiaitri.vn
I guess they can be made from ◣ U+25E3 Black Lower Left Triangle and ◥ U+25E5 Black Upper Right Triangle or some of the triangles like below
◸ U+25F8 Upper Left Triangle
◹ U+25F9 Upper Right Triangle
◺ U+25FA Lower Left Triangle
◿ U+25FF Lower Right Triangle
𝅊 U+1D14A Musical Symbol Triangle Notehead Left White
𝅋 U+1D14B Musical Symbol Triangle Notehead Left Black
𝅌 U+1D14C Musical Symbol Triangle Notehead Right White
𝅍 U+1D14D Musical Symbol Triangle Notehead Right Black
𝅎 U+1D14E Musical Symbol Triangle Notehead Down White
𝅏 U+1D14F Musical Symbol Triangle Notehead Down Black
𝅐 U+1D150 Musical Symbol Triangle Notehead Up Right White
𝅑 U+1D151 Musical Symbol Triangle Notehead Up Right Black
There are also ⤧⤨⤩⤪⤭⤮⤯⤰, unfortunately they don't have the double-head arrow version, but a simple solution like ⤪⤭ might work
You can draw on shapecatcher to find more relevant solutions or look for more arrows on
https://en.wikipedia.org/wiki/Arrow_(symbol)#Arrows_in_Unicode
https://en.wikipedia.org/wiki/Arrows_(Unicode_block)
https://en.wikipedia.org/wiki/Supplemental_Arrows-A
https://en.wikipedia.org/wiki/Supplemental_Arrows-B
https://en.wikipedia.org/wiki/Supplemental_Arrows-C
FWIW, as of this writing, YouTube is using an SVG for its "SQUARE FOUR CORNERS" icon; here's the code:
<svg height="100%" version="1.1" viewBox="0 0 36 36" width="100%">
<path d="m 10,16 2,0 0,-4 4,0 0,-2 L 10,10 l 0,6 0,0 z"></path>
<path d="m 20,10 0,2 4,0 0,4 2,0 L 26,10 l -6,0 0,0 z"></path>
<path d="m 24,24 -4,0 0,2 L 26,26 l 0,-6 -2,0 0,4 0,0 z"></path>
<path d="M 12,20 10,20 10,26 l 6,0 0,-2 -4,0 0,-4 0,0 z"></path>
</svg>
You can use some of these Unicode chars:
⌈⌊⌊⌋
「」
┘┌└ ┐
╬
⛶
╭ ╮╯╰
with <sub> or <sup> + overlapping
Or arrows:
⇱⇲
⇳⇖⇗⇘⇙⇕⇔↔↕↖↗↘↙ (and other arrows...)
Here's the classic Windows "full screen" icon: 🗖
https://www.fileformat.info/info/unicode/char/1f5d6/index.htm
I'm currently using ⇱︎, which isn't great, but sort of gets the idea across. I've also played around with "merging" characters like this:
<div style="position:relative; display:inline-block;">
<div>↖</div>
<div style="position:absolute; top:0;">↗</div>
<div style="position:absolute; top:0;">↘</div>
<div style="position:absolute; top:0;">↙</div>
</div>
Which produces this:
But it'd be much nicer if there was a single character for that sort of shape.
<sup>⇱</sup><sub>⇲</sub>
⇱⇲

SVG Rendering Error in Batik/Eclipse

I have been using Batik with Eclipse for a year, and came across a rendering error I cannot seem to shake. I have reduced it to a minimal set and placed the image on flickr:https://www.flickr.com/photos/dattatreya/15019722962/. I expect to see a solid wide red line crossing a solid yellow wide line. You can see the artifact (error) in the thin yellow line that crosses the red band (along the top edge of the yellow band). I see similar errors in many images I draw.
The SVG code generated by Batik is below. Interestingly, that code was incorrectly rendered by both Safari and Chrome (but not by IE) some time ago, but right now, all browsers seem to work correctly. Only Batik does not.
This could be a Batik bug; if so, I hope they fix it soon!
SVG code generated by Batik for the image:
========================================================
<svg stroke-dasharray="none" shape-rendering="auto"
xmlns="http://www.w3.org/2000/svg" font-family="&apos;Dialog&apos;"
text-rendering="auto" fill-opacity="1" contentScriptType="text/ecmascript"
color-interpolation="auto" color-rendering="auto"
preserveAspectRatio="xMidYMid meet" font-size="12" fill="black"
xmlns:xlink="http://www.w3.org/1999/xlink" stroke="black"
image-rendering="auto" stroke-miterlimit="10" zoomAndPan="magnify"
version="1.0" stroke-linecap="square" stroke-linejoin="miter"
contentStyleType="text/css" font-style="normal" stroke-width="1"
stroke-dashoffset="0" font-weight="normal" stroke-opacity="1">
<!--Generated by the Batik Graphics2D SVG Generator-->
<defs id="genericDefs"/>
<g>
<g fill="red" stroke="red">
<path d="M-106.066 106.066 L893.934 1106.066 L1000 1212.1321 L1212.1321 1000 L1106.066 893.934 L106.066 -106.066 L0 -212.132 L-212.132 0 L-106.066 106.066 Z"
stroke="none"/>
</g>
</g>
<!--Generated by the Batik Graphics2D SVG Generator-->
<defs id="genericDefs"/>
<g>
<g fill="yellow" stroke="yellow">
<path d="M106.066 1106.066 L1106.066 106.066 L1212.1321 0 L1000 -212.132 L893.934 -106.066 L-106.066 893.934 L-212.132 1000 L0 1212.1321 L106.066 1106.066 Z"
stroke="none"/>
</g>
</g>
<!--Generated by the Batik Graphics2D SVG Generator-->
<defs id="genericDefs"/>
<g>
<defs id="defs1">
<clipPath clipPathUnits="userSpaceOnUse" id="clipPath1">
<path d="M500 287.868 L287.868 500 L287.868 500 L500 712.1321 L500 712.1321 L712.1321 500 L500 287.868 Z"/>
</clipPath>
</defs>
<g fill="red" stroke="red">
<path d="M-106.066 106.066 L893.934 1106.066 L1000 1212.1321 L1212.1321 1000 L1106.066 893.934 L106.066 -106.066 L0 -212.132 L-212.132 0 L-106.066 106.066 Z"
clip-path="url(#clipPath1)" stroke="none"/>
</g>
</g>
</svg>
=================================================================
This is not a Batik bug. It is a "problem" pretty much all graphics libraries will have whether they are SVG renderers or otherwise. It is still visible when I render this in Chrome - it's just less noticeable.
What your SVG does is:
draw a red stripe on the bottom.
then draw a yellow stripe across it
finally it draws a red square to cover the intersection of the two stripes to make it look like the red square is on top.
The reason you are seeing a barely visible yellow line is due to antialiasing. The renderer is drawing partially yellow pixels at the edge of the yellow strip to make the edge of the stripe look more smooth. When you draw the red square on top, some of the yellow pixels are going to remain visible and/or the partially red pixels being drawn on top are letting the yellow show through. The result is a yellowish strip of pixels at the edge.
I guess the question is "why are you not just drawing the red stripe on top of the yellow?" Doing that would fix your problem.

Javafx Scene Builder Linear Gradient is what

is there any one knows what on earth is the linear gradient?
How Can I use the right panel, especially the four scroll bar, to adjust the fill of the triangle on the left to make the triangle upper half white but down half black?
Is there any document to help train people how to use this? I am really sorry I can not find it.
Thanks in advance!
General info on linear gradients
The linear-gradient documentation is at:
JavaFX CSS reference.
It is a w3c color stop form.
javadoc of how linear gradients work in JavaFX.
Because the linear gradient in JavaFX CSS is the same syntax as w3c CSS, any tutorial on CSS linear gradients returned by google will probably apply to JavaFX CSS.
Feedback email address for JavaFX documentation is: javasedocs_us#oracle.com
Linear Gradients and SceneBuilder
Scene Builder uses FXML to represent linear gradients. It can also use render linear gradients from CSS, though the gradient editor in SceneBuilder works to edit the FXML representation of gradients and not the CSS representation.
Here is a result of loading the following FXML file into SceneBuilder:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.paint.*?>
<?import java.lang.*?>
<?import javafx.scene.shape.*?>
<Polygon xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<points>
<Double fx:value="-50.0" />
<Double fx:value="40.0" />
<Double fx:value="50.0" />
<Double fx:value="40.0" />
<Double fx:value="0.0" />
<Double fx:value="-60.0" />
</points>
<fill>
<LinearGradient startX="0.5" startY="0" endX="0.5" endY="1">
<stops>
<Stop color="WHITE" />
<Stop color="BLACK" offset="1.0" />
</stops>
</LinearGradient>
</fill>
</Polygon>
Scroll Bar Settings
The scroll bar settings are marking the proportional co-ordinates of the start and end properties of the linear gradient. These co-ordinates from a directional vector (line) along which colors in the linear gradient change according to the defined stops. The bars work as follows:
left bar: startY
top bar: startX
right bar: endY
bottom bar: endX
For the above fill, it means start at the top center and travel to the bottom center, varying the color from white to black as you go, so it's a straight top to bottom vertical transition.
Discrete Gradients
If you didn't want a smooth gradient, but instead wanted an abrupt one, then add more stops, for example:
<fill>
<LinearGradient endX="0.5" endY="1" startX="0.5" startY="0">
<stops>
<Stop color="WHITE" />
<Stop color="WHITE" offset="0.5"/>
<Stop color="BLACK" offset="0.5" />
<Stop color="BLACK" offset="1.0" />
</stops>
</LinearGradient>
</fill>

Resizing images in the Modelica documentation

Consider this scenario. I save a plotted curve using the save option in OMEdit Plotting Window. I want to use this image in the Documentation of the same model as a reference for others. But the issue with this is the images that are saved using this feature are very big and take up a lot of space(i.e. width and height) in the Documentation window.
I tried using the HTML code width = "xx" height = "yy". But this did not work.
Is there any way I can resize the images using HTML code in the OpenModelica Documentation?
Just for information. The size of the exported plot image depends on the size of the plot window. The plot window is a MDI container so you can resize the plot window and then can export a smaller image.
The following code works fine for me (uses the same Documentation annotation as suggested by Martin),
model documentation
annotation(Documentation(info = "<html>
<img width=\"200\" src=\"modelica://documentation/modeling.png\" />
<br />
<img width=\"100\" src=\"modelica://documentation/modeling.png\" />
</html>"));
end documentation;
Here is the sample screenshot,