Editing User:Gaganjyotsingh/Proposal/LibreCADkickoff

From BRL-CAD

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 49: Line 49:
  
 
For the Line, the move can be implemented as
 
For the Line, the move can be implemented as
 
 
void move_line ( coordinate offset ) {
 
void move_line ( coordinate offset ) {
 
 
start_point = start_point + offset;
 
start_point = start_point + offset;
 
 
end_point = end_point + offset;
 
end_point = end_point + offset;
 
 
}
 
}
  
 
delete_line(id); // Immutable approach, older gets deleted and a new will be created.
 
delete_line(id); // Immutable approach, older gets deleted and a new will be created.
 
 
new_line(start_point, end_point); // values changed above.
 
new_line(start_point, end_point); // values changed above.
 
  
 
For Circle and Arc, the center will be moved by the offset value
 
For Circle and Arc, the center will be moved by the offset value
Line 86: Line 80:
  
 
void rotate ( double angle ) {
 
void rotate ( double angle ) {
 
 
// Rotation around itself at some angle.
 
// Rotation around itself at some angle.
 
+
// first the double value will be converted into a coordinate using sin cos functions for x and y coordinate respectively
// first the double value will be converted into a coordinate using sin cos  
 
functions for x and y coordinate respectively
 
 
and then the algo will be applied to rotate the entity. Which is like
 
and then the algo will be applied to rotate the entity. Which is like
 
 
temp_x = x * angle.x – y * angle.y // stored in temp since we need older x value
 
temp_x = x * angle.x – y * angle.y // stored in temp since we need older x value
 
 
y = x * angle.y – y * angle.x
 
y = x * angle.y – y * angle.x
 
 
x = temp
 
x = temp
 
 
}
 
}
  
Line 109: Line 96:
 
*Text will have support for the following attributes,
 
*Text will have support for the following attributes,
  
**Insertion point : The point at wich entity is to be inserted.
+
Insertion point : The point at wich entity is to be inserted.
**SecondPoint : It is used by the aligned fit.
+
SecondPoint : It is used by the aligned fit.
**Widthrel : It is the width of reference rectangle around the text.
+
Widthrel : It is the width of reference rectangle around the text.
**Height : Height of text
+
Height : Height of text  
**Valign : Vertical Alignment of the Dimension value text
+
Valign : Vertical Alignment of the Dimension value text
**Halign : Horizontal Alignment of the dimension value text     
+
Halign : Horizontal Alignment of the dimension value text     
**Text : Text value held by dimension entity
+
Text : Text value held by dimension entity
**Style : Style of the text     
+
Style : Style of the text     
**Angle : If the text is aligned at some angle
+
Angle : If the text is aligned at some angle
  
 
*Dimension has the following attributes,
 
*Dimension has the following attributes,
  
**DefinitionPoint : The point at which dimension is defined
+
DefinitionPoint : The point at which dimension is defined
**MiddleOfText : Middle of the dimension text
+
MiddleOfText : Middle of the dimension text
**Valign : Vertical Alignment of the Dimension value text
+
Valign : Vertical Alignment of the Dimension value text
**Halign : Horizontal Alignment of the dimension value text
+
Halign : Horizontal Alignment of the dimension value text
**LineSpacingStyle : Spacing style if any for the dimension     
+
LineSpacingStyle : Spacing style if any for the dimension     
**LineSpacingFactor : Spacing factor if any
+
LineSpacingFactor : Spacing factor if any
**Text : Text value held by dimension entity
+
Text : Text value held by dimension entity
**Style : Style of the text     
+
Style : Style of the text     
**Angle : If the text is aligned at some angle
+
Angle : If the text is aligned at some angle
  
 
====Intersection Stuff====
 
====Intersection Stuff====
 +
// YET TO BE ADDED AND IS THE MAIN MATHS PART
  
The Kernel manages the intersection of two entities. The types of entities being Arc, Line, Ellipse, circle, point if we create the functions to check and return intersection between entities, we will get a number of functions.
+
====References :====
For example :
+
Circle circle intersection
 
