Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define points with irrational coordinates in SVG?

Tags:

svg

Let's say I want to draw a sqare in svg which has a diagonal of 1. That means the edges of the square would have a length of a = 1/sqrt(2). The coordinates of the square's vertices then would be: (0,0), (0,a), (a,0) and (a,a). Of course I could approximate a with a decimal number and use this number. But what if I want the vertices to be mathematically precise, for example because I want them to be exactly on some line I know to go through the intended point?

I'm totally new to SVG. I was reading up on transformations here, hoping to get some pointers, but it got me confused.

Does anyone know if this can be done and if so, how?

like image 580
Rinke Avatar asked Feb 04 '12 13:02

Rinke


1 Answers

SVG doesn't support anything like that.

But you'll get pretty good precision from a floating point approximation. There won't be very many scenarios where you'll see the errors once the SVG is rendered, unless you are magnifying it a lot.

If the svg is embedded in web page - and if you are noticing errors under high magnification - you could consider modifying the SVG dynamically with JavaScript, rather than applying SVG transforms.

like image 114
Peter Hall Avatar answered Nov 02 '22 23:11

Peter Hall