I'm coding on a specialized motion controller hardware which uses a subset of Visual Basic language as its programming language. I need to make some calculations on given points, like getting center coordinates of an arc that is passing through 3 distinct points; shifting lines, getting intersection coordinates of 2 lines etc...

I'm using cartesian coordinate system for calculations. It seems that the code will get bloated while handling `divide by zero`

cases.

So, what is the best coordinate system for such calculations? Or what is the best approach to keep such code small?

The code giving center point coordinates of an arc that is passing through 3 points is as follows:

```
' p1: (px1, py1) p2: (px2, py2) p3: (px3, py3)
' ----------------------------------------------
m_r=(py2-py1)/(px2-px1) ' slope of the line between p1 and p2
m_t=(py3-py2)/(px3-px2) ' slope of the line between p2 and p3
center_x=(m_r*m_t*(py3-py1)+m_r*(px2+px3)-m_t*(px1+px2))/(2*(m_r-m_t))
center_y=(-1/m_r)*(x_mrk-(px1+px2)/2)+(py1+py2)/2
```

As you can see, there are many cases that will cause a `divide by zero`

exception. Should I use `if/else`

structure or is there a better way?

Answer:

When you calculate center point of an arc that is passing through 3 points, you definitely need to check if these points lies on the same line. But rewrite expression

```
if (py2-py1)/(px2-px1) = (py3-py2)/(px3-px2)
```

to avoid dividing

