Point slope form in C# - point

Im trying to find the ortho-centre of a triangle using the tutorial found here. All is fine up to the point where I have to calculate the equation of the line. For the equation of the line I should end up with 2 equations that should look something like x + 9y = 45 and 2x - y = 12 as per the example.
This is where I get stuck. How can I express this programatically as 2 of the variables for each equation are unknown?
And then I am to use the 2 equations above to solve for x and y. Again, how can I do this programatically? I know how to do it on paper but I cant seem to get my head around how to do this in C# (XNA)
Does anyone have any solutions?

Related

How to use Revit API to create a structural wall?

I already know how to create a Architectural wall using Revit API.
The code is something like this. Notice, I am also use Revit Python Wrapper in my code.
def create_wall(a, b, c, d, e, f, g, h):
doc = revit.doc
with rpw.db.Transaction('Test Is Instance') as t:
start_point = XYZ(a, b, c)
# convert millimeter to feet, internal, it uses feet
end_point = XYZ(d, e, f)
# Wrapper Line
line = Line.new(start_point, end_point)
levels = db.Collector(of_class='Level')
level_0 = levels.get_first()
wall = DB.Wall.Create(doc, line.unwrap(), level_0.Id, False)
w = db.Wall(wall)
# convert the mm to feet.
w.parameters['Base Offset'].value = g
w.parameters['Unconnected Height'].value = h
After I did this, I found it is working well. But there is one thing, the wall I created using this function, when it comes across a wall in the intersection, if there is a small gap, for example 45 mm, it will automatically stick to the wall in the intersection and the gap disappears.
Say, I created a wall 1.5 meters long, but there is anothter wall in the intersection and there is a 45 mm distance between this created wall and the existing wall in the intersection. The 45 mm gap disappears and the length of the created new wall actually 1.5 meters plus 45 mm long. And this is not what I want.
Someone told me I can use structural wall instead Architectural wall. The way to do that is to follow this step,
In menu - Structure, choose the Component in the ribbon of structure menu, then click the model-in-place, after that, there will be a window pop up, Then choose the Family Category - Walls with filter list is Structure, Then in Project Brower tree, Families - walls there will be new type of wall, and this wall doesn't have the issue I mentioned above, that is it won't automatically strectch and change the length when I create the wall.
First topic is that is this true? What are their differences for these two types of wall creation? And if this is true, how can I use revit API to create the second type of wall?
PS. I also use Revit Python Shell to inspect two different kinds of walls. The first type of wall - Architectural wall type is Wall class in Revit API. I also have the second type of wall handy, but it's created manually, it's created by someone else and not created by Revit API. I inspected the revit file containing the second type of wall, when I select this second type of wall in his Revit file, the return type of selected Revit wall in Revit python shell is FamilyInstance.
Secondly, I have this question, why the first type of the wall is Wall Class but the type of the second wall - structural wall is FamilyInstance.
I think what the wall you create through the revit-api does, is that it is joining the wall end to another wall.
What you need is WallUtils.DisallowWallJoinAtEnd().
As stated in the revit-api documentation. revitapidocs.com - WallUtils

Calculate CV2 Homography by points and line

I have a list of points in the field (like upper_goal_point/ left_upper_outer_corner, etc.
I know their corresponding coordinates in destination image - so I can calculate the homography:
h, status = cv2.findHomography(pts_src, pts_dst)
I also have blue points in the upper corner line (look at image above), which I only know that their destination's y coordinates are 0 (because they are in the upper line), but I don't know where exactly they lay in that line.
Can I use those blue points in order to improve the homography?
P.S.
You can see that the upper corner line in the homography is not horizontal line, it's diagonal, which of course is not correct:
Actually it possible to use line correspondence in find homography.
https://www.researchgate.net/publication/220845575_Combining_Line_and_Point_Correspondences_for_Homography_Estimation
Several years ago we implement this approach in one project. During simplification all math we come up with simple trick. We transform every line a*x + b*y + c = 0 to point (a/c, b/c)
// *** Don't copy paste this code, read below! ***//
Point2f convertPointsToHomogeneousLine(Point2f p1, Point2f p2) {
Point3f p1h(p1.x, p1.y, 1);
Point3f p2h(p2.x, p2.y, 1);
Point3f lineHomo(p1h.y*p2h.z - p1h.z*p2h.y,
p1h.z*p2h.x - p1h.x*p2h.z,
p1h.x*p2h.y - p1h.y*p2h.x);
Point2f lineHomoNorm(lineHomo.x / lineHomo.z,
lineHomo.y / lineHomo.z);
return lineHomoNorm;
}
And pass this points inside. As I remember I also dig inside OpenCV implementation of findHomography and insert this lines somewhere inside to solve step. Inside OpenCV there some normalization applied to points before pass to solve step. So you need to skip this step for this kind of points.
We do not use it in production. User need to calibrate camera manually by providing lines and points on the image and in meter system. It has too complicated interface and bad stability. But in your case I think it can work better. If you will automatically find lines and correspondence.
P.S. Please note that in paper they use some normalization technique.
It will improve stability. We faced with stability problem, do not
solved it in our journey.

Python - Reading File Then Adding Value to Sum?

I've been looking all around the web for this answer and can't find it.
I'm semi new to python so hoping i get an answer here,
so basically what i want to do is, access a text file "number.txt"
that has a 10 as a line, and do a sum within the python code.
Here is what i got so far:
with open('number.txt', 'r') as sum:
num = sum.readline()
clean = num.rstrip('\n')
#number.txt file only contains 1 line and is a 10
increase = "5"
adding = clean + increase
print(adding)
it doesn't do the sum, instead i get the 5 added after the 10
so instead of getting 15 i get 105.
can anyone help?
Welcome to programming. Keep aware of the concepts of data types, I suggest doing some reading on that.
The + operator behaves differently between strings, arrays, and integers.
I would give you the answer but I am guess you are doing this as an assignment of sorts, so I just wanted to point you in the right direction. Use a python debugger (like PyCharm, or Wing IDE) to determine the differences between "5" + "10" 5+10 and [5]+[10]
You need to look into what's called Type Casting

Wrong fit parameters, Undefined value during function evaluation

I'm trying to do some simple fits using Gnuplot and encountering an error which somehow I'm not able to explain. Seems that I'm doing something terribly wrong with the definition of my function.
I first started with a fit of some functions. The functional form of these is not important as the fits work pretty well, but since they are involved later I'm reporting them as well.
evap(x)=(x>x_fc)?A*qnet(x)/wm2_to_mmh:(x<x_wp)?0:(A*qnet(x)/wm2_to_mmh)*(x-x_wp)/(x_fc-x_wp)
fit evap(x) './fluxes_da_1p0.txt' using 1:2 via A, x_fc, x_wp
sensible(x)=( (qnet(x)/wm2_to_mmh)-evap(x) ) / (1+B)+C
fit sensible(x) './fluxes_da_1p0.txt' using 1:3 via B,C
Then I defined
deltasensible(x)=abs(sensible(x)-sensible(0.454))
deltalatent(x)=abs(evap(x)-evap(0.454))
period_adv=18.0
g(x)=m*deltalatent(x)*period_adv*(deltasensible(x))**e
If I impose
m=3.8
e=0.5
and just plot the function g(x) superimposed on the data it seems to work pretty well.
However if I try to fit it using the parameters
fit g(x) './advection_da_1p0.txt' using 5:2 via m,e
I get the following error
iter chisq delta/lim lambda m e
0 4.2471983038e+00 0.00e+00 5.51e+00 3.800000e+00 5.000000e-01
1 3.7149813491e+00 -1.43e+04 5.51e-01 3.573384e+00 4.843345e-01
Current data point
=========================
# = 8 out of 8
x = 0.0178156
z = 0.0309726
Current set of parameters
=========================
m = 0.0178156
e = -0.0583802
"rain_estimate.gpl", line 52: Undefined value during function evaluation
For some reason Gnuplot is trying out really strange values for m,e, although I provided their initial values. If I remove the deltalatent(x) dependency everything is working fine. Am I missing something simple?
So I think I figured it out the problem by myself. Given my data a line was the best fit for Gnuplot so that it was trying to remove the exponential dependency on deltasensible by choosing a really small coefficient. Seems more an "error" with the data than with Gnuplot itself.

Turning a list into a set of coordinates [Haskell]

I am a starting out programmer and have my first few programming classes. We started off with functional programming, in this case using Haskell. I've managed to complete a few assignments already, but seem to have gotten stuck in one point and was hoping to get some help with it.
In order to not bore you with the entire code, my program right now is extracting a list of commands from a text file. I need to turn this list into a set of coordinates. What I mean is something along the lines of:
function :: [String] -> (Int, Int, Char)
where the function will receive, for example, the list ["0 0 N"] and output the coordinates and direction (0, 0, N).
I tried doing:
function [x y o] = (show x, show y, read o)
which would work if it were just Integers. I can't seem to get the Char part to work. I appologize if it's such a noobie question, but bear with me, please, I'm really new to all of this.
Thank you and best regards!
For your specific test case this should work:
function [(x:' ':y:' ':o:_)] = (read [x], read [y], o)
If your string contains spaces you need to match on them as well if you want to do it like that.
But that's probably not what you actually want. It would break for inputs like ["12 23 S"] or ["3 5 W", "2 8 E"].
If your input is actually a list of Strings like your signature says you should probably write two functions: One that deals with a single String and one that applies your other function to all Strings in the list. Look at the functions map and words and think about how you can use them to solve your problem.

Resources