Discussion:
Straight lines and straight line segments: different types ?
(too old to reply)
GianLuigi Piacentini
2015-01-04 22:35:02 UTC
Permalink
or same type and (sometimes) different handling logic ?

I coded a module handling with parametric straight lines in the space, then
noticed that segments will practically be same code, with some exceptions.

So
- same type, sometimes different handling logic ?
- 2 types, lot of duplicate code ? (are they really different ? is it worth
to reflect logic difference into the type system ?)
- inheritance ?

What do you suggest about ?

Thanks in advance, happy new year to everybody.

Gigi
Hans-Bernhard Bröker
2015-01-05 00:01:04 UTC
Permalink
Post by GianLuigi Piacentini
or same type and (sometimes) different handling logic ?
Different.
Post by GianLuigi Piacentini
I coded a module handling with parametric straight lines in the space, then
noticed that segments will practically be same code, with some exceptions.
Actually, straight lines have fewer exceptions (as in: restrictions)
than segments, as can be seen from the fact that you actually need less
data to describe them. A straight in 3D space has only 4 degrees of
freedom; a segment has 6.

And the similarity really only exists for the parametric form. Implicit
forms can look rather more different.
Post by GianLuigi Piacentini
- inheritance ?
No. Neither is a subset of the other.
GianLuigi Piacentini
2015-01-05 18:06:46 UTC
Permalink
Post by Hans-Bernhard Bröker
Post by GianLuigi Piacentini
or same type and (sometimes) different handling logic ?
Different.
Suspect I will end in a lot of duplicated code, have to think how to
minimize that.
Post by Hans-Bernhard Bröker
Post by GianLuigi Piacentini
I coded a module handling with parametric straight lines in the space,
then noticed that segments will practically be same code, with some
exceptions.
Actually, straight lines have fewer exceptions (as in: restrictions)
than segments, as can be seen from the fact that you actually need less
data to describe them. A straight in 3D space has only 4 degrees of
freedom; a segment has 6.
And the similarity really only exists for the parametric form. Implicit
forms can look rather more different.
Post by GianLuigi Piacentini
- inheritance ?
No. Neither is a subset of the other.
My opinion was that a segment S along a line L is a subset of L because is
formed by a subset of the points forming L, and so, generalizing, a segment
(and a ray) is a subset of the line. Wrong opinion ?

Thanks in advance.

Gigi
Hans-Bernhard Bröker
2015-01-06 17:58:42 UTC
Permalink
Post by GianLuigi Piacentini
My opinion was that a segment S along a line L is a subset of L because is
formed by a subset of the points forming L, and so, generalizing, a segment
(and a ray) is a subset of the line. Wrong opinion ?
Yes, because you're applying the term "subset" to the wrong set.

A data type is a set of objects; each instance of the type is an element
of that set. In the case at hand the type "line" is the set of all
lines, and each line is itself a set of points.

Inheritance is applicable where you want to describe a subset of the set
that is a type. E.g. the set of cars is a subset of the set of all
vehicles, so type "car" will inherit from type "vehicle". But segments
aren't lines, so they're not in the type "line", and therefore shouldn't
be derived from "line".
Limited_Atonement
2015-01-06 20:44:31 UTC
Permalink
Post by Hans-Bernhard Bröker
Actually, straight lines have fewer exceptions (as in: restrictions)
than segments, as can be seen from the fact that you actually need less
data to describe them. A straight in 3D space has only 4 degrees of
freedom; a segment has 6.
Can you explain the 4 degrees of freedom? I don't think I follow.
Hans-Bernhard Bröker
2015-01-06 23:06:13 UTC
Permalink
Post by Limited_Atonement
Post by Hans-Bernhard Bröker
Actually, straight lines have fewer exceptions (as in: restrictions)
than segments, as can be seen from the fact that you actually need less
data to describe them. A straight in 3D space has only 4 degrees of
freedom; a segment has 6.
Can you explain the 4 degrees of freedom? I don't think I follow.
There are several ways to see that. One of the more obvious ones is
this: a segment in 3D obviously has 6 continuous degrees of freedom,
from 3 coordinates per endpoint. The only ambiguity is that you can
switch the two endpoints around. A line has two less than that because
you can place each of the endpoints of the representative segment
arbitrarily along the line, so two of the 6 superficial coordinates are
"don't-care". They are not actually degrees of freedom of the line.

Another way of seeing it is the implicit equation fulfilled by point
vector 'p' to be on a line:

p x n = r where |n| = 1, and r.n = 0

n and r are 3D vectors, but the two restrictions remove one degree of
freedom each, so you end up with four actual degrees of freedom.

Limited_Atonement
2015-01-06 20:43:32 UTC
Permalink
Post by GianLuigi Piacentini
or same type and (sometimes) different handling logic ?
I coded a module handling with parametric straight lines in the space, then
noticed that segments will practically be same code, with some exceptions.
So
- same type, sometimes different handling logic ?
- 2 types, lot of duplicate code ? (are they really different ? is it worth
to reflect logic difference into the type system ?)
- inheritance ?
What do you suggest about ?
Thanks in advance, happy new year to everybody.
Gigi
You have some choices. A line is a 5-dimensional object: a point (3), longitute (1), and latitude (1). The latter two being angles about x and angles about z (say) that determine where the line goes from the point. A line segment is a six-dimensional object: a point(3), longitude (1), latitude (1), and line-segment length (1). In this way, it is a "subclass" of a line because it adds one more member: length.

You can, alternatively, create a new type of object that is either a line or line segment based on an internal boolean represented by two points and a boolean. In this way, they would be the exact same type.
Loading...