```
Det = (py2-py1) * (px3-px2) - (py3-py2) * (px2-px1)
if Det = 0 then ... `bad case
```

for else case (Det<>0) arc exists, and you can find center coordinates without zero-divide errors

```
center_x= ((py2-py1) * (py3-py2) * (py3-py1) +
(py2-py1) *(px2+px3) * (px3-px2) -
(py3-py2) * (px1+px2) * (px2-px1)) / (2 * Det)
```

math,geometry

I have a line and point (2D). Ok, using Paul Bourke formula I can get the distance of ortogonal projection of point to the line. ( Also I can know if the solution is or not inside the segment of line. ) OK, But I'd like to know if the...

javafx,geometry

I thought I'd use the Point2D class for calculating e. g. the angle betwen 2 points instead of creating a utility method. It turned out, it's not usable at all. Code example: Point2D p1; Point2D p2; p1 = new Point2D(0, 0); p2 = new Point2D(10, 10); System.out.println( "Point2D: " +...

sql-server,oracle,ssis,geometry

Ihave some geometry datatype entries in one of my table in a Oracle database.I would need to import those data into a sql server table to then use them for something else. I am aware that I cannot do that with an ssis package.There might also be some conversion problems.Could...

merge,three.js,geometry,rendering,mesh

I am trying to make a coil with several small loops. I have a custom function to create a single helix for each loop, and at first I was calling that within a for loop several hundred times, but it was taking too long to render and slowed down the...

javascript,geometry

I want to calculate the radius of an inverted circle. I managed to implement everything but, after hours of struggle, I could not find a formula to calculate the correct inverted radius. More info about circle inversion: http://en.wikipedia.org/wiki/Inversive_geometry https://www.youtube.com/watch?v=sG_6nlMZ8f4 My code so far: http://codepen.io/rafaelcastrocouto/pen/Mwjdga It seems to be working but...

merge,three.js,geometry,selection,octree

I am using Three.js to show a number of custom geometry's in various positions and rotations. They are static and rarely change, but the user can add, delete or change the shape of each individual object. This has worked well using the code snippet below: var Mat=new THREE.MeshBasicMaterial( { color:...

javascript,geometry,computational-geometry,famo.us

I'm trying to place six circles around a center circle. Eeach of them has the same diameter so it should be possible to place them around the center without space between or overlaps. I thinking to be close to the solution but there are small overlaps. I can't find an...

javascript,arrays,geometry

I want an array looking like this: [ [0,0,1,1,1,0,0], [0,1,1,1,1,1,0], [1,1,1,1,1,1,1], [1,1,1,1,1,1,1], [1,1,1,1,1,1,1], [0,1,1,1,1,1,0], [0,0,1,1,1,0,0], ] My first approach was to get the circumference var steps = 100; var coord = []; var x,y; for (var i = 0; i < steps; i++) { var phase = 2 * Math.PI...

c++,geometry,quaternions,euler-angles

I've been trying to figure out the difference between these, and why ToEulerXYZ does not get the right rotation. Using MathGeoLib: axisX: x 0.80878228 float y -0.58810818 float z 0.00000000 float axisY: x 0.58811820 float y 0.80877501 float z 0.00000000 float axisZ: x 0.00000000 float y 0.00000000 float z 1.0000000...

c#,order,geometry,polygon,intersection

I was wondering if there is a method to order intersection points in a list based on the direction of the intersected line. Here is a picture to get the idea: The red numbers are the polygon lines which exist in a List. Then I have another List with lines...

image,matlab,image-processing,matlab-figure,coordinate-systems

How to find the relation between image imrotated with loose option Image 1 and image imrotated with crop option Image 2 ? the angle of rotation is not necessary -45° ... I = imread('cameraman.tif'); Im1 = imrotate(I,-45); % bbox option sets to 'loose' by default Im2 = imrotate(I,-45,'nearest','crop'); % bbox...

algorithm,geometry

I'm plotting data in matplotlib that the user can interact with via a lasso, which is internally represented as a list of vertices that make up a polygonal chain. What I would like to be able to do is to trim lassos as illustrated in this highly professional picture: Formally,...

ios,coordinate-systems,cgpoint,icarousel,coordinate-transformation

I wanted to add a possibility to drag elements inside the carousel and I have some troubles with positioning and transformations of a draggable element. As I understand it is better to temporarily hide/delete the draggable element and create its proxy outside the carousel item array which represents the position...

algorithm,3d,geometry,distance,computational-geometry

For an ellipsoid of the form with orientation vector and centre at point , how to find whether a point is inside the ellipsoid or not? An additional note that the geometry actually is with a=b (spheroid) and therefore one axis is sufficient to define orientation Note: I see a...

c++,geometry,rounding,cgal,convex

I'm making a little app to analyze geometry. In one part of my program, I use an algorithm that has to have a convex object as input. Luckily, all my objects are initially convex, but some are just barely so (see image). After I apply some transformations, my algorithm fails...

geometry

I have islands in my game defined by an array of vertices. I would like to create a larger version of them to make a type of "shore", mainly for cosmetic purposes, while keeping the original shape intact to use for collision purposes. I have tried dilating it point by...

c#,wpf,geometry

I am attempting to create a shape like the following: For the curves of the spiral, I am utilizing Quadratic Bezier Segments. PathGeometry pg1 = new PathGeometry(); PathFigure pf1 = new PathFigure() { StartPoint = new Point(Convert.ToDouble(middle) + 500, Convert.ToDouble(middle) + 500) }; PathSegmentCollection psc1= new PathSegmentCollection(); QuadraticBezierSegment arcs1 =...

android,algorithm,geometry,figure

I'm creating an Android app which simulates petri nets. I'm representing place by circle and transition by square and I'm connecting those views by arc (it's just the name from petri nets for my purpose it's just a straight line) and here's the problem I'm facing, I know how to...

math,javafx,geometry,coordinates

I have a line which has points (x1,y1) and (x2,y2). I wanted to attach a Button to it, it should align with the line by rotating based on the line segment points. I need some help in calculating the rotation angle for the Button.

geometry

We have a red circle with radius 10. On this red cicle, there is 3 other circles in blue (radius 8) that are equally spaced by 120°. The point C is the middle of two blue circle and has a green circle (radius 2). I need to find the coordinate...

geometry,intersection,lines

I found this code snippet on raywenderlich.com, however the link to the explanation wasn't valid anymore. I "translated" the answer into Swift, I hope you can understand, it's actually quite easy even without knowing the language. Could anyone explain what exactly is going on here? Thanks for any help. class...

c#,selection,picturebox,coordinate-systems

I have two PictureBoxes pbOriginal and pbFace. After Selecting a "face" from an image in pbOriginal I clone the rectangle selection and place it into pbFace. However, Because pbOriginal is using SelectionMode=Stretch the actual area being copied is not the same as the area being selected. How do I convert...

sql,sql-server,geometry

I am building a stored procedure for SQL Server 2014. All works as expected except I receive an error when trying to use a geometry type to base the location results upon. USE UKStreetsAndPlaces GO DECLARE @Latitude Decimal(9,6) = 51.3083162 DECLARE @Longitude Decimal(9,6) = -0.7799193 DECLARE @LongitudeOperator AS NVARCHAR(1) DECLARE...

c++,math,geometry,angle

C++, I want calculate the angle of the direction of the two points. Here is a picture which shows the two points and the direction of how to get the angle of the direction? p1 - start point. p2 - direction point. me need direction angle(facing?) from p1 to p2...

geometry,coordinate

I have the following problem: I have a list of all the x, y coordinates of a polygon's points. I now need to sort them in such a way that I obtain the points in a clockwise order. Currently I have the 6 coordinates to draw a polygon but its...

algorithm,geometry,computational-geometry,mesh,3d-model

I am working with a serialization pipeline. I am taking a model and exporting it. I do not wish to export any model with a hole in a face. How would I detect a hole and report a error? I have access to all vertexes, edges, faces etc. Here is...

c++,geometry

I have a 2D point A inside the [0,1]² square. The square is divided into 9 subsquares (of equal dimensions) http://www.noelshack.com/2015-23-1433689273-capture.png I want to know which subsquare the point A belongs to. I can do a if elseif else on the first coordinate, then inside each branch, another if else...

c++,matrix,rotation,geometry,axis

I'm trying to figure out how to reverse RotateAxisAngle to get back rotations around these arbitrary axes (or equivalent rotations that yield same net rotation, doesn't have to be identical). Does anyone know how to do it? I'm using MathGeoLib, but I don't see an opposite way, to return back...

python,geometry,networkx,sympy

OK. I have the points that comprise the borders of a polygon. I want to (a) use Sympy's geometry module to determine, from all of the possible line-segments between any pair of points, which segments do not cross the perimeter. This result will be the "edges" that are allowed to...

actionscript-3,geometry,displayobject,angles

I want to make a symbol rotate to point at the mouse. I'm using this function, but it doesn't work below the symbol's pivot. The inverse tan function has a range of 180 degrees right? So how can i get 360 degrees of movement? Would I need to add an...

sql,oracle,geometry

I have a single Geometry Field in a table select g3e_GEOMETRY from MyTable where g3e_FID = 15463352 This returns (3001, , (, , ), (1, 1, 1, 4, 1, 0, , , , , , , , , , , , , , , , , , , , ,...

lua,geometry,corona,geometry-surface

I'm having trouble even figuring out where to start with this. ANY help would be highly appreciated! Using the Corona SDK I want to draw a circle that will slowly fill as a percentage increases. The fill effect will follow the path of the circle, going anti-clockwise until the entire...

opengl-es,geometry,opengl-es-2.0

I've tried to implement an inefficient function to generate the points, normals, tex coords, and index list of a sphere. Ignoring the lines, when I draw the sphere with OpenGL I get the following output which is clearly wrong: Can anyone help me understand what's wrong with my code? public...

opengl,coordinate-systems,rotational-matrices

Was just trying to do some rendering with OpenGL and I happened to think about that: how would you run transformations in a fixed coordinate system. In other words, if you rotate an object around one axis you will see that the others are going to rotate too? Therefore, following...

python,opengl,geometry,trigonometry,pyglet

I've tried to draw a circle with Pyglet and I have failed. With beautiful and unexpected results, though. I have worked out the math: I have implemented the method: """ Pyglet utilities. Designed to ease drawing of primitives with Pyglet. """ # Dependencies import pyglet from math import sin, cos...

c++,algorithm,math,geometry

If I had the following figure shown below and I wanted to scale the top rectangle by some factor such that the left side will still touch the circle like it does now, how would I go about doing that? This is being done in C++ where the rectangles are...

math,geometry,line,pseudocode,angle

I have two lines specified by two points with x and y coordinate each. The first point (where the lines begin) is equal meaning that I have 3 points A, B and C where one line is from A to B and the other one from A to C. I...

c++,math,rotation,grid,geometry

If i had an array of point structs defined as struct Point{ float x; float y; }; How would I rotate the points in this array by a given angle? As an example: Any help would be appreciated!...

algorithm,math,geometry,computational-geometry

I have two circles that are positioned perfectly on the boarder of each other. They have position A and B (both vectors), and radii Ra and Rb. Now I add a third circle with radii Rc. How can I find the position vector C where the three circles are placed...

javascript,geometry,computational-geometry,bezier,adobe-illustrator

I am now scripting Illustrator by javascript. Is it possible to check a closed path is on the inside of an ellipse? (As drawn in below picture, I wish to check a red path is on the inside of an ellipse) A closed path is generally created by cubic bezier...

javascript,canvas,rotation,geometry

I am trying to rotate a square about its center in javascript. Although in this case I am using canvas to draw the square, I need to have a functional method of rotating the square for use elsewhere so just rotating the canvas is not acceptable. This is what I...

javascript,geometry,2d,spatial,perspective

Looking for a code example of how to calculate (accurately) the dimensions of a rectangle from a top down view (90 degrees) at a particular angle. e.g. I have a rectangle of 1200mm x 2000mm How would i determine the new perspective measurements of the rectangle if it was angled...

algorithm,coordinates,coordinate-systems,coordinate

I'm writing a program for visualizing crystals. As a part of the program, I have to generate all different basic points in a lattice structure. For those that aren't familiar with crystallography, you can find the most general cases of these structures here: https://en.wikipedia.org/wiki/Hermann%E2%80%93Mauguin_notation#Lattice_types The problem was that I wanted...

php,mkmapview,latitude-longitude,coordinate-systems

I'm using MKMapView and I send my php program the visible region (center lat, center lon, span lat, span lon). I need to determine if a coordinate is inside that region using php. I'm hoping there's a standard formula somewhere, but I haven't found one. I'll keep trying to come...

c#,math,geometry

I think the image says all. I have to find out the theta for any given line programatically with c#. Point X = new Point(x1,y1); Point Y = new Point(x2,y2); Now I want to draw a line from X point with theta angle. how can I implement with c#....

algorithm,math,geometry,polygon,intersection

The polygon may or may not be convex. We can assume that the edges of the square align with X and Y axis. Calculating the intersection [A simple algorithm for polygon intersection]1 is an over-kill, as I only need to know whether they intersect (Yes or No)....

html,css,geometry

If I have a DOM structure like this: <li> <a> <h2></h2> <img> <p></p> <button></button> </a> </li> And I want the image to be perfectly round, how would I achieve that? I tried using the following after looking at this article: .circle-box { width: 70%; height: 0; margin-top: 10px; padding-bottom: 70%;...

matlab,image-processing,geometry,pixel,binary-image

I have one vector of radii and second vector of hundreds of [X,Y] coordinates. For each possible coordinate-radius pair I have count all black pixels within a circle (whose center is placed in the coordinate) on an input binary image. What is the fastest way to do it? My only...

ios,objective-c,geometry,calayer,uibezierpath

I know there are lots of example related to UIBezierPath, but I am very confused about the angles to use to draw arc, my requirement is like the image below to draw arcs. The length and angle should be calculated as per total number. Right now I have created a...

c#,geometry,drawing

I'm currently working with files that define rectangular shapes in a way that I'm unfamiliar with. Someone told me it might be a matrix, but knowing that doesn't particularly help me with my problem, converting it to points and back. For example, I have these values: 0.95, -0.28, -0.28, -0.95,...