R - Change starting point of a line - r

I'm trying to plot a graph from a list of values stored in a vector.
I have a list of 1000 elements and another one of 900 elements.
I'd like to start to draw my second line at x=100 to make sure the last point of both lines are at x=1000.
I can't use "padding" by adding 0 to the second data vector.
I found the segment function which allow to draw from a starting to an end point but it seems that it can only draw..segments?
Do you know what option I should use to begin the drawing of a line to a given abscissa ?

Related

Get manually defined vectors from Curve3D (Path) in Godot

I have a scene containing a Path Node (the red dots with the blue lines)
I want to use the Path Node as a list of ordered checkpoints (easy to add with the editor), for a character, with some kind of obstacle avoidance.
I can get the list of all steps along the Curve3D, with $Path.get_curve().get_baked_points(), the distance between two steps being $Path.bake_interval. But that's not what I need for my purpose. I only want the red dots, not all increment, since some of them are inside the obstacles.
Is there any mean to get a list of the red dots from script ? Or some configuration on Path or Curve3D to force all the increments being the red dots ?
Otherwise, could you suggest an alternative way to add, as easily as that, a list of ordered checkpoints ?
You can get the number of points of the curve with get_point_count, and then get the position of each one with get_point_position. For example:
for index in curve.get_point_count():
print(curve.get_point_position(index))
Should print the positions you want.

Find intersection of given two lines each passing through more than two points

Challenge:
We have two lines.
Blue line passes through points : (20,100), (25,44.44), (30,30), (35,20), (40,0), (45,0), (50,0), (55,0), (60,0)
Pink line passes through points : (20,00), (25,0), (30,0), (35,0), (40,20), (45,33.33), (50,64.44), (55,100), (60,100)
Without any manual intervention, I want to know the point where they intersect. For example, the point of intersection as shown in figure is (37.5,10)
Remember: The only input of the program is set of points of two lines. Output needed is intersection point of both the line.
Things that did not work out:
I tried to find library of Python that can generate intersection point of two lines(both passing through more than two points). Couldn't find it.
I tried to find a mathematical equation generator for lines passing through more than two points. Then I thought I'll be able to find the intersection of those two equations. Got very complex with lots of polynomial equations!
Most of the places I searched in internet were able to give me intersection of two straight lines that passed through two points only. However as seen in the above image, the both the line passes through about 9 points.
Correct solution:
Well, call it a bummer or any but the solution wasn't as complex as I thought.
Now if you carefully look at the image, you can interpret it in this way:
Instead of calling it a line that passes from lots of points and not just two points, call it a line that is passing through two points. Then it is passing through another two points. Then another two points.. so on..
There are many solutions available online for finding intersection of lines that passes through 2 points. The problem here was only because of the interpretation that both the lines are passing through N number of points (N>2).
Hence, the answer is calculated this way
Step 1: Check for intersection of line1 with first two points [(20,100),(25,44.44)] and line2 with first two points[(20,0.0),(25,0.0)]
Step 2: Check for intersection of line1 with next two points [(25,44.44),(30,30)] and line2 with first two points[(25,0.0),(30,0)]
Step 3: Repeat this process for the whole loop of points till the last point is reached.
Output: The program was able to yield (37.5,10) correctly!
PS: I can share the code of this if need be.

Calculate intersection of points on graph

I'm trying to generate SVG paths that repeat. To do this I am plotting a minimum of 2 points on a graph to create a line like so...
However I want to draw a straight line from the last point to the next point of the repeated path on the next SVG, and to do that I need to find the Y position where the current graph ends and the next starts.
Based on the x and y coordinates of the 2 points, how do I calculate the y coordinate (that's in red and should be 40 in this example)
Any help greatly appreciated!
Assuming the tile size is a x a, you can construct a coordination system from the bottom left of the first tile. Also assume the finish of the first line is (x1,y1) and in this new coordination system, the start of the second line would be (a+x2,y2). Look at the following paint masterpiece (:D) to understand what I mean.
OK, now you can write the line's formula of these two points:
y-y1=((y2-y1)/(a+x2-x1))(x-x1)
replacing x with a and solving the formula for y would result in what you need:
y=((y2-y1)/(a+x2-x1))(a-x1)+y1
UPDATE
From the values you represented, you can use the formula by replacing x1=70, x2=20, y1=100, y2=0, a=100

Graphics, smooth shading and normals

I'm trying to achieve smooth shading of triangles in my graphics program, however I'm currently stuck on how to do it exactly, I've got two options.
Option 1: (per vector)
Create a "zero" Vector.
Add the non-normalized normal of every incident triangle to the created vector.
Scale the resulting vector by 1 / incidentTriangleCount.
Return the normalized version of the resulting vector.
Option 2: (per vector)
Create a "zero" Vector.
Add the normalized normal of every incident triangle to the created vector.
Scale the resulting vector by 1 / incidentTriangleCount.
Return the non-normalized version of the resulting vector.
Both approaches are giving me different results and I don't really know which one to take, can anyone give me advice on this?
Always work with normalized normals. Thus your two options will merge in single one :)
Besides, you have to be careful when using "every" incident triangle, because in this case you will have your entire model smoothed, which is not good. E.g. a model of pencil that actually have edges will look like a rounded one. Implement a treshold, i.e. only consider triangles, which normals have relatively small angle beetween them.

Formula to determine if a line segment intersects a circle (flat)

Apologies if this is considered a repeat question, but the answers I've seen on here are too complex for my needs.
I simply need to find out if a line segment intersects a circle. I don't need to find the distance to the line from the circle center, I don't need to solve for the points of intersection.
The reason I need something simple is that I have to code this in SQL and am unable to call out to external libraries, and need to write this formula in a WHERE clause... basicaly it has to be done in a single statement that I can plug values in to.
Assuming 2 points A (Ax,Ay) and B (Bx,By) to describe the line segment, and a circle with center point C (Cx,Cy) and radius R, the formula I am currently using is:
( RR ( (Ax-Bx)(Ax-Bx) + (Ay-By)(Ay-By) ) )
-( ((Ax-Cx)(By-Cy))-((Bx-Cx)(Ay-Cy)) ) > 0
This formula is taken from link text, and is based on a 0,0 centered circle.
The reason I am posting is that I am getting weird results and I wondered if I did something stupid. :(
although this doesn't exactly answer your question: Do you really have to calculate this on the fly on a SQL-Select? This means that the DB-system has to calculate the formula for every single row in the table (or every single row for which the remaining where conditions hold, respectively) which might result in bad performance.
Instead, you might consider creating a separate boolean column and calculate its value in an on-insert/on-update trigger. There, in turn, you wouldn't even need to put the test in a single line formula. Using a separate column has another advantage: You can create an index on that column which allows you to get your set of intersecting/non-intersecting records very fast.

Resources