+
http://mathworld.wolfram.com/Circle-CircleIntersection.html
intersect_line_line(line, line);
+
http://stackoverflow.com/questions/3349125/circle-circle-intersection-points
 
+
Ellipse Line :
intersect_line_arc(line, arc);
+
http://www.nabla.hr/Z_MemoHU-029.htm
 
+
http://gieseanw.wordpress.com/2013/07/19/an-analytic-solution-for-ellipse-and-line-intersection/
intersect_line_ellipse(line, ellipse);
 
 
 
and so on for every entity.
 
 
 
The quadratic of any entity can be found. Then the quadratic of two entities can be passed to a common function that just calculates the intersection points from the two quadratic equations.
 
 
 
quad1 = line.get_quadratic()
 
 
 
quad2 = circle.get_quadratic()
 
 
 
quad3 = ellipse.get_quadratic() // ellipse quadratic equation
 
 
 
get_intersection(quad1,quad2) // will give intersection points of line and circle
 
 
 
get_intersection(quad1,quad3)// will give intersection points of line and ellipse
 
 
 
For example,
 
 
 
Approach 1 ( Line Line direct intersection calculation )
 
 
 
void Intersect::visit(shared_ptr<const lc::Line> l1, shared_ptr<const lc::Line> l2) {
 
 
 
    geo::Coordinate p1 = l1->start();
 
    geo::Coordinate p2 = l1->end();
 
    geo::Coordinate p3 = l2->start();
 
    geo::Coordinate p4 = l2->end();
 
 
 
    double num = ((p4.x() - p3.x()) * (p1.y() - p3.y()) - (p4.y() - p3.y()) * (p1.x() - p3.x()));
 
    double div = ((p4.y() - p3.y()) * (p2.x() - p1.x()) - (p4.x() - p3.x()) * (p2.y() - p1.y()));
 
 
 
    // TODO: We properly should add a tolorance here ??
 
    if (fabs(div) > 0.0) {
 
        double u = num / div;
 
        double xs = p1.x() + u * (p2.x() - p1.x());
 
        double ys = p1.y() + u * (p2.y() - p1.y());
 
        geo::Coordinate coord(xs, ys);
 
 
 
        if (_method == Method::Any || (_method == Method::MustIntersect && l1->isCoordinateOnPath(coord) && l2->isCoordinateOnPath(coord))) {
 
            _intersectionPoints.append(coord);
 
        }
 
    }
 
}
 
 
 
Approach 2 ( First calculate quadratic of entities and then calculate intersection from quadratic )
 
 
 
void Intersect::visit(const shared_ptr<const lc::Line>& l1, const shared_ptr<const lc::Line>& l2) {
 
 
 
//getIntersection
 
QList<geo::Coordinate>&& points=LC_Quadratic::getIntersection(l1->getQuadratic(), l2->getQuadratic());
 
// Where getQuadratic is a function to calculate quadratic of lines.
 
if (points.empty() == false )
 
    _intersectionPoints.append(points);
 
 
 
}
 
 
 
References :
 
http://en.wikipedia.org/wiki/Quadratic_form
 
 
 
Maths will be taken from LibreCAD2 :
 
 
 
https://github.com/LibreCAD/LibreCAD/blob/master/librecad/src/lib/math/lc_quadratic.h
 
  
https://github.com/LibreCAD/LibreCAD/blob/master/librecad/src/lib/math/rs_math.h
 
  
 
===Deliverables:===
 
===Deliverables:===
The project can be divided in at least 4 parts, so all of this can be considered a specific measurable goal (one for every feature implemented). LibreCAD v3 Kernel will be delivered with the support of following,
+
The project can be divided in at least 5 parts, so all of this can be considered a specific measurable goal (one for every feature implemented). LibreCAD v3 Kernel will be delivered with the support of following,
  
 
#Operations:
 
#Operations:

Please note that all contributions to BRL-CAD may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see BRL-CAD:